@linzumi/cli 1.0.341 → 1.0.343

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,10 +1,10 @@
1
1
  import { createRequire as __linzumiBundleCreateRequire } from 'node:module';
2
2
  const require = __linzumiBundleCreateRequire(import.meta.url);
3
- var jr=Object.create;var dt=Object.defineProperty;var $r=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var Vr=Object.getPrototypeOf,Br=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 R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var zr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ur(t))!Br.call(e,i)&&i!==r&&dt(e,i,{get:()=>t[i],enumerable:!(n=$r(t,i))||n.enumerable});return e};var Hr=(e,t,r)=>(r=e!=null?jr(Vr(e)):{},zr(t||!e||!e.__esModule?dt(r,"default",{value:e,enumerable:!0}):r,e));var Zt=R((Ni,Kt)=>{var K=W("constants"),kn=process.cwd,ke=null,Cn=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ke||(ke=kn.call(process)),ke};try{process.cwd()}catch{}typeof process.chdir=="function"&&(qe=process.chdir,process.chdir=function(e){ke=null,qe.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,qe));var qe;Kt.exports=bn;function bn(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(){}),Cn==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:(function(u){function c(s,a,d){var _=Date.now(),h=0;u(s,a,function A(k){if(k&&(k.code==="EACCES"||k.code==="EPERM"||k.code==="EBUSY")&&Date.now()-_<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,_,h,A){var k;if(A&&typeof A=="function"){var I=0;k=function(Te,ct,st){if(Te&&Te.code==="EAGAIN"&&I<10)return I++,u.call(e,s,a,d,_,h,k);A.apply(this,arguments)}}return u.call(e,s,a,d,_,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,_){for(var h=0;;)try{return u.call(e,c,s,a,d,_)}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,_){if(d){a&&a(d);return}u.fchmod(_,s,function(h){u.close(_,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,_;try{_=u.fchmodSync(a,s),d=!1}finally{if(d)try{u.closeSync(a)}catch{}else u.closeSync(a)}return _}}function r(u){K.hasOwnProperty("O_SYMLINK")&&u.futimes?(u.lutimes=function(c,s,a,d){u.open(c,K.O_SYMLINK,function(_,h){if(_){d&&d(_);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),_,h=!0;try{_=u.futimesSync(d,s,a),h=!1}finally{if(h)try{u.closeSync(d)}catch{}else u.closeSync(d)}return _}):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){p(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(!p(a))throw a}}}function o(u){return u&&function(c,s,a,d){return u.call(e,c,s,a,function(_){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(!p(d))throw d}}}function f(u){return u&&function(c,s,a){typeof s=="function"&&(a=s,s=null);function d(_,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 p(u){if(!u||u.code==="ENOSYS")return!0;var c=!process.getuid||process.getuid()!==0;return!!(c&&(u.code==="EINVAL"||u.code==="EPERM"))}}});var Qt=R((Pi,Xt)=>{var Yt=W("stream").Stream;Xt.exports=Nn;function Nn(e){return{ReadStream:t,WriteStream:r};function t(n,i){if(!(this instanceof t))return new t(n,i);Yt.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 p=l[f];this[p]=i[p]}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);Yt.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 tr=R((Fi,er)=>{"use strict";er.exports=Fn;var Pn=Object.getPrototypeOf||function(e){return e.__proto__};function Fn(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Pn(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Ye=R((Mi,Ze)=>{var S=W("fs"),Mn=Zt(),In=Qt(),Ln=tr(),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 Rn(){}function ir(e,t){Object.defineProperty(e,M,{get:function(){return t}})}var ee=Rn;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]||(rr=global[M]||[],ir(S,rr),S.close=(function(e){function t(r,n){return e.call(S,r,function(i){i||nr(),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),nr()}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 rr;global[M]||ir(global,S[M]);Ze.exports=Je(Ln(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Ze.exports=Je(S),S.__patched=!0);function Je(e){Mn(e),e.gracefulify=Je,e.createReadStream=ct,e.createWriteStream=st;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,w){return t(P,C,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?se([N,[P,C,G],x,w||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,w,x,F){return n(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,w,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,w,x,F){return o(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,w,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,w,x,F){return f(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,w,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var p=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,w,x,F){return p(G,P(G,w,x,F))}:function(G,w,x,F){return p(G,w,P(G,w,x,F))};return N(T,E,y);function P(C,G,w,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?se([N,[C,G,w],F,x||Date.now(),Date.now()]):(O&&O.sort&&O.sort(),typeof w=="function"&&w.call(this,F,O))}}}if(process.version.substr(0,4)==="v0.8"){var s=In(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 _=A;Object.defineProperty(e,"FileReadStream",{get:function(){return _},set:function(T){_=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;je(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;je(T.path,T.flags,T.mode,function(E,y){E?(T.destroy(),T.emit("error",E)):(T.fd=y,T.emit("open",y))})}function ct(T,E){return new e.ReadStream(T,E)}function st(T,E){return new e.WriteStream(T,E)}var Dr=e.open;e.open=je;function je(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,w,x,F){return Dr(C,G,w,function(O,Ai){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,w,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),Ke()}var be;function nr(){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);Ke()}function Ke(){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),p=Math.min(m*1.2,100);f>=p?(ee("RETRY",t.name,r),t.apply(null,r.concat([i]))):S[M].push(e)}be===void 0&&(be=setTimeout(Ke,0))}}});var ur=R((Ii,or)=>{function D(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))}or.exports=D;D.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};D.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};D.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};D.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)};D.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};D.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};D.prototype.start=D.prototype.try;D.prototype.errors=function(){return this._errors};D.prototype.attempts=function(){return this._attempts};D.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 lr=R(te=>{var Dn=ur();te.operation=function(e){var t=te.timeouts(e);return new Dn(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 p=te.operation(t),u=Array.prototype.slice.call(arguments,1),c=u.pop();u.push(function(s){p.retry(s)||(s&&(arguments[0]=p.mainError()),c.apply(this,arguments))}),p.attempt(function(){m.apply(e,u)})}.bind(e,l),e[o].options=t}}});var cr=R((Ri,ar)=>{ar.exports=lr()});var sr=R((Di,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 pr=R((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)?(dr=W("assert"),de=sr(),fr=/^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(){};dr.equal(typeof e,"function","a callback must be provided for exit handler"),fe===!1&&Xe();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=Qe,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),fr&&e==="SIGHUP"&&(e="SIGINT"),v.kill(v.pid,e))}}}),me.exports.signals=function(){return de},fe=!1,Xe=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=_r,v.reallyExit=mr)},me.exports.load=Xe,Qe=v.reallyExit,mr=function(t){re(global.process)&&(v.exitCode=t||0,ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),Qe.call(v,v.exitCode))},Ie=v.emit,_r=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 dr,de,fr,ve,b,Fe,ne,Me,fe,Xe,Qe,mr,Ie,_r});var Ar=R(($i,Ge)=>{"use strict";var jn=W("path"),rt=Ye(),$n=cr(),Un=pr(),H={};function _e(e,t){return t.lockfilePath||`${e}.lock`}function nt(e,t,r){if(!t.realpath)return r(null,jn.resolve(e));t.fs.realpath(e,r)}function et(e,t,r){t.fs.mkdir(_e(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(_e(e,t),(i,o)=>{if(i)return i.code==="ENOENT"?et(e,{...t,stale:0},r):r(i);if(!Tr(o,t))return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));yr(e,t,l=>{if(l)return r(l);et(e,{...t,stale:0},r)})})})}function Tr(e,t){return e.mtime.getTime()<Date.now()-t.stale}function yr(e,t,r){t.fs.rmdir(_e(e,t),n=>{if(n&&n.code!=="ENOENT")return r(n);r()})}function tt(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(_e(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 hr(e,r,o)}if(i)return i.code==="ENOENT"?hr(e,r,Object.assign(i,{code:"ECOMPROMISED"})):(r.updateError=i,r.updateDelay=1e3,tt(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,tt(e,t)}})},r.updateDelay),r.updateTimeout.unref&&r.updateTimeout.unref())}function hr(e,t,r){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),H[e]===t&&delete H[e],t.options.onCompromised(r)}function Vn(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:rt,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),nt(e,t,(n,i)=>{if(n)return r(n);let o=$n.operation(t.retries);o.attempt(()=>{et(i,t,l=>{if(o.retry(l))return;if(l)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};tt(i,t),r(null,m=>{if(f.released)return m&&m(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Er(i,{...t,realpath:!1},m)})})})})}function Er(e,t,r){t={fs:rt,realpath:!0,...t},nt(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],yr(i,t,r)})}function Bn(e,t,r){t={stale:1e4,realpath:!0,fs:rt,...t},t.stale=Math.max(t.stale||0,2e3),nt(e,t,(n,i)=>{if(n)return r(n);t.fs.stat(_e(i,t),(o,l)=>o?o.code==="ENOENT"?r(null,!1):r(o):r(null,!Tr(l,t)))})}function zn(){return H}Un(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(_e(e,t))}catch{}}});Ge.exports.lock=Vn;Ge.exports.unlock=Er;Ge.exports.check=Bn;Ge.exports.getLocks=zn});var Or=R((Ui,xr)=>{"use strict";var Hn=Ye();function Wn(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 qn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Jn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function Kn(e){if(e={...e},e.fs=Wn(e.fs||Hn),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}xr.exports={toPromise:qn,toSync:Jn,toSyncOptions:Kn}});var Gr=R((Vi,Z)=>{"use strict";var pe=Ar(),{toPromise:Le,toSync:Re,toSyncOptions:it}=Or();async function vr(e,t){let r=await Le(pe.lock)(e,t);return Le(r)}function Zn(e,t){let r=Re(pe.lock)(e,it(t));return Re(r)}function Yn(e,t){return Le(pe.unlock)(e,t)}function Xn(e,t){return Re(pe.unlock)(e,it(t))}function Qn(e,t){return Le(pe.check)(e,t)}function ei(e,t){return Re(pe.check)(e,it(t))}Z.exports=vr;Z.exports.lock=vr;Z.exports.unlock=Yn;Z.exports.lockSync=Zn;Z.exports.unlockSync=Xn;Z.exports.check=Qn;Z.exports.checkSync=ei});import*as lt from"node:url";import*as Nr 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 mt(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 j(e,t){return e!==void 0?L(e):t}function _t(e,t){return e.TAG==="Ok"?e:{TAG:"Error",_0:t(e._0)}}var Tt=(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 p=m;if(p===l)return!0;if(!le(e[p],t[p]))return!1;m=p+1|0}}else{if(e instanceof Date&&t instanceof Date)return!(e>t||e<t);{let m={contents:!0},p=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 Tt(e,p),m.contents&&Tt(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 Pr from"node:fs/promises";function Zr(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function U(e){return Zr(e)?e:{RE_EXN_ID:"JsExn",_1:e}}var yt={name:"@linzumi/cli",version:"1.0.341",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","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",prepack:"rescript build -q ../linzumi-cli-rescript && node scripts/build.mjs","pack:dry-run":"npm pack --dry-run","test:startup":"npm run build && node --test --test-concurrency=1 ../linzumi-cli-rescript/src/parity/CommanderStartupRefusalConformance.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.322","@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 Xr=yt,Ue=Xr.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),wi=Se("stack"),we=Se("message"),Et=Se("name"),gi=Se("fileName");var en=new RegExp("\\bsmk_[A-Za-z0-9._-]+","g");function g(e){return e.replace(en,"smk_[REDACTED]")}var tn="https://api.smolmachines.com";function Be(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 j(we(r),String(r))}function Ot(e){let t=xe(e);return t!==void 0?le(Et(L(t)),"AbortError"):!1}var rn=new RegExp("\\/+$");function xt(e,t){let r=e[t];if(r===void 0)return;let n=r.trim();if(n!=="")return n}function ze(e){let t=xt(e,"SMOLCLOUD_API_KEY");return $(t!==void 0?t:xt(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:j(e.SMOLCLOUD_BASE_URL,tn).replace(rn,""),apiKey:r}))}async function ge(e,t){try{return{TAG:"Ok",_0:await fetch(e,t)}}catch(r){return{TAG:"Error",_0:U(r)}}}async function vt(e){try{return await e.text()}catch{return""}}function Gt(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,p=setTimeout(()=>{m.abort()},l),u=e.baseUrl+r,c=m.signal,s;if(typeof o!="object"?s=await ge(u,{method:t,headers:f,body:null,signal:c}):o.TAG==="JsonBody"?(f["content-type"]="application/json",s=await ge(u,{method:t,headers:f,body:JSON.stringify(o._0),signal:c})):(f["content-type"]="application/octet-stream",s=await ge(u,{method:t,headers:f,body:o._0,signal:c})),clearTimeout(p),s.TAG==="Ok"){let a=s._0;if(a.ok){if(a.status===204)return{TAG:"Ok",_0:"NoPayload"};if(!j($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 _=U(d);return{TAG:"Error",_0:{TAG:"Thrown",_0:q(_)}}}}else{let d=a.status,_=await vt(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 "+Gt(d,_);return{TAG:"Error",_0:{TAG:"Smolcloud",code:h,message:g(A)}}}}else{let a=s._0;if(Ot(a)){let _="smolcloud "+t+" "+r+" timed out after "+l.toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(_)}}}let d="smolcloud request failed: "+q(a);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:g(d)}}}}function ce(e){return"/v1/machines/"+e.id}var He="linzumi-role";function ae(e,t){let r=e[t];if(typeof r=="string")return r}function nn(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.labels,l;return l=typeof o=="object"&&o!==null&&!Array.isArray(o)?ae(o,He):void 0,{id:i,name:ae(r,"name"),role:l}}}return{id:e.id,name:void 0,role:void 0}}async function St(e){let t=await Q(e.conn,"GET",ce(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:nn(e,t._0)}:{TAG:"Error",_0:t._0}}function B(e){return e.TAG==="Numeric"?e._0===0:!1}function wt(e){return e.TAG==="Numeric"?e._0.toString():String(e._0)}function gt(e,t){return Object.fromEntries([["command",e.map(r=>r)],["env",Object.fromEntries(j(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 kt(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 on(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:kt(t.exitCode),stdout:j(ae(t,"stdout"),""),stderr:j(ae(t,"stderr"),"")}}:{TAG:"Ok",_0:{exitCode:{TAG:"Numeric",_0:0},stdout:"",stderr:""}}}async function z(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:gt(t,n)},o);return l.TAG==="Ok"?on(l._0):{TAG:"Error",_0:l._0}}function un(e){let t;try{t=JSON.parse(e)}catch{t=void 0}return t!==void 0?typeof t=="object"&&t!==null&&!Array.isArray(t)?kt(t.exitCode):{TAG:"Numeric",_0:0}:{TAG:"Numeric",_0:0}}function ln(e,t){switch(e){case"error":return{TAG:"StreamError",_0:g(t)};case"exit":return{TAG:"Exit",_0:un(t)};case"stderr":return{TAG:"Stderr",_0:t};case"stdout":return{TAG:"Stdout",_0:t};default:return}}var an=new RegExp("^ ");async function cn(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
- `);o.contents="",l.contents=[];let a=ln(c,s);return a!==void 0?t(a):"Continue"},m=()=>{for(;;){let c=i.contents.indexOf(`
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(an,"")),"Continue");if(typeof d=="object")return d}},p=async()=>{let c;try{c={TAG:"Ok",_0:await r.read()}}catch(_){c={TAG:"Error",_0:U(_)}}if(c.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"Thrown",_0:q(c._0)}};let s=c._0;if(s.done){let _=f();return typeof _!="object"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:_._0}}let a=s.value;a!=null&&(i.contents=i.contents+n.decode(a,{stream:!0}));let d=m();return typeof d!="object"?await p():{TAG:"Error",_0:d._0}},u=await p();return r.releaseLock(),u}async function Ct(e,t,r,n){let i=new AbortController,o=$(r.timeout,c=>setTimeout(()=>{i.abort()},(c*1e3|0)+3e4|0)),l=()=>mt(o,c=>{clearTimeout(c)}),f=ce(e)+"/exec/stream",m=await ge(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(gt(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:g("exec/stream returned no response body")}}:await cn(a,n)}else{let a=c.status,d=await vt(c),_="smolcloud POST "+f+" \u2192 "+Gt(a,d);s={TAG:"Error",_0:{TAG:"Smolcloud",code:a===404?"NotFound":"CloudError",message:g(_)}}}return l(),s}let p=m._0;if(l(),Ot(p)){let s="smolcloud exec/stream timed out after "+((j(r.timeout,0)*1e3|0)+3e4|0).toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(s)}}}let u="smolcloud exec/stream failed: "+q(p);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:g(u)}}}function sn(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/"+sn(t),{TAG:"BytesBody",_0:Buffer.from(r,"utf8")},void 0);if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=await z(e,["chmod",n.toString(8),t],void 0);return o.TAG==="Ok"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:o._0}}async function We(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 dn(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:g(l)}}}return n(r.slice(0,i),o)}function fn(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]]))],["labels",Object.fromEntries(e.labels.map(r=>[r[0],r[1]]))],["autoStopSeconds",e.autoStopSeconds],["ttlSeconds",e.ttlSeconds]])}function mn(e){return new Promise((t,r)=>{setTimeout(()=>t(),e)})}async function _n(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:g("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="+j(o,"unknown")+")";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(l)}}}return await mn(1e3),await r()};return await r()}async function bt(e,t){let r=dn(t.image);if(r.TAG!=="Ok")return{TAG:"Error",_0:r._0};let n=await Q(e,"POST","/v1/machines",{TAG:"JsonBody",_0:fn(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:g("machine create returned no machine id")}};let l=ae(o,"id");if(l===void 0)return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:g("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 _n(f);return m.TAG==="Ok"?{TAG:"Ok",_0:f}:(await We(f),{TAG:"Error",_0:m._0})}import*as jt from"node:fs";import*as $t from"node:path";import*as Ut from"node:fs/promises";function Pt(e){return"'"+e.replaceAll("'","'\\''")+"'"}import*as Ft from"node:crypto";function Mt(e){return Ft.createHash("sha256").update(e).digest("hex")}var J="/home/agent",Tn=J+"/.linzumi-provisioned",Vt="v1",Bt=J+"/cloud-supervisor.mjs",zt=J+"/mcp-server.mjs",It=J+"/.secrets",Lt=J+"/.codex",Ht="/etc/ssl/certs/ca-certificates.crt",yn=new RegExp("[^A-Za-z0-9._-]","g");function Wt(e){return J+"/.linzumi-provisioned-"+Vt+"-"+e.replace(yn,"_")}function En(e){return["/bin/sh","-c",["set -e","mkdir -p "+J+" "+It+" "+Lt,"chmod 700 "+It+" "+Lt,"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@"+Pt(e)+" >/dev/null","rm -f "+J+"/.linzumi-provisioned-"+Vt+"-* 2>/dev/null || true","touch "+Wt(e),"touch "+Tn].join(" && ")]}function qt(e){return"test -f "+Wt(e)+" && command -v codex >/dev/null && command -v node >/dev/null && "}function An(e){return["/bin/sh","-c",qt(e)+"command -v bwrap >/dev/null && test -s "+Ht]}function xn(e){return["/bin/sh","-c","if "+qt(e)+("command -v bwrap >/dev/null && test -s "+Ht+"; ")+"then echo TOOLCHAIN_OK; else echo TOOLCHAIN_MISSING; fi; "+("echo BUNDLE_SUP $(sha256sum "+Bt+" 2>/dev/null | cut -d' ' -f1); ")+("echo BUNDLE_MCP $(sha256sum "+zt+" 2>/dev/null | cut -d' ' -f1)")]}var On=new RegExp("^[0-9a-f]{64}$");function vn(e){let t=e.split(`
7
- `).map(n=>n.trim()),r=n=>ye($(t.find(i=>i.startsWith(n+" ")),i=>i.slice(n.length+1|0).trim()),i=>On.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 Rt(e,t){let r;try{r={TAG:"Ok",_0:await Ut.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:g("could not read "+t+" bundle at "+e+": "+r._0)}};let n=r._0;return n.trim()===""?{TAG:"Error",_0:{TAG:"Thrown",_0:g(t+" bundle at "+e+" is empty")}}:{TAG:"Ok",_0:n}}function Dt(e,t){let r=$t.join(e,t);if(jt.existsSync(r))return r}async function Jt(e,t,r){let n=Dt(r,"cloud-supervisor.mjs"),i=Dt(r,"mcp-server.mjs");if(n===void 0)return{TAG:"Error",_0:{TAG:"Thrown",_0:g("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:g("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 Rt(n,"cloud-supervisor.mjs");if(o.TAG!=="Ok")return{TAG:"Error",_0:o._0};let l=o._0,f=await Rt(i,"mcp-server.mjs");if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await z(e,xn(t),{timeout:30}),u;if(p.TAG==="Ok"){let _=p._0;u=B(_.exitCode)?vn(_.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 _=await z(e,En(t),{timeout:600});if(_.TAG==="Ok"){let h=_._0,A=h.exitCode;if(B(A)){let k=await z(e,An(t),{timeout:30});s=k.TAG==="Ok"?B(k._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Thrown",_0:g("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 "+wt(A)+"): "+h.stderr.slice(0,400);s={TAG:"Error",_0:{TAG:"Thrown",_0:g(k)}}}}else s={TAG:"Error",_0:_._0}}else s={TAG:"Ok",_0:void 0};let a=(_,h)=>c?!0:X(_,Mt(h));if(s.TAG!=="Ok")return{TAG:"Error",_0:s._0};let d=a(ue(u,_=>_.supervisorSha256),l)?await Oe(e,Bt,l,420):{TAG:"Ok",_0:void 0};return d.TAG==="Ok"?a(ue(u,_=>_.mcpSha256),m)?await Oe(e,zt,m,420):{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:d._0}}var ti=Hr(Gr(),1);var Sr=new RegExp("(\\d+\\.\\d+\\.\\d+)");function wr(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 ii(e,t){let r=wr(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 gr(e,t,r){let n;if(e===0&&t.length<=1048576){let i=Sr.exec(t);n=i==null?void 0:ue(i.slice(1)[0],o=>o)}else n=void 0;return ii(n,r)}var at="/opt/linzumi/hosted-coding-account-auth.mjs",De="/home/agent/.linzumi-hosted-auth",Fr=De+"/authorization-code.sock",ui="smolmachine:linzumi-agent-vm:codex-0.139.0-claude-2.1.260-v8",ut="coding-account-authorization";function li(e){return e==="Codex"?"codex":"claude_code"}function ai(e){switch(e){case"claude_code":return"ClaudeCode";case"codex":return"Codex";default:return}}function ci(e){return e==="Codex"?2048:4096}var Mr="hosted coding-account authorization and machine cleanup both failed";function si(e){switch(e.TAG){case"Failed":return e._0;case"CloudFailed":return Be(e._0);case"Cleanup":return Mr}}function Ir(e){switch(e.TAG){case"Failed":case"CloudFailed":return new Error(si(e));case"Cleanup":return new AggregateError([Ir(e.primary),new Error(Be(e.cleanup))],Mr)}}function ot(e){return e.TAG==="Ok"?Promise.resolve():Promise.reject(Ir(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 Lr={TAG:"Failed",_0:"hosted coding-account authorization compute is unavailable"};function di(){return lt.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 fi(){try{return{TAG:"Ok",_0:await Pr.readFile(di(),"utf8")}}catch(e){let t=U(e);return{TAG:"Error",_0:{TAG:"Failed",_0:q(t)}}}}async function mi(e,t){let r=ze(process.env);if(r===void 0)return{TAG:"Error",_0:Lr};let n=await bt(r,{image:ui,name:"linzumi-auth-"+e,cpus:2,memoryMb:ci(t),diskGb:20,env:[["LINZUMI_ROLE",ut]],labels:[[He,ut]],autoStopSeconds:900,ttlSeconds:900});return _t(n,i=>({TAG:"CloudFailed",_0:i}))}async function kr(e,t,r){let n=await z(e,t,void 0);return n.TAG==="Ok"?B(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 _i(e){let t=await Jt(e,Ue,Nr.dirname(lt.fileURLToPath(import.meta.url)));if(t.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:t._0}};let r=await z(e,["codex","--version"],{timeout:10});if(r.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:r._0}};let n=r._0,i=B(n.exitCode)?0:1,o=gr(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 pi(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 Ct(e,["node",at,f],{env:[["LINZUMI_HOSTED_AUTH_CALLBACK_URL",n],["LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN",i],["LINZUMI_HOSTED_AUTH_ROOT",De],["LINZUMI_HOSTED_AUTH_EXPIRES_AT",o],["LINZUMI_HOSTED_AUTH_HARNESS",li(r)],["LINZUMI_HOSTED_AUTH_WORKER_ID",e.id],["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]],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"}}}}),p=l.contents;return m.TAG==="Ok"?p!==void 0&&B(p)?{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 hi(e,t,r,n,i,o){let l;if(l=r==="Codex"?await _i(e):{TAG:"Ok",_0:void 0},l.TAG!=="Ok")return{TAG:"Error",_0:l._0};let f=await fi();if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await kr(e,["mkdir","-p",De],"auth-root creation");if(m.TAG!=="Ok")return{TAG:"Error",_0:m._0};let p=await kr(e,["chmod","700",De],"auth-root permission");if(p.TAG!=="Ok")return{TAG:"Error",_0:p._0};let u=await Oe(e,at,f._0,448);return u.TAG==="Ok"?await pi(e,t,r,n,i,o):{TAG:"Error",_0:{TAG:"CloudFailed",_0:u._0}}}async function Cr(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(ai(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 _=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=_.TAG==="Ok"?{TAG:"Ok",_0:[n._0,s._0,a._0,d._0,_._0]}:_}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 mi(o[0],l);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await hi(m,t,l,o[2],o[4],o[3]),u=await We(m);return u.TAG==="Ok"?p:p.TAG==="Ok"?{TAG:"Error",_0:{TAG:"CloudFailed",_0:u._0}}:{TAG:"Error",_0:{TAG:"Cleanup",primary:p._0,cleanup:u._0}}}var br="invalid hosted authorization code input";function Ti(e){return new Promise((t,r)=>{let n={contents:""},i=()=>{e.removeListener("data",l),e.removeListener("end",f),e.removeListener("error",m),e.destroy()},o=()=>{let p=n.contents.indexOf(`
8
- `),c=(p!==-1?n.contents.slice(0,p):n.contents).trim();return i(),c===""||Buffer.byteLength(c,"utf8")>4096?t({TAG:"Error",_0:{TAG:"Failed",_0:br}}):t({TAG:"Ok",_0:c})},l=p=>(n.contents=n.contents+p.toString(),Buffer.byteLength(n.contents,"utf8")>4097?(i(),t({TAG:"Error",_0:{TAG:"Failed",_0:br}})):n.contents.includes(`
9
- `)?o():void 0),f=()=>o(),m=()=>{i(),t({TAG:"Error",_0:{TAG:"Failed",_0:"hosted authorization code input failed"}})};e.on("data",l),e.once("end",f),e.once("error",m)})}async function yi(e){let t=he(e,"--attempt-id"),r;if(t.TAG==="Ok"){let p=he(e,"--machine-id");if(p.TAG==="Ok"){let u=V(ze(process.env),{TAG:"Error",_0:Lr},c=>({TAG:"Ok",_0:c}));r=u.TAG==="Ok"?{TAG:"Ok",_0:[t._0,{conn:u._0,id:p._0}]}:u}else r=p}else r=t;if(r.TAG!=="Ok")return{TAG:"Error",_0:r._0};let n=r._0,i=n[1],o=await St(i);if(o.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:o._0}};let l=o._0;if(X(l.id,i.id)||X(l.name,"linzumi-auth-"+n[0])||X(l.role,ut))return{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization worker identity mismatch"}};let f=await Ti(process.stdin);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await z(i,["node",at,"--hosted-coding-account-auth-submit"],{env:[["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]],timeout:30,stdin:f._0+`
10
- `});return m.TAG==="Ok"?B(m._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization code delivery failed"}}:{TAG:"Error",_0:{TAG:"CloudFailed",_0:m._0}}}function Rr(e){let t=e.slice(1),r=e[0];if(r===void 0)return Promise.reject(new Error("unsupported hosted account command: undefined"));switch(r){case"hosted-coding-account-auth":return Cr(t,"Authorization").then(ot);case"hosted-coding-account-auth-submit":return yi(t).then(ot);case"hosted-coding-account-model-catalog":return Cr(t,"ModelCatalog").then(ot);default:return Promise.reject(new Error("unsupported hosted account command: "+r))}}var Ki=Rr;export{Ki as main};
3
+ var jr=Object.create;var dt=Object.defineProperty;var $r=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var Vr=Object.getPrototypeOf,Br=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 R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var zr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ur(t))!Br.call(e,i)&&i!==r&&dt(e,i,{get:()=>t[i],enumerable:!(n=$r(t,i))||n.enumerable});return e};var Hr=(e,t,r)=>(r=e!=null?jr(Vr(e)):{},zr(t||!e||!e.__esModule?dt(r,"default",{value:e,enumerable:!0}):r,e));var Zt=R((Fi,Kt)=>{var K=W("constants"),kn=process.cwd,ke=null,Cn=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ke||(ke=kn.call(process)),ke};try{process.cwd()}catch{}typeof process.chdir=="function"&&(qe=process.chdir,process.chdir=function(e){ke=null,qe.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,qe));var qe;Kt.exports=bn;function bn(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=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=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,l,s){s&&process.nextTick(s)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(u,l,s,c){c&&process.nextTick(c)},e.lchownSync=function(){}),Cn==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:(function(u){function l(s,c,d){var _=Date.now(),h=0;u(s,c,function y(k){if(k&&(k.code==="EACCES"||k.code==="EPERM"||k.code==="EBUSY")&&Date.now()-_<6e4){setTimeout(function(){e.stat(c,function(I,Te){I&&I.code==="ENOENT"?u(s,c,y):d(k)})},h),h<100&&(h+=10);return}d&&d(k)})}return Object.setPrototypeOf&&Object.setPrototypeOf(l,u),l})(e.rename)),e.read=typeof e.read!="function"?e.read:(function(u){function l(s,c,d,_,h,y){var k;if(y&&typeof y=="function"){var I=0;k=function(Te,ct,st){if(Te&&Te.code==="EAGAIN"&&I<10)return I++,u.call(e,s,c,d,_,h,k);y.apply(this,arguments)}}return u.call(e,s,c,d,_,h,k)}return Object.setPrototypeOf&&Object.setPrototypeOf(l,u),l})(e.read),e.readSync=typeof e.readSync!="function"?e.readSync:(function(u){return function(l,s,c,d,_){for(var h=0;;)try{return u.call(e,l,s,c,d,_)}catch(y){if(y.code==="EAGAIN"&&h<10){h++;continue}throw y}}})(e.readSync);function t(u){u.lchmod=function(l,s,c){u.open(l,K.O_WRONLY|K.O_SYMLINK,s,function(d,_){if(d){c&&c(d);return}u.fchmod(_,s,function(h){u.close(_,function(y){c&&c(h||y)})})})},u.lchmodSync=function(l,s){var c=u.openSync(l,K.O_WRONLY|K.O_SYMLINK,s),d=!0,_;try{_=u.fchmodSync(c,s),d=!1}finally{if(d)try{u.closeSync(c)}catch{}else u.closeSync(c)}return _}}function r(u){K.hasOwnProperty("O_SYMLINK")&&u.futimes?(u.lutimes=function(l,s,c,d){u.open(l,K.O_SYMLINK,function(_,h){if(_){d&&d(_);return}u.futimes(h,s,c,function(y){u.close(h,function(k){d&&d(y||k)})})})},u.lutimesSync=function(l,s,c){var d=u.openSync(l,K.O_SYMLINK),_,h=!0;try{_=u.futimesSync(d,s,c),h=!1}finally{if(h)try{u.closeSync(d)}catch{}else u.closeSync(d)}return _}):u.futimes&&(u.lutimes=function(l,s,c,d){d&&process.nextTick(d)},u.lutimesSync=function(){})}function n(u){return u&&function(l,s,c){return u.call(e,l,s,function(d){p(d)&&(d=null),c&&c.apply(this,arguments)})}}function i(u){return u&&function(l,s){try{return u.call(e,l,s)}catch(c){if(!p(c))throw c}}}function o(u){return u&&function(l,s,c,d){return u.call(e,l,s,c,function(_){p(_)&&(_=null),d&&d.apply(this,arguments)})}}function a(u){return u&&function(l,s,c){try{return u.call(e,l,s,c)}catch(d){if(!p(d))throw d}}}function f(u){return u&&function(l,s,c){typeof s=="function"&&(c=s,s=null);function d(_,h){h&&(h.uid<0&&(h.uid+=4294967296),h.gid<0&&(h.gid+=4294967296)),c&&c.apply(this,arguments)}return s?u.call(e,l,s,d):u.call(e,l,d)}}function m(u){return u&&function(l,s){var c=s?u.call(e,l,s):u.call(e,l);return c&&(c.uid<0&&(c.uid+=4294967296),c.gid<0&&(c.gid+=4294967296)),c}}function p(u){if(!u||u.code==="ENOSYS")return!0;var l=!process.getuid||process.getuid()!==0;return!!(l&&(u.code==="EINVAL"||u.code==="EPERM"))}}});var Qt=R((Mi,Xt)=>{var Yt=W("stream").Stream;Xt.exports=Nn;function Nn(e){return{ReadStream:t,WriteStream:r};function t(n,i){if(!(this instanceof t))return new t(n,i);Yt.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 a=Object.keys(i),f=0,m=a.length;f<m;f++){var p=a[f];this[p]=i[p]}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,l){if(u){o.emit("error",u),o.readable=!1;return}o.fd=l,o.emit("open",l),o._read()})}function r(n,i){if(!(this instanceof r))return new r(n,i);Yt.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),a=0,f=o.length;a<f;a++){var m=o[a];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 tr=R((Ii,er)=>{"use strict";er.exports=Fn;var Pn=Object.getPrototypeOf||function(e){return e.__proto__};function Fn(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Pn(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Ye=R((Li,Ze)=>{var S=W("fs"),Mn=Zt(),In=Qt(),Ln=tr(),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 Rn(){}function ir(e,t){Object.defineProperty(e,M,{get:function(){return t}})}var ee=Rn;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]||(rr=global[M]||[],ir(S,rr),S.close=(function(e){function t(r,n){return e.call(S,r,function(i){i||nr(),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),nr()}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 rr;global[M]||ir(global,S[M]);Ze.exports=Je(Ln(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Ze.exports=Je(S),S.__patched=!0);function Je(e){Mn(e),e.gracefulify=Je,e.createReadStream=ct,e.createWriteStream=st;var t=e.readFile;e.readFile=r;function r(T,E,A){return typeof E=="function"&&(A=E,E=null),N(T,E,A);function N(P,C,G,w){return t(P,C,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?de([N,[P,C,G],x,w||Date.now(),Date.now()]):typeof G=="function"&&G.apply(this,arguments)})}}var n=e.writeFile;e.writeFile=i;function i(T,E,A,N){return typeof A=="function"&&(N=A,A=null),P(T,E,A,N);function P(C,G,w,x,F){return n(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,G,w,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var o=e.appendFile;o&&(e.appendFile=a);function a(T,E,A,N){return typeof A=="function"&&(N=A,A=null),P(T,E,A,N);function P(C,G,w,x,F){return o(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,G,w,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,A,N){return typeof A=="function"&&(N=A,A=0),P(T,E,A,N);function P(C,G,w,x,F){return f(C,G,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,G,w,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var p=e.readdir;e.readdir=l;var u=/^v[0-5]\./;function l(T,E,A){typeof E=="function"&&(A=E,E=null);var N=u.test(process.version)?function(G,w,x,F){return p(G,P(G,w,x,F))}:function(G,w,x,F){return p(G,w,P(G,w,x,F))};return N(T,E,A);function P(C,G,w,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?de([N,[C,G,w],F,x||Date.now(),Date.now()]):(O&&O.sort&&O.sort(),typeof w=="function"&&w.call(this,F,O))}}}if(process.version.substr(0,4)==="v0.8"){var s=In(e);y=s.ReadStream,I=s.WriteStream}var c=e.ReadStream;c&&(y.prototype=Object.create(c.prototype),y.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 y},set:function(T){y=T},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return I},set:function(T){I=T},enumerable:!0,configurable:!0});var _=y;Object.defineProperty(e,"FileReadStream",{get:function(){return _},set:function(T){_=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 y(T,E){return this instanceof y?(c.apply(this,arguments),this):y.apply(Object.create(y.prototype),arguments)}function k(){var T=this;je(T.path,T.flags,T.mode,function(E,A){E?(T.autoClose&&T.destroy(),T.emit("error",E)):(T.fd=A,T.emit("open",A),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;je(T.path,T.flags,T.mode,function(E,A){E?(T.destroy(),T.emit("error",E)):(T.fd=A,T.emit("open",A))})}function ct(T,E){return new e.ReadStream(T,E)}function st(T,E){return new e.WriteStream(T,E)}var Dr=e.open;e.open=je;function je(T,E,A,N){return typeof A=="function"&&(N=A,A=null),P(T,E,A,N);function P(C,G,w,x,F){return Dr(C,G,w,function(O,Oi){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,G,w,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}return e}function de(e){ee("ENQUEUE",e[0].name,e[1]),S[M].push(e),Ke()}var be;function nr(){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);Ke()}function Ke(){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 a=r.pop();typeof a=="function"&&a.call(null,n)}else{var f=Date.now()-o,m=Math.max(o-i,1),p=Math.min(m*1.2,100);f>=p?(ee("RETRY",t.name,r),t.apply(null,r.concat([i]))):S[M].push(e)}be===void 0&&(be=setTimeout(Ke,0))}}});var ur=R((Ri,or)=>{function D(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))}or.exports=D;D.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};D.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};D.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};D.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)};D.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};D.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};D.prototype.start=D.prototype.try;D.prototype.errors=function(){return this._errors};D.prototype.attempts=function(){return this._attempts};D.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,a=(e[o]||0)+1;e[o]=a,a>=r&&(t=i,r=a)}return t}});var lr=R(te=>{var Dn=ur();te.operation=function(e){var t=te.timeouts(e);return new Dn(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,a){return o-a}),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],a=e[o];e[o]=function(m){var p=te.operation(t),u=Array.prototype.slice.call(arguments,1),l=u.pop();u.push(function(s){p.retry(s)||(s&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){m.apply(e,u)})}.bind(e,a),e[o].options=t}}});var cr=R((ji,ar)=>{ar.exports=lr()});var sr=R(($i,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 pr=R((Ui,_e)=>{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)?(dr=W("assert"),fe=sr(),fr=/^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),_e.exports=function(e,t){if(!re(global.process))return function(){};dr.equal(typeof e,"function","a callback must be provided for exit handler"),me===!1&&Xe();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(){!me||!re(global.process)||(me=!1,fe.forEach(function(t){try{v.removeListener(t,Me[t])}catch{}}),v.emit=Ie,v.reallyExit=Qe,b.count-=1)},_e.exports.unload=Fe,ne=function(t,r,n){b.emitted[t]||(b.emitted[t]=!0,b.emit(t,r,n))},Me={},fe.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),fr&&e==="SIGHUP"&&(e="SIGINT"),v.kill(v.pid,e))}}}),_e.exports.signals=function(){return fe},me=!1,Xe=function(){me||!re(global.process)||(me=!0,b.count+=1,fe=fe.filter(function(t){try{return v.on(t,Me[t]),!0}catch{return!1}}),v.emit=_r,v.reallyExit=mr)},_e.exports.load=Xe,Qe=v.reallyExit,mr=function(t){re(global.process)&&(v.exitCode=t||0,ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),Qe.call(v,v.exitCode))},Ie=v.emit,_r=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)}):_e.exports=function(){return function(){}};var dr,fe,fr,ve,b,Fe,ne,Me,me,Xe,Qe,mr,Ie,_r});var Er=R((Vi,Ge)=>{"use strict";var jn=W("path"),rt=Ye(),$n=cr(),Un=pr(),H={};function pe(e,t){return t.lockfilePath||`${e}.lock`}function nt(e,t,r){if(!t.realpath)return r(null,jn.resolve(e));t.fs.realpath(e,r)}function et(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"?et(e,{...t,stale:0},r):r(i);if(!Tr(o,t))return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));yr(e,t,a=>{if(a)return r(a);et(e,{...t,stale:0},r)})})})}function Tr(e,t){return e.mtime.getTime()<Date.now()-t.stale}function yr(e,t,r){t.fs.rmdir(pe(e,t),n=>{if(n&&n.code!=="ENOENT")return r(n);r()})}function tt(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 hr(e,r,o)}if(i)return i.code==="ENOENT"?hr(e,r,Object.assign(i,{code:"ECOMPROMISED"})):(r.updateError=i,r.updateDelay=1e3,tt(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,tt(e,t)}})},r.updateDelay),r.updateTimeout.unref&&r.updateTimeout.unref())}function hr(e,t,r){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),H[e]===t&&delete H[e],t.options.onCompromised(r)}function Vn(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:rt,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),nt(e,t,(n,i)=>{if(n)return r(n);let o=$n.operation(t.retries);o.attempt(()=>{et(i,t,a=>{if(o.retry(a))return;if(a)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};tt(i,t),r(null,m=>{if(f.released)return m&&m(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Ar(i,{...t,realpath:!1},m)})})})})}function Ar(e,t,r){t={fs:rt,realpath:!0,...t},nt(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],yr(i,t,r)})}function Bn(e,t,r){t={stale:1e4,realpath:!0,fs:rt,...t},t.stale=Math.max(t.stale||0,2e3),nt(e,t,(n,i)=>{if(n)return r(n);t.fs.stat(pe(i,t),(o,a)=>o?o.code==="ENOENT"?r(null,!1):r(o):r(null,!Tr(a,t)))})}function zn(){return H}Un(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(pe(e,t))}catch{}}});Ge.exports.lock=Vn;Ge.exports.unlock=Ar;Ge.exports.check=Bn;Ge.exports.getLocks=zn});var Or=R((Bi,xr)=>{"use strict";var Hn=Ye();function Wn(e){let t=["mkdir","realpath","stat","rmdir","utimes"],r={...e};return t.forEach(n=>{r[n]=(...i)=>{let o=i.pop(),a;try{a=e[`${n}Sync`](...i)}catch(f){return o(f)}o(null,a)}}),r}function qn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Jn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function Kn(e){if(e={...e},e.fs=Wn(e.fs||Hn),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}xr.exports={toPromise:qn,toSync:Jn,toSyncOptions:Kn}});var Gr=R((zi,Z)=>{"use strict";var he=Er(),{toPromise:Le,toSync:Re,toSyncOptions:it}=Or();async function vr(e,t){let r=await Le(he.lock)(e,t);return Le(r)}function Zn(e,t){let r=Re(he.lock)(e,it(t));return Re(r)}function Yn(e,t){return Le(he.unlock)(e,t)}function Xn(e,t){return Re(he.unlock)(e,it(t))}function Qn(e,t){return Le(he.check)(e,t)}function ei(e,t){return Re(he.check)(e,it(t))}Z.exports=vr;Z.exports.lock=vr;Z.exports.unlock=Yn;Z.exports.lockSync=Zn;Z.exports.unlockSync=Xn;Z.exports.check=Qn;Z.exports.checkSync=ei});import*as lt from"node:url";import*as Nr from"node:path";function oe(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 oe(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 mt(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 oe(t(L(e)))}function le(e,t){if(e!==void 0)return t(L(e))}function j(e,t){return e!==void 0?L(e):t}function _t(e,t){return e.TAG==="Ok"?e:{TAG:"Error",_0:t(e._0)}}var Tt=(function(e,t){for(var r in e)t(r)});function ae(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 a=e.length|0,f=t.length|0;if(a===f)if(Array.isArray(e)){let m=0;for(;;){let p=m;if(p===a)return!0;if(!ae(e[p],t[p]))return!1;m=p+1|0}}else{if(e instanceof Date&&t instanceof Date)return!(e>t||e<t);{let m={contents:!0},p=l=>{if(!Object.prototype.hasOwnProperty.call(t,l)){m.contents=!1;return}},u=l=>{if(!Object.prototype.hasOwnProperty.call(e,l)||!ae(t[l],e[l])){m.contents=!1;return}};return Tt(e,p),m.contents&&Tt(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:!ae(e,t)}import*as Pr from"node:fs/promises";function Zr(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function U(e){return Zr(e)?e:{RE_EXN_ID:"JsExn",_1:e}}var yt={name:"@linzumi/cli",version:"1.0.343",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","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",prepack:"rescript build -q ../linzumi-cli-rescript && node scripts/build.mjs","pack:dry-run":"npm pack --dry-run","test:startup":"npm run build && node --test --test-concurrency=1 ../linzumi-cli-rescript/src/parity/CommanderStartupRefusalConformance.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.322","@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 Xr=yt,Ue=Xr.dependencies["@openai/codex"];function xe(e){if(e.RE_EXN_ID==="JsExn")return oe(e._1)}var Se=(e=>t=>t&&typeof t[e]=="string"?t[e]:void 0),ki=Se("stack"),we=Se("message"),At=Se("name"),Ci=Se("fileName");var en=new RegExp("\\bsmk_[A-Za-z0-9._-]+","g");function g(e){return e.replace(en,"smk_[REDACTED]")}var tn="https://api.smolmachines.com";function Be(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 j(we(r),String(r))}function Ot(e){let t=xe(e);return t!==void 0?ae(At(L(t)),"AbortError"):!1}var rn=new RegExp("\\/+$");function xt(e,t){let r=e[t];if(r===void 0)return;let n=r.trim();if(n!=="")return n}function ze(e){let t=xt(e,"SMOLCLOUD_API_KEY");return $(t!==void 0?t:xt(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:j(e.SMOLCLOUD_BASE_URL,tn).replace(rn,""),apiKey:r}))}async function ge(e,t){try{return{TAG:"Ok",_0:await fetch(e,t)}}catch(r){return{TAG:"Error",_0:U(r)}}}async function vt(e){try{return await e.text()}catch{return""}}function Gt(e,t){return t===""?e.toString():e.toString()+": "+t}async function Q(e,t,r,n,i){let o=n!==void 0?n:"NoBody",a=i!==void 0?i:3e4,f=Object.fromEntries([["authorization","Bearer "+e.apiKey]]),m=new AbortController,p=setTimeout(()=>{m.abort()},a),u=e.baseUrl+r,l=m.signal,s;if(typeof o!="object"?s=await ge(u,{method:t,headers:f,body:null,signal:l}):o.TAG==="JsonBody"?(f["content-type"]="application/json",s=await ge(u,{method:t,headers:f,body:JSON.stringify(o._0),signal:l})):(f["content-type"]="application/octet-stream",s=await ge(u,{method:t,headers:f,body:o._0,signal:l})),clearTimeout(p),s.TAG==="Ok"){let c=s._0;if(c.ok){if(c.status===204)return{TAG:"Ok",_0:"NoPayload"};if(!j($e(c.headers.get("content-type")),"").includes("application/json"))return{TAG:"Ok",_0:"NoPayload"};try{return{TAG:"Ok",_0:{TAG:"Payload",_0:await c.json()}}}catch(d){let _=U(d);return{TAG:"Error",_0:{TAG:"Thrown",_0:q(_)}}}}else{let d=c.status,_=await vt(c),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 y="smolcloud "+t+" "+r+" \u2192 "+Gt(d,_);return{TAG:"Error",_0:{TAG:"Smolcloud",code:h,message:g(y)}}}}else{let c=s._0;if(Ot(c)){let _="smolcloud "+t+" "+r+" timed out after "+a.toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(_)}}}let d="smolcloud request failed: "+q(c);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:g(d)}}}}function se(e){return"/v1/machines/"+e.id}var He="linzumi-role";function ce(e,t){let r=e[t];if(typeof r=="string")return r}function nn(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.labels,a;return a=typeof o=="object"&&o!==null&&!Array.isArray(o)?ce(o,He):void 0,{id:i,name:ce(r,"name"),role:a}}}return{id:e.id,name:void 0,role:void 0}}async function St(e){let t=await Q(e.conn,"GET",se(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:nn(e,t._0)}:{TAG:"Error",_0:t._0}}function B(e){return e.TAG==="Numeric"?e._0===0:!1}function wt(e){return e.TAG==="Numeric"?e._0.toString():String(e._0)}function gt(e,t){return Object.fromEntries([["command",e.map(r=>r)],["env",Object.fromEntries(j(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 kt(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 on(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:kt(t.exitCode),stdout:j(ce(t,"stdout"),""),stderr:j(ce(t,"stderr"),"")}}:{TAG:"Ok",_0:{exitCode:{TAG:"Numeric",_0:0},stdout:"",stderr:""}}}async function z(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,a=await Q(e.conn,"POST",se(e)+"/exec",{TAG:"JsonBody",_0:gt(t,n)},o);return a.TAG==="Ok"?on(a._0):{TAG:"Error",_0:a._0}}function un(e){let t;try{t=JSON.parse(e)}catch{t=void 0}return t!==void 0?typeof t=="object"&&t!==null&&!Array.isArray(t)?kt(t.exitCode):{TAG:"Numeric",_0:0}:{TAG:"Numeric",_0:0}}function ln(e,t){switch(e){case"error":return{TAG:"StreamError",_0:g(t)};case"exit":return{TAG:"Exit",_0:un(t)};case"stderr":return{TAG:"Stderr",_0:t};case"stdout":return{TAG:"Stdout",_0:t};default:return}}var an=new RegExp("^ ");async function cn(e,t){let r=e.getReader(),n=new TextDecoder,i={contents:""},o={contents:""},a={contents:[]},f=()=>{let l=o.contents,s=a.contents.join(`
5
+ `);o.contents="",a.contents=[];let c=ln(l,s);return c!==void 0?t(c):"Continue"},m=()=>{for(;;){let l=i.contents.indexOf(`
6
+ `);if(l===-1)return"Continue";let s=i.contents.slice(0,l);i.contents=i.contents.slice(l+1|0);let c=s.endsWith("\r")?s.slice(0,-1):s,d=c===""?f():(c.startsWith("event:")?o.contents=c.slice(6).trim():c.startsWith("data:")&&a.contents.push(c.slice(5).replace(an,"")),"Continue");if(typeof d=="object")return d}},p=async()=>{let l;try{l={TAG:"Ok",_0:await r.read()}}catch(_){l={TAG:"Error",_0:U(_)}}if(l.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"Thrown",_0:q(l._0)}};let s=l._0;if(s.done){let _=f();return typeof _!="object"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:_._0}}let c=s.value;c!=null&&(i.contents=i.contents+n.decode(c,{stream:!0}));let d=m();return typeof d!="object"?await p():{TAG:"Error",_0:d._0}},u=await p();return r.releaseLock(),u}async function Ct(e,t,r,n){let i=new AbortController,o=$(r.timeout,l=>setTimeout(()=>{i.abort()},(l*1e3|0)+3e4|0)),a=()=>mt(o,l=>{clearTimeout(l)}),f=se(e)+"/exec/stream",m=await ge(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(gt(t,r)),signal:i.signal});if(m.TAG==="Ok"){let l=m._0,s;if(l.ok){let c=l.body;s=c==null?{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:g("exec/stream returned no response body")}}:await cn(c,n)}else{let c=l.status,d=await vt(l),_="smolcloud POST "+f+" \u2192 "+Gt(c,d);s={TAG:"Error",_0:{TAG:"Smolcloud",code:c===404?"NotFound":"CloudError",message:g(_)}}}return a(),s}let p=m._0;if(a(),Ot(p)){let s="smolcloud exec/stream timed out after "+((j(r.timeout,0)*1e3|0)+3e4|0).toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(s)}}}let u="smolcloud exec/stream failed: "+q(p);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:g(u)}}}function sn(e){return e.split("/").map(t=>encodeURIComponent(t)).join("/")}async function Oe(e,t,r,n){let i=await Q(e.conn,"PUT",se(e)+"/files/"+sn(t),{TAG:"BytesBody",_0:Buffer.from(r,"utf8")},void 0);if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=await z(e,["chmod",n.toString(8),t],void 0);return o.TAG==="Ok"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:o._0}}async function We(e){let t=await Q(e.conn,"DELETE",se(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:t._0}}function dn(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=(a,f)=>({TAG:"Ok",_0:Object.fromEntries([["type","smolmachine"],["reference",a],["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 a="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:g(a)}}}return n(r.slice(0,i),o)}function fn(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]]))],["labels",Object.fromEntries(e.labels.map(r=>[r[0],r[1]]))],["autoStopSeconds",e.autoStopSeconds],["ttlSeconds",e.ttlSeconds]])}function mn(e){return new Promise((t,r)=>{setTimeout(()=>t(),e)})}async function _n(e){let t=Date.now()+12e4,r=async()=>{let n=await Q(e.conn,"GET",se(e),void 0,void 0),i;if(n.TAG==="Ok"){let a=n._0;if(typeof a!="object")i={TAG:"Ok",_0:void 0};else{let f=a._0;i=typeof f=="object"&&f!==null&&!Array.isArray(f)?{TAG:"Ok",_0:ce(f,"state")}:{TAG:"Ok",_0:void 0}}}else{let a=n._0;if(a.TAG==="Smolcloud")switch(a.code){case"Unauthorized":case"NotFound":i={TAG:"Error",_0:a};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:g("machine "+e.id+" entered error state while starting")}};case"running":case"started":return{TAG:"Ok",_0:void 0}}if(Date.now()>=t){let a="machine "+e.id+" not ready after 120000ms (state="+j(o,"unknown")+")";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(a)}}}return await mn(1e3),await r()};return await r()}async function bt(e,t){let r=dn(t.image);if(r.TAG!=="Ok")return{TAG:"Error",_0:r._0};let n=await Q(e,"POST","/v1/machines",{TAG:"JsonBody",_0:fn(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:g("machine create returned no machine id")}};let a=ce(o,"id");if(a===void 0)return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:g("machine create returned no machine id")}};let f={conn:e,id:a};await Q(e,"POST","/v1/machines/"+a+"/start",void 0,void 0);let m=await _n(f);return m.TAG==="Ok"?{TAG:"Ok",_0:f}:(await We(f),{TAG:"Error",_0:m._0})}import*as jt from"node:fs";import*as $t from"node:path";import*as Ut from"node:fs/promises";function Pt(e){return"'"+e.replaceAll("'","'\\''")+"'"}import*as Ft from"node:crypto";function Mt(e){return Ft.createHash("sha256").update(e).digest("hex")}var J="/home/agent",Tn=J+"/.linzumi-provisioned",Vt="v1",Bt=J+"/cloud-supervisor.mjs",zt=J+"/mcp-server.mjs",It=J+"/.secrets",Lt=J+"/.codex",Ht="/etc/ssl/certs/ca-certificates.crt",yn=new RegExp("[^A-Za-z0-9._-]","g");function Wt(e){return J+"/.linzumi-provisioned-"+Vt+"-"+e.replace(yn,"_")}function An(e){return["/bin/sh","-c",["set -e","mkdir -p "+J+" "+It+" "+Lt,"chmod 700 "+It+" "+Lt,"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@"+Pt(e)+" >/dev/null","rm -f "+J+"/.linzumi-provisioned-"+Vt+"-* 2>/dev/null || true","touch "+Wt(e),"touch "+Tn].join(" && ")]}function qt(e){return"test -f "+Wt(e)+" && command -v codex >/dev/null && command -v node >/dev/null && "}function En(e){return["/bin/sh","-c",qt(e)+"command -v bwrap >/dev/null && test -s "+Ht]}function xn(e){return["/bin/sh","-c","if "+qt(e)+("command -v bwrap >/dev/null && test -s "+Ht+"; ")+"then echo TOOLCHAIN_OK; else echo TOOLCHAIN_MISSING; fi; "+("echo BUNDLE_SUP $(sha256sum "+Bt+" 2>/dev/null | cut -d' ' -f1); ")+("echo BUNDLE_MCP $(sha256sum "+zt+" 2>/dev/null | cut -d' ' -f1)")]}var On=new RegExp("^[0-9a-f]{64}$");function vn(e){let t=e.split(`
7
+ `).map(n=>n.trim()),r=n=>ye($(t.find(i=>i.startsWith(n+" ")),i=>i.slice(n.length+1|0).trim()),i=>On.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 Rt(e,t){let r;try{r={TAG:"Ok",_0:await Ut.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:g("could not read "+t+" bundle at "+e+": "+r._0)}};let n=r._0;return n.trim()===""?{TAG:"Error",_0:{TAG:"Thrown",_0:g(t+" bundle at "+e+" is empty")}}:{TAG:"Ok",_0:n}}function Dt(e,t){let r=$t.join(e,t);if(jt.existsSync(r))return r}async function Jt(e,t,r){let n=Dt(r,"cloud-supervisor.mjs"),i=Dt(r,"mcp-server.mjs");if(n===void 0)return{TAG:"Error",_0:{TAG:"Thrown",_0:g("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:g("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 Rt(n,"cloud-supervisor.mjs");if(o.TAG!=="Ok")return{TAG:"Error",_0:o._0};let a=o._0,f=await Rt(i,"mcp-server.mjs");if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await z(e,xn(t),{timeout:30}),u;if(p.TAG==="Ok"){let _=p._0;u=B(_.exitCode)?vn(_.stdout):void 0}else console.warn("cloud_agent_provision_preflight_unavailable",{reason:"transport_failure",codexVersion:t}),u=void 0;let l=u!==void 0?u.toolchain!=="ToolchainOk":!0,s;if(l){let _=await z(e,An(t),{timeout:600});if(_.TAG==="Ok"){let h=_._0,y=h.exitCode;if(B(y)){let k=await z(e,En(t),{timeout:30});s=k.TAG==="Ok"?B(k._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Thrown",_0:g("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 "+wt(y)+"): "+h.stderr.slice(0,400);s={TAG:"Error",_0:{TAG:"Thrown",_0:g(k)}}}}else s={TAG:"Error",_0:_._0}}else s={TAG:"Ok",_0:void 0};let c=(_,h)=>l?!0:X(_,Mt(h));if(s.TAG!=="Ok")return{TAG:"Error",_0:s._0};let d=c(le(u,_=>_.supervisorSha256),a)?await Oe(e,Bt,a,420):{TAG:"Ok",_0:void 0};return d.TAG==="Ok"?c(le(u,_=>_.mcpSha256),m)?await Oe(e,zt,m,420):{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:d._0}}var ti=Hr(Gr(),1);var Sr=new RegExp("(\\d+\\.\\d+\\.\\d+)");function wr(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 ii(e,t){let r=wr(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 gr(e,t,r){let n;if(e===0&&t.length<=1048576){let i=Sr.exec(t);n=i==null?void 0:le(i.slice(1)[0],o=>o)}else n=void 0;return ii(n,r)}var at="/opt/linzumi/hosted-coding-account-auth.mjs",De="/home/agent/.linzumi-hosted-auth",Fr=De+"/authorization-code.sock",ui="smolmachine:linzumi-agent-vm:codex-0.139.0-claude-2.1.260-v8",ut="coding-account-authorization";function li(e){return e==="Codex"?"codex":"claude_code"}function ai(e){switch(e){case"claude_code":return"ClaudeCode";case"codex":return"Codex";default:return}}function ci(e){return e==="Codex"?2048:4096}var Mr="hosted coding-account authorization and machine cleanup both failed";function si(e){switch(e.TAG){case"Failed":return e._0;case"CloudFailed":return Be(e._0);case"Cleanup":return Mr}}function Ir(e){switch(e.TAG){case"Failed":case"CloudFailed":return new Error(si(e));case"Cleanup":return new AggregateError([Ir(e.primary),new Error(Be(e.cleanup))],Mr)}}function ot(e){return e.TAG==="Ok"?Promise.resolve():Promise.reject(Ir(e._0))}function ie(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 Lr={TAG:"Failed",_0:"hosted coding-account authorization compute is unavailable"};function di(e,t){if(!e.includes("--ceremony"))return{TAG:"Ok",_0:"ProviderLogin"};if(t==="Codex")return{TAG:"Error",_0:{TAG:"Failed",_0:"unsupported hosted coding-account authorization ceremony"}};let n=ie(e,"--ceremony");return n.TAG==="Ok"&&n._0==="setup_token"?{TAG:"Ok",_0:"SetupToken"}:{TAG:"Error",_0:{TAG:"Failed",_0:"unsupported hosted coding-account authorization ceremony"}}}function fi(e){return e==="ProviderLogin"?[]:[["LINZUMI_HOSTED_AUTH_CLAUDE_CEREMONY","setup_token"]]}function mi(){return lt.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 _i(){try{return{TAG:"Ok",_0:await Pr.readFile(mi(),"utf8")}}catch(e){let t=U(e);return{TAG:"Error",_0:{TAG:"Failed",_0:q(t)}}}}async function pi(e,t){let r=ze(process.env);if(r===void 0)return{TAG:"Error",_0:Lr};let n=await bt(r,{image:ui,name:"linzumi-auth-"+e,cpus:2,memoryMb:ci(t),diskGb:20,env:[["LINZUMI_ROLE",ut]],labels:[[He,ut]],autoStopSeconds:900,ttlSeconds:900});return _t(n,i=>({TAG:"CloudFailed",_0:i}))}async function kr(e,t,r){let n=await z(e,t,void 0);return n.TAG==="Ok"?B(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 hi(e){let t=await Jt(e,Ue,Nr.dirname(lt.fileURLToPath(import.meta.url)));if(t.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:t._0}};let r=await z(e,["codex","--version"],{timeout:10});if(r.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:r._0}};let n=r._0,i=B(n.exitCode)?0:1,o=gr(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 Ti(e,t,r,n,i,o,a){let f={contents:void 0},m;m=t==="Authorization"?"--hosted-coding-account-auth":"--hosted-coding-account-model-catalog";let p=await Ct(e,["node",at,m],{env:[["LINZUMI_HOSTED_AUTH_CALLBACK_URL",n],["LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN",i],["LINZUMI_HOSTED_AUTH_ROOT",De],["LINZUMI_HOSTED_AUTH_EXPIRES_AT",o],["LINZUMI_HOSTED_AUTH_HARNESS",li(r)],["LINZUMI_HOSTED_AUTH_WORKER_ID",e.id],["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]].concat(fi(a)),timeout:630},l=>{switch(l.TAG){case"Stdout":case"Stderr":return"Continue";case"Exit":return f.contents=l._0,"Continue";case"StreamError":return{TAG:"Stop",_0:{TAG:"Thrown",_0:"hosted coding-account authorization guest failed"}}}}),u=f.contents;return p.TAG==="Ok"?u!==void 0&&B(u)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization guest exited unsuccessfully"}}:{TAG:"Error",_0:{TAG:"CloudFailed",_0:p._0}}}async function yi(e,t,r,n,i,o,a){let f;if(f=r==="Codex"?await hi(e):{TAG:"Ok",_0:void 0},f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await _i();if(m.TAG!=="Ok")return{TAG:"Error",_0:m._0};let p=await kr(e,["mkdir","-p",De],"auth-root creation");if(p.TAG!=="Ok")return{TAG:"Error",_0:p._0};let u=await kr(e,["chmod","700",De],"auth-root permission");if(u.TAG!=="Ok")return{TAG:"Error",_0:u._0};let l=await Oe(e,at,m._0,448);return l.TAG==="Ok"?await Ti(e,t,r,n,i,o,a):{TAG:"Error",_0:{TAG:"CloudFailed",_0:l._0}}}async function Cr(e,t){let r;r=t==="Authorization"?"--attempt-id":"--request-id";let n=ie(e,r),i;if(n.TAG==="Ok"){let l=ie(e,"--harness");if(l.TAG==="Ok"){let s=V(ai(l._0),{TAG:"Error",_0:{TAG:"Failed",_0:"unsupported hosted coding-account authorization harness"}},c=>({TAG:"Ok",_0:c}));if(s.TAG==="Ok"){let c=s._0,d=ie(e,"--callback-url");if(d.TAG==="Ok"){let _=ie(e,"--expires-at");if(_.TAG==="Ok"){let h=V(ye($(process.env.LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN,y=>y.trim()),y=>y!==""),{TAG:"Error",_0:{TAG:"Failed",_0:"hosted authorization callback token is unavailable"}},y=>({TAG:"Ok",_0:y}));if(h.TAG==="Ok"){let y=di(e,c);i=y.TAG==="Ok"?{TAG:"Ok",_0:[n._0,c,d._0,_._0,h._0,y._0]}:y}else i=h}else i=_}else i=d}else i=s}else i=l}else i=n;if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=i._0,a=o[1],f=await pi(o[0],a);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await yi(m,t,a,o[2],o[4],o[3],o[5]),u=await We(m);return u.TAG==="Ok"?p:p.TAG==="Ok"?{TAG:"Error",_0:{TAG:"CloudFailed",_0:u._0}}:{TAG:"Error",_0:{TAG:"Cleanup",primary:p._0,cleanup:u._0}}}var br="invalid hosted authorization code input";function Ai(e){return new Promise((t,r)=>{let n={contents:""},i=()=>{e.removeListener("data",a),e.removeListener("end",f),e.removeListener("error",m),e.destroy()},o=()=>{let p=n.contents.indexOf(`
8
+ `),l=(p!==-1?n.contents.slice(0,p):n.contents).trim();return i(),l===""||Buffer.byteLength(l,"utf8")>4096?t({TAG:"Error",_0:{TAG:"Failed",_0:br}}):t({TAG:"Ok",_0:l})},a=p=>(n.contents=n.contents+p.toString(),Buffer.byteLength(n.contents,"utf8")>4097?(i(),t({TAG:"Error",_0:{TAG:"Failed",_0:br}})):n.contents.includes(`
9
+ `)?o():void 0),f=()=>o(),m=()=>{i(),t({TAG:"Error",_0:{TAG:"Failed",_0:"hosted authorization code input failed"}})};e.on("data",a),e.once("end",f),e.once("error",m)})}async function Ei(e){let t=ie(e,"--attempt-id"),r;if(t.TAG==="Ok"){let p=ie(e,"--machine-id");if(p.TAG==="Ok"){let u=V(ze(process.env),{TAG:"Error",_0:Lr},l=>({TAG:"Ok",_0:l}));r=u.TAG==="Ok"?{TAG:"Ok",_0:[t._0,{conn:u._0,id:p._0}]}:u}else r=p}else r=t;if(r.TAG!=="Ok")return{TAG:"Error",_0:r._0};let n=r._0,i=n[1],o=await St(i);if(o.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:o._0}};let a=o._0;if(X(a.id,i.id)||X(a.name,"linzumi-auth-"+n[0])||X(a.role,ut))return{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization worker identity mismatch"}};let f=await Ai(process.stdin);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await z(i,["node",at,"--hosted-coding-account-auth-submit"],{env:[["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]],timeout:30,stdin:f._0+`
10
+ `});return m.TAG==="Ok"?B(m._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization code delivery failed"}}:{TAG:"Error",_0:{TAG:"CloudFailed",_0:m._0}}}function Rr(e){let t=e.slice(1),r=e[0];if(r===void 0)return Promise.reject(new Error("unsupported hosted account command: undefined"));switch(r){case"hosted-coding-account-auth":return Cr(t,"Authorization").then(ot);case"hosted-coding-account-auth-submit":return Ei(t).then(ot);case"hosted-coding-account-model-catalog":return Cr(t,"ModelCatalog").then(ot);default:return Promise.reject(new Error("unsupported hosted account command: "+r))}}var Yi=Rr;export{Yi as main};