@linzumi/cli 1.0.349 → 1.0.351

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 $r=Object.create;var mt=Object.defineProperty;var jr=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 L=(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&&mt(e,i,{get:()=>t[i],enumerable:!(n=jr(t,i))||n.enumerable});return e};var Hr=(e,t,r)=>(r=e!=null?$r(Vr(e)):{},zr(t||!e||!e.__esModule?mt(r,"default",{value:e,enumerable:!0}):r,e));var Zt=L((Fi,Kt)=>{var K=W("constants"),bn=process.cwd,ke=null,Nn=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ke||(ke=bn.call(process)),ke};try{process.cwd()}catch{}typeof process.chdir=="function"&&(Ke=process.chdir,process.chdir=function(e){ke=null,Ke.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,Ke));var Ke;Kt.exports=Pn;function Pn(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(){}),Nn==="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,dt,ft){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=L((Mi,Xt)=>{var Yt=W("stream").Stream;Xt.exports=Fn;function Fn(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=L((Ii,er)=>{"use strict";er.exports=In;var Mn=Object.getPrototypeOf||function(e){return e.__proto__};function In(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Mn(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Qe=L((Ri,Xe)=>{var S=W("fs"),Rn=Zt(),Ln=Qt(),Dn=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 $n(){}function ir(e,t){Object.defineProperty(e,M,{get:function(){return t}})}var ee=$n;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]);Xe.exports=Ze(Dn(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Xe.exports=Ze(S),S.__patched=!0);function Ze(e){Rn(e),e.gracefulify=Ze,e.createReadStream=dt,e.createWriteStream=ft;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,v,w){return t(P,C,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?de([N,[P,C,v],x,w||Date.now(),Date.now()]):typeof v=="function"&&v.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,v,w,x,F){return n(C,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,v,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,v,w,x,F){return o(C,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,v,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,v,w,x,F){return f(C,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,v,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(v,w,x,F){return p(v,P(v,w,x,F))}:function(v,w,x,F){return p(v,w,P(v,w,x,F))};return N(T,E,A);function P(C,v,w,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?de([N,[C,v,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=Ln(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;$e(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;$e(T.path,T.flags,T.mode,function(E,A){E?(T.destroy(),T.emit("error",E)):(T.fd=A,T.emit("open",A))})}function dt(T,E){return new e.ReadStream(T,E)}function ft(T,E){return new e.WriteStream(T,E)}var Dr=e.open;e.open=$e;function $e(T,E,A,N){return typeof A=="function"&&(N=A,A=null),P(T,E,A,N);function P(C,v,w,x,F){return Dr(C,v,w,function(O,vi){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[C,v,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),Ye()}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);Ye()}function Ye(){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(Ye,0))}}});var ur=L((Li,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=L(te=>{var jn=ur();te.operation=function(e){var t=te.timeouts(e);return new jn(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=L(($i,ar)=>{ar.exports=lr()});var sr=L((ji,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=L((Ui,_e)=>{var G=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(G)?(dr=W("assert"),fe=sr(),fr=/^win/i.test(G.platform),Ge=W("events"),typeof Ge!="function"&&(Ge=Ge.EventEmitter),G.__signal_exit_emitter__?b=G.__signal_exit_emitter__:(b=G.__signal_exit_emitter__=new Ge,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&&et();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{G.removeListener(t,Me[t])}catch{}}),G.emit=Ie,G.reallyExit=tt,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=G.listeners(e);r.length===b.count&&(Fe(),ne("exit",null,e),ne("afterexit",null,e),fr&&e==="SIGHUP"&&(e="SIGINT"),G.kill(G.pid,e))}}}),_e.exports.signals=function(){return fe},me=!1,et=function(){me||!re(global.process)||(me=!0,b.count+=1,fe=fe.filter(function(t){try{return G.on(t,Me[t]),!0}catch{return!1}}),G.emit=_r,G.reallyExit=mr)},_e.exports.load=et,tt=G.reallyExit,mr=function(t){re(global.process)&&(G.exitCode=t||0,ne("exit",G.exitCode,null),ne("afterexit",G.exitCode,null),tt.call(G,G.exitCode))},Ie=G.emit,_r=function(t,r){if(t==="exit"&&re(global.process)){r!==void 0&&(G.exitCode=r);var n=Ie.apply(this,arguments);return ne("exit",G.exitCode,null),ne("afterexit",G.exitCode,null),n}else return Ie.apply(this,arguments)}):_e.exports=function(){return function(){}};var dr,fe,fr,Ge,b,Fe,ne,Me,me,et,tt,mr,Ie,_r});var Er=L((Vi,ve)=>{"use strict";var Un=W("path"),it=Qe(),Vn=cr(),Bn=pr(),H={};function pe(e,t){return t.lockfilePath||`${e}.lock`}function ot(e,t,r){if(!t.realpath)return r(null,Un.resolve(e));t.fs.realpath(e,r)}function rt(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"?rt(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);rt(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 nt(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,nt(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,nt(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 zn(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:it,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),ot(e,t,(n,i)=>{if(n)return r(n);let o=Vn.operation(t.retries);o.attempt(()=>{rt(i,t,a=>{if(o.retry(a))return;if(a)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};nt(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:it,realpath:!0,...t},ot(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 Hn(e,t,r){t={stale:1e4,realpath:!0,fs:it,...t},t.stale=Math.max(t.stale||0,2e3),ot(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 Wn(){return H}Bn(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(pe(e,t))}catch{}}});ve.exports.lock=zn;ve.exports.unlock=Ar;ve.exports.check=Hn;ve.exports.getLocks=Wn});var Or=L((Bi,xr)=>{"use strict";var qn=Qe();function Jn(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 Kn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Zn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function Yn(e){if(e={...e},e.fs=Jn(e.fs||qn),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:Kn,toSync:Zn,toSyncOptions:Yn}});var vr=L((zi,Z)=>{"use strict";var he=Er(),{toPromise:Re,toSync:Le,toSyncOptions:ut}=Or();async function Gr(e,t){let r=await Re(he.lock)(e,t);return Re(r)}function Xn(e,t){let r=Le(he.lock)(e,ut(t));return Le(r)}function Qn(e,t){return Re(he.unlock)(e,t)}function ei(e,t){return Le(he.unlock)(e,ut(t))}function ti(e,t){return Re(he.check)(e,t)}function ri(e,t){return Le(he.check)(e,ut(t))}Z.exports=Gr;Z.exports.lock=Gr;Z.exports.unlock=Qn;Z.exports.lockSync=Xn;Z.exports.unlockSync=ei;Z.exports.check=ti;Z.exports.checkSync=ri});import*as ct 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 je(e){if(e!=null)return oe(e)}function R(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(R(e)))return e}function pt(e,t){if(e!==void 0)return t(R(e))}function V(e,t,r){return e!==void 0?r(R(e)):t}function j(e,t){if(e!==void 0)return oe(t(R(e)))}function le(e,t){if(e!==void 0)return t(R(e))}function $(e,t){return e!==void 0?R(e):t}function Ue(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.349",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,Be=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),bi=Se("stack"),we=Se("message"),At=Se("name"),Ni=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 He(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=R(t);return $(we(r),String(r))}function Ot(e){let t=xe(e);return t!==void 0?ae(At(R(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 We(e){let t=xt(e,"SMOLCLOUD_API_KEY");return j(t!==void 0?t:xt(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:$(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 Gt(e){try{return await e.text()}catch{return""}}function vt(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(!$(je(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 Gt(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 "+vt(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 qe="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,qe):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($(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:$(ce(t,"stdout"),""),stderr:$(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(`
3
+ var $r=Object.create;var mt=Object.defineProperty;var jr=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 D=(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&&mt(e,i,{get:()=>t[i],enumerable:!(n=jr(t,i))||n.enumerable});return e};var Hr=(e,t,r)=>(r=e!=null?$r(Vr(e)):{},zr(t||!e||!e.__esModule?mt(r,"default",{value:e,enumerable:!0}):r,e));var Zt=D((Fi,Kt)=>{var K=W("constants"),Cn=process.cwd,ke=null,Nn=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ke||(ke=Cn.call(process)),ke};try{process.cwd()}catch{}typeof process.chdir=="function"&&(Ke=process.chdir,process.chdir=function(e){ke=null,Ke.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,Ke));var Ke;Kt.exports=Pn;function Pn(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(){}),Nn==="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,dt,ft){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=D((Mi,Xt)=>{var Yt=W("stream").Stream;Xt.exports=Fn;function Fn(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=D((Ii,er)=>{"use strict";er.exports=In;var Mn=Object.getPrototypeOf||function(e){return e.__proto__};function In(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Mn(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Qe=D((Li,Xe)=>{var S=W("fs"),Ln=Zt(),Dn=Qt(),Rn=tr(),be=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 $n(){}function ir(e,t){Object.defineProperty(e,M,{get:function(){return t}})}var ee=$n;be.debuglog?ee=be.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(ee=function(){var e=be.format.apply(be,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]);Xe.exports=Ze(Rn(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Xe.exports=Ze(S),S.__patched=!0);function Ze(e){Ln(e),e.gracefulify=Ze,e.createReadStream=dt,e.createWriteStream=ft;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,b,v,w){return t(P,b,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?de([N,[P,b,v],x,w||Date.now(),Date.now()]):typeof v=="function"&&v.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(b,v,w,x,F){return n(b,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[b,v,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(b,v,w,x,F){return o(b,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[b,v,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(b,v,w,x,F){return f(b,v,w,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[b,v,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(v,w,x,F){return p(v,P(v,w,x,F))}:function(v,w,x,F){return p(v,w,P(v,w,x,F))};return N(T,E,A);function P(b,v,w,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?de([N,[b,v,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=Dn(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;$e(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;$e(T.path,T.flags,T.mode,function(E,A){E?(T.destroy(),T.emit("error",E)):(T.fd=A,T.emit("open",A))})}function dt(T,E){return new e.ReadStream(T,E)}function ft(T,E){return new e.WriteStream(T,E)}var Rr=e.open;e.open=$e;function $e(T,E,A,N){return typeof A=="function"&&(N=A,A=null),P(T,E,A,N);function P(b,v,w,x,F){return Rr(b,v,w,function(O,vi){O&&(O.code==="EMFILE"||O.code==="ENFILE")?de([P,[b,v,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),Ye()}var Ce;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);Ye()}function Ye(){if(clearTimeout(Ce),Ce=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)}Ce===void 0&&(Ce=setTimeout(Ye,0))}}});var ur=D((Di,or)=>{function R(e,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}or.exports=R;R.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};R.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};R.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var r=this._timeouts.shift();if(r===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift();else return!1;var n=this,i=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},r);return this._options.unref&&i.unref(),!0};R.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){r._operationTimeoutCb()},r._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};R.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};R.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};R.prototype.start=R.prototype.try;R.prototype.errors=function(){return this._errors};R.prototype.attempts=function(){return this._attempts};R.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,r=0,n=0;n<this._errors.length;n++){var i=this._errors[n],o=i.message,a=(e[o]||0)+1;e[o]=a,a>=r&&(t=i,r=a)}return t}});var lr=D(te=>{var jn=ur();te.operation=function(e){var t=te.timeouts(e);return new jn(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=D(($i,ar)=>{ar.exports=lr()});var sr=D((ji,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=D((Ui,_e)=>{var G=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(G)?(dr=W("assert"),fe=sr(),fr=/^win/i.test(G.platform),Ge=W("events"),typeof Ge!="function"&&(Ge=Ge.EventEmitter),G.__signal_exit_emitter__?C=G.__signal_exit_emitter__:(C=G.__signal_exit_emitter__=new Ge,C.count=0,C.emitted={}),C.infinite||(C.setMaxListeners(1/0),C.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&&et();var r="exit";t&&t.alwaysLast&&(r="afterexit");var n=function(){C.removeListener(r,e),C.listeners("exit").length===0&&C.listeners("afterexit").length===0&&Fe()};return C.on(r,e),n},Fe=function(){!me||!re(global.process)||(me=!1,fe.forEach(function(t){try{G.removeListener(t,Me[t])}catch{}}),G.emit=Ie,G.reallyExit=tt,C.count-=1)},_e.exports.unload=Fe,ne=function(t,r,n){C.emitted[t]||(C.emitted[t]=!0,C.emit(t,r,n))},Me={},fe.forEach(function(e){Me[e]=function(){if(re(global.process)){var r=G.listeners(e);r.length===C.count&&(Fe(),ne("exit",null,e),ne("afterexit",null,e),fr&&e==="SIGHUP"&&(e="SIGINT"),G.kill(G.pid,e))}}}),_e.exports.signals=function(){return fe},me=!1,et=function(){me||!re(global.process)||(me=!0,C.count+=1,fe=fe.filter(function(t){try{return G.on(t,Me[t]),!0}catch{return!1}}),G.emit=_r,G.reallyExit=mr)},_e.exports.load=et,tt=G.reallyExit,mr=function(t){re(global.process)&&(G.exitCode=t||0,ne("exit",G.exitCode,null),ne("afterexit",G.exitCode,null),tt.call(G,G.exitCode))},Ie=G.emit,_r=function(t,r){if(t==="exit"&&re(global.process)){r!==void 0&&(G.exitCode=r);var n=Ie.apply(this,arguments);return ne("exit",G.exitCode,null),ne("afterexit",G.exitCode,null),n}else return Ie.apply(this,arguments)}):_e.exports=function(){return function(){}};var dr,fe,fr,Ge,C,Fe,ne,Me,me,et,tt,mr,Ie,_r});var Er=D((Vi,ve)=>{"use strict";var Un=W("path"),it=Qe(),Vn=cr(),Bn=pr(),H={};function pe(e,t){return t.lockfilePath||`${e}.lock`}function ot(e,t,r){if(!t.realpath)return r(null,Un.resolve(e));t.fs.realpath(e,r)}function rt(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"?rt(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);rt(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 nt(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,nt(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,nt(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 zn(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:it,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),ot(e,t,(n,i)=>{if(n)return r(n);let o=Vn.operation(t.retries);o.attempt(()=>{rt(i,t,a=>{if(o.retry(a))return;if(a)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};nt(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:it,realpath:!0,...t},ot(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 Hn(e,t,r){t={stale:1e4,realpath:!0,fs:it,...t},t.stale=Math.max(t.stale||0,2e3),ot(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 Wn(){return H}Bn(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(pe(e,t))}catch{}}});ve.exports.lock=zn;ve.exports.unlock=Ar;ve.exports.check=Hn;ve.exports.getLocks=Wn});var Or=D((Bi,xr)=>{"use strict";var qn=Qe();function Jn(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 Kn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Zn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function Yn(e){if(e={...e},e.fs=Jn(e.fs||qn),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:Kn,toSync:Zn,toSyncOptions:Yn}});var vr=D((zi,Z)=>{"use strict";var he=Er(),{toPromise:Le,toSync:De,toSyncOptions:ut}=Or();async function Gr(e,t){let r=await Le(he.lock)(e,t);return Le(r)}function Xn(e,t){let r=De(he.lock)(e,ut(t));return De(r)}function Qn(e,t){return Le(he.unlock)(e,t)}function ei(e,t){return De(he.unlock)(e,ut(t))}function ti(e,t){return Le(he.check)(e,t)}function ri(e,t){return De(he.check)(e,ut(t))}Z.exports=Gr;Z.exports.lock=Gr;Z.exports.unlock=Qn;Z.exports.lockSync=Xn;Z.exports.unlockSync=ei;Z.exports.check=ti;Z.exports.checkSync=ri});import*as ct 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 je(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 pt(e,t){if(e!==void 0)return t(L(e))}function V(e,t,r){return e!==void 0?r(L(e)):t}function j(e,t){if(e!==void 0)return oe(t(L(e)))}function le(e,t){if(e!==void 0)return t(L(e))}function $(e,t){return e!==void 0?L(e):t}function Ue(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.351",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,Be=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),Ci=Se("stack"),we=Se("message"),At=Se("name"),Ni=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 He(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 $(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 We(e){let t=xt(e,"SMOLCLOUD_API_KEY");return j(t!==void 0?t:xt(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:$(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 Gt(e){try{return await e.text()}catch{return""}}function vt(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(!$(je(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 Gt(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 "+vt(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 qe="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,qe):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($(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:$(ce(t,"stdout"),""),stderr:$(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
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=j(r.timeout,l=>setTimeout(()=>{i.abort()},(l*1e3|0)+3e4|0)),a=()=>pt(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 Gt(l),_="smolcloud POST "+f+" \u2192 "+vt(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 "+(($(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 Je(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="+$(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 Je(f),{TAG:"Error",_0:m._0})}import*as $t from"node:fs";import*as jt 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",An=J+"/.linzumi-provisioned",Vt="v1",Bt=J+"/cloud-supervisor.mjs",zt=J+"/mcp-server.mjs",It=J+"/.secrets",Rt=J+"/.codex",Ht="/etc/ssl/certs/ca-certificates.crt",En=new RegExp("[^A-Za-z0-9._-]","g");function Wt(e){return J+"/.linzumi-provisioned-"+Vt+"-"+e.replace(En,"_")}function xn(e){return["/bin/sh","-c",["set -e","mkdir -p "+J+" "+It+" "+Rt,"chmod 700 "+It+" "+Rt,"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 "+An].join(" && ")]}function qt(e){return"test -f "+Wt(e)+" && command -v codex >/dev/null && command -v node >/dev/null && "}function On(e){return["/bin/sh","-c",qt(e)+"command -v bwrap >/dev/null && test -s "+Ht]}function Gn(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 vn=new RegExp("^[0-9a-f]{64}$");function Sn(e){let t=e.split(`
7
- `).map(n=>n.trim()),r=n=>ye(j(t.find(i=>i.startsWith(n+" ")),i=>i.slice(n.length+1|0).trim()),i=>vn.test(i));return j(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 Lt(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=jt.join(e,t);if($t.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 Lt(n,"cloud-supervisor.mjs");if(o.TAG!=="Ok")return{TAG:"Error",_0:o._0};let a=o._0,f=await Lt(i,"mcp-server.mjs");if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await z(e,Gn(t),{timeout:30}),u;if(p.TAG==="Ok"){let _=p._0;u=B(_.exitCode)?Sn(_.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,xn(t),{timeout:600});if(_.TAG==="Ok"){let h=_._0,y=h.exitCode;if(B(y)){let k=await z(e,On(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 ni=Hr(vr(),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 ui(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 ui(n,r)}var st="/opt/linzumi/hosted-coding-account-auth.mjs",De="/home/agent/.linzumi-hosted-auth",Fr=De+"/authorization-code.sock",ai="smolmachine:linzumi-agent-vm:codex-0.139.0-claude-2.1.260-v8",at="coding-account-authorization";function ci(e){return e==="Codex"?"codex":"claude_code"}function si(e){switch(e){case"claude_code":return"ClaudeCode";case"codex":return"Codex";default:return}}function di(e){return e==="Codex"?2048:4096}var Mr="hosted coding-account authorization and machine cleanup both failed";function fi(e){switch(e.TAG){case"Failed":return e._0;case"CloudFailed":return He(e._0);case"Cleanup":return Mr}}function Ir(e){switch(e.TAG){case"Failed":case"CloudFailed":return new Error(fi(e));case"Cleanup":return new AggregateError([Ir(e.primary),new Error(He(e.cleanup))],Mr)}}function lt(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 Rr={TAG:"Failed",_0:"hosted coding-account authorization compute is unavailable"};function mi(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 _i(e){return e==="ProviderLogin"?[]:[["LINZUMI_HOSTED_AUTH_CLAUDE_CEREMONY","setup_token"]]}function pi(){return ct.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 hi(){try{return{TAG:"Ok",_0:await Pr.readFile(pi(),"utf8")}}catch(e){let t=U(e);return{TAG:"Error",_0:{TAG:"Failed",_0:q(t)}}}}async function Ti(e,t){let r=We(process.env);if(r===void 0)return{TAG:"Error",_0:Rr};let n=await bt(r,{image:ai,name:"linzumi-auth-"+e,cpus:2,memoryMb:di(t),diskGb:20,env:[["LINZUMI_ROLE",at]],labels:[[qe,at]],autoStopSeconds:900,ttlSeconds:900});return Ue(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 yi(e){let t=await Jt(e,Be,Nr.dirname(ct.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,Be);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 Ai(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",st,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",ci(r)],["LINZUMI_HOSTED_AUTH_WORKER_ID",e.id],["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]].concat(_i(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 Ei(e,t,r,n,i,o,a){let f;if(f=r==="Codex"?await yi(e):{TAG:"Ok",_0:void 0},f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await hi();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,st,m._0,448);return l.TAG==="Ok"?await Ai(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(si(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(j(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=mi(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 Ti(o[0],a);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await Ei(m,t,a,o[2],o[4],o[3],o[5]),u=await Je(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 xi(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 Oi(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(We(process.env),{TAG:"Error",_0:Rr},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,at))return{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization worker identity mismatch"}};let f=await xi(process.stdin);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await z(i,["node",st,"--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 Lr(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(lt);case"hosted-coding-account-auth-submit":return Oi(t).then(lt);case"hosted-coding-account-model-catalog":return Cr(t,"ModelCatalog").then(lt);default:return Promise.reject(new Error("unsupported hosted account command: "+r))}}var Yi=Lr;export{Yi as main};
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 bt(e,t,r,n){let i=new AbortController,o=j(r.timeout,l=>setTimeout(()=>{i.abort()},(l*1e3|0)+3e4|0)),a=()=>pt(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 Gt(l),_="smolcloud POST "+f+" \u2192 "+vt(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 "+(($(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 Je(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="+$(o,"unknown")+")";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:g(a)}}}return await mn(1e3),await r()};return await r()}async function Ct(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 Je(f),{TAG:"Error",_0:m._0})}import*as $t from"node:fs";import*as jt 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",An=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",En=new RegExp("[^A-Za-z0-9._-]","g");function Wt(e){return J+"/.linzumi-provisioned-"+Vt+"-"+e.replace(En,"_")}function xn(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 "+An].join(" && ")]}function qt(e){return"test -f "+Wt(e)+" && command -v codex >/dev/null && command -v node >/dev/null && "}function On(e){return["/bin/sh","-c",qt(e)+"command -v bwrap >/dev/null && test -s "+Ht]}function Gn(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 vn=new RegExp("^[0-9a-f]{64}$");function Sn(e){let t=e.split(`
7
+ `).map(n=>n.trim()),r=n=>ye(j(t.find(i=>i.startsWith(n+" ")),i=>i.slice(n.length+1|0).trim()),i=>vn.test(i));return j(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 Dt(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 Rt(e,t){let r=jt.join(e,t);if($t.existsSync(r))return r}async function Jt(e,t,r){let n=Rt(r,"cloud-supervisor.mjs"),i=Rt(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 Dt(n,"cloud-supervisor.mjs");if(o.TAG!=="Ok")return{TAG:"Error",_0:o._0};let a=o._0,f=await Dt(i,"mcp-server.mjs");if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await z(e,Gn(t),{timeout:30}),u;if(p.TAG==="Ok"){let _=p._0;u=B(_.exitCode)?Sn(_.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,xn(t),{timeout:600});if(_.TAG==="Ok"){let h=_._0,y=h.exitCode;if(B(y)){let k=await z(e,On(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 ni=Hr(vr(),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 ui(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 ui(n,r)}var st="/opt/linzumi/hosted-coding-account-auth.mjs",Re="/home/agent/.linzumi-hosted-auth",Fr=Re+"/authorization-code.sock",ai="smolmachine:linzumi-agent-vm:codex-0.139.0-claude-2.1.260-v8",at="coding-account-authorization";function ci(e){return e==="Codex"?"codex":"claude_code"}function si(e){switch(e){case"claude_code":return"ClaudeCode";case"codex":return"Codex";default:return}}function di(e){return e==="Codex"?2048:4096}var Mr="hosted coding-account authorization and machine cleanup both failed";function fi(e){switch(e.TAG){case"Failed":return e._0;case"CloudFailed":return He(e._0);case"Cleanup":return Mr}}function Ir(e){switch(e.TAG){case"Failed":case"CloudFailed":return new Error(fi(e));case"Cleanup":return new AggregateError([Ir(e.primary),new Error(He(e.cleanup))],Mr)}}function lt(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 mi(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 _i(e){return e==="ProviderLogin"?[]:[["LINZUMI_HOSTED_AUTH_CLAUDE_CEREMONY","setup_token"]]}function pi(){return ct.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 hi(){try{return{TAG:"Ok",_0:await Pr.readFile(pi(),"utf8")}}catch(e){let t=U(e);return{TAG:"Error",_0:{TAG:"Failed",_0:q(t)}}}}async function Ti(e,t){let r=We(process.env);if(r===void 0)return{TAG:"Error",_0:Lr};let n=await Ct(r,{image:ai,name:"linzumi-auth-"+e,cpus:2,memoryMb:di(t),diskGb:20,env:[["LINZUMI_ROLE",at]],labels:[[qe,at]],autoStopSeconds:900,ttlSeconds:900});return Ue(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 yi(e){let t=await Jt(e,Be,Nr.dirname(ct.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,Be);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 Ai(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 bt(e,["node",st,m],{env:[["LINZUMI_HOSTED_AUTH_CALLBACK_URL",n],["LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN",i],["LINZUMI_HOSTED_AUTH_ROOT",Re],["LINZUMI_HOSTED_AUTH_EXPIRES_AT",o],["LINZUMI_HOSTED_AUTH_HARNESS",ci(r)],["LINZUMI_HOSTED_AUTH_WORKER_ID",e.id],["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Fr]].concat(_i(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 Ei(e,t,r,n,i,o,a){let f;if(f=r==="Codex"?await yi(e):{TAG:"Ok",_0:void 0},f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await hi();if(m.TAG!=="Ok")return{TAG:"Error",_0:m._0};let p=await kr(e,["mkdir","-p",Re],"auth-root creation");if(p.TAG!=="Ok")return{TAG:"Error",_0:p._0};let u=await kr(e,["chmod","700",Re],"auth-root permission");if(u.TAG!=="Ok")return{TAG:"Error",_0:u._0};let l=await Oe(e,st,m._0,448);return l.TAG==="Ok"?await Ai(e,t,r,n,i,o,a):{TAG:"Error",_0:{TAG:"CloudFailed",_0:l._0}}}async function br(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(si(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(j(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=mi(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 Ti(o[0],a);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,p=await Ei(m,t,a,o[2],o[4],o[3],o[5]),u=await Je(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 Cr="invalid hosted authorization code input";function xi(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:Cr}}):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:Cr}})):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 Oi(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(We(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,at))return{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization worker identity mismatch"}};let f=await xi(process.stdin);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await z(i,["node",st,"--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 Dr(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 br(t,"Authorization").then(lt);case"hosted-coding-account-auth-submit":return Oi(t).then(lt);case"hosted-coding-account-model-catalog":return br(t,"ModelCatalog").then(lt);default:return Promise.reject(new Error("unsupported hosted account command: "+r))}}var Yi=Dr;export{Yi as main};