@linzumi/cli 1.0.54 → 1.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,7 +58,7 @@ Install the CLI or run it with `npx`:
58
58
  ```bash
59
59
  npm install -g @linzumi/cli@latest
60
60
  npx -y @linzumi/cli@latest signup
61
- npx -y @linzumi/cli@1.0.54 --version
61
+ npx -y @linzumi/cli@1.0.56 --version
62
62
  linzumi --version
63
63
  ```
64
64
 
package/dist/index.js CHANGED
@@ -1312,7 +1312,7 @@ To kick the agent off:
1312
1312
  3. Paste into the thread. Codex will pick it up and start editing this folder.
1313
1313
  `});import{connect as Yfe}from"node:net";import{gzipSync as eme}from"node:zlib";async function Zq(e,n){if(!n.includes(e.port))return dy(e.requestId,"forward_port_not_allowed");let t=ome(e);if(!t.ok)return dy(e.requestId,t.error);try{let r={method:e.method,headers:ime(e.headers),redirect:"manual",...t.body===void 0?{}:{body:t.body.buffer.slice(t.body.byteOffset,t.body.byteOffset+t.body.byteLength)}},o=await rme(e.port,e.path,e.queryString,r),i=Buffer.from(await o.arrayBuffer()),s=ame(e.path,o.headers,i),a=dme(e,o.headers,s);return a.body.byteLength>Hq?dy(e.requestId,"forward_response_too_large"):{requestId:e.requestId,ok:!0,status:o.status,headers:a.headers,bodyBase64:a.body.toString("base64")}}catch{return dy(e.requestId,"forward_target_unavailable")}}function Gq(e){return e.type==="forward_http_request"}function Qq(e){return e.type==="forward_tcp_open"||e.type==="forward_tcp_send"||e.type==="forward_tcp_close"}function Xq(e,n,t,r=tme){let o=new Map,i=a=>e.push(n,"forward:tcp_event",a).catch(()=>{}),s=a=>{let d=o.get(a);o.delete(a),d?.socket.end()};return{handle:a=>{switch(a.type){case"forward_tcp_open":{if(!t().includes(a.port)){i({socketId:a.socketId,type:"error",error:"forward_port_not_allowed"});return}o.get(a.socketId)?.socket.destroy();let u=r(a.port);o.set(a.socketId,{socket:u}),u.on("connect",()=>{ay(o,a.socketId,u)&&i({socketId:a.socketId,type:"open"})}),u.on("data",c=>{!ay(o,a.socketId,u)||!(c instanceof Uint8Array)||i({socketId:a.socketId,type:"data",bodyBase64:Buffer.from(c).toString("base64")})}),u.on("close",()=>{ay(o,a.socketId,u)&&(o.delete(a.socketId),i({socketId:a.socketId,type:"close"}))}),u.on("error",()=>{ay(o,a.socketId,u)&&(o.delete(a.socketId),i({socketId:a.socketId,type:"error",error:"forward_target_unavailable"}),u.destroy())});return}case"forward_tcp_send":{let d=o.get(a.socketId),u=Yq(a.bodyBase64);if(u===void 0){i({socketId:a.socketId,type:"error",error:"invalid_forward_request"});return}if(d===void 0||d.socket.destroyed===!0||d.socket.writable===!1){i({socketId:a.socketId,type:"error",error:"tcp_socket_not_open"});return}d.socket.write(u);return}case"forward_tcp_close":s(a.socketId);return}},close:()=>{for(let a of o.keys())s(a)}}}function ay(e,n,t){return e.get(n)?.socket===t}function tme(e){return Yfe({host:"127.0.0.1",port:e})}function Wq(e,n,t,r){let o=t.startsWith("/")?t:`/${t}`,i=new URL(`${e}://127.0.0.1:${n}${o}`);return r!==void 0&&r.trim()!==""&&(i.search=r),i.toString()}async function rme(e,n,t,r){try{return await fetch(Wq("http",e,n,t),r)}catch(o){try{return await fetch(Wq("https",e,n,t),r)}catch{throw o}}}function ome(e){if(e.method==="GET"||e.method==="HEAD")return{ok:!0,body:void 0};if(e.bodyBase64===void 0||e.bodyBase64==="")return{ok:!0,body:void 0};let n=Yq(e.bodyBase64);return n===void 0?{ok:!1,error:"invalid_forward_request"}:n.byteLength>Hq?{ok:!1,error:"forward_body_too_large"}:{ok:!0,body:n}}function Yq(e){let n=e.trim();if(n.length%4===1||!/^[A-Za-z0-9+/]*={0,2}$/.test(n))return;let t=Buffer.from(n,"base64"),r=t.toString("base64").replace(/=+$/,""),o=n.replace(/=+$/,"");return r===o?t:void 0}function ime(e){let n=new Headers;if(!Array.isArray(e))return n;for(let t of e)fme(t)&&n.set(t.name,t.value);return n}function sme(e){return Array.from(e.entries()).filter(([n])=>!nF.has(n.toLowerCase())).slice(0,40).map(([n,t])=>({name:n,value:t}))}function ame(e,n,t){return pme(e,n)?Buffer.from(t.toString("utf8").replace('message:h(3783,null,"code-server")','message:h(3783,null,"Kandan")')):t}function dme(e,n,t){let r=sme(n);return ume(e,n,t)?{body:eme(t),headers:[...r,{name:"content-encoding",value:"gzip"},{name:"vary",value:"accept-encoding"}]}:{body:t,headers:r}}function ume(e,n,t){return e.method==="HEAD"||t.byteLength<nme||!cme(e.headers)?!1:lme(e.path,n)}function cme(e){return Array.isArray(e)?e.some(n=>eF(n)&&n.name.toLowerCase()==="accept-encoding"&&n.value.toLowerCase().split(",").map(t=>t.trim()).some(t=>t==="gzip"||t.startsWith("gzip;"))):!1}function lme(e,n){let t=n.get("content-type")?.toLowerCase()??"";return t.startsWith("text/")||t.includes("javascript")||t.includes("json")||t.includes("xml")?!0:/\.(?:css|html|js|json|map|mjs|svg|txt)$/i.test(e)}function pme(e,n){return e.endsWith("/out/vs/code/browser/workbench/workbench.js")&&(n.get("content-type")??"").toLowerCase().includes("javascript")}function fme(e){return eF(e)&&!nF.has(e.name.toLowerCase())}function eF(e){return Z(e)&&typeof e.name=="string"&&typeof e.value=="string"}function dy(e,n){return{requestId:e,ok:!1,error:n}}var Hq,nme,nF,tF=j(()=>{"use strict";Rn();Hq=64*1024*1024,nme=32*1024;nF=new Set(["accept-encoding","connection","content-encoding","content-length","cookie","host","keep-alive","authorization","proxy-authenticate","proxy-authorization","te","trailer","transfer-encoding","upgrade"])});import{spawn as ak}from"node:child_process";import{copyFileSync as mme,cpSync as hme,existsSync as uy,mkdirSync as qa,mkdtempSync as gme,readFileSync as yme,realpathSync as dk,writeFileSync as xme}from"node:fs";import{tmpdir as _me}from"node:os";import{basename as bme,delimiter as wme,dirname as Zi,join as Xn}from"node:path";function oF(e){return e.type==="start_local_editor"}function iF(e,n,t){let r={localEditor:e!==void 0&&n.length>0,localEditorStatus:t.status};return t.status==="running"?{...r,localEditorPort:t.port,localEditorCwd:t.cwd,...t.collaboration===void 0?{}:{localEditorCollaboration:sk(t.collaboration)}}:r}async function sF(e,n){if(n.editorRuntime===void 0)return{ok:!1,state:n.currentState,reason:"local_editor_disabled"};let t=Vr(e.cwd,n.allowedCwds);if(!t.ok)return{ok:!1,state:n.currentState,reason:t.reason};if(n.currentState.status==="running"&&n.currentState.cwd===t.cwd&&qme(n.currentState.collaboration,e.collaboration))return{ok:!0,state:n.currentState,event:{cwd:n.currentState.cwd,port:n.currentState.port,startedAt:new Date().toISOString(),collaboration:sk(n.currentState.collaboration)}};let r=vme(e,n);if(e.collaboration!==void 0&&r===void 0)return{ok:!1,state:n.currentState,reason:"missing_browser_base_url"};let o=await gg(),i=e.collaboration===void 0?void 0:await gg(),s=e.collaboration===void 0||r===void 0?void 0:Ame(e.collaboration,n.runnerId??"local-runner",i,r),a=Sme(s,n.editorRuntime);if(!a.ok)return{ok:!1,state:n.currentState,reason:a.reason};let d=Ime({codeServerBin:n.editorRuntime.codeServerBin,codeServerRuntimeRoot:n.editorRuntime.root,port:o,cwd:t.cwd,userDataDir:a.userDataDir,extensionsDir:a.extensionsDir,platform:n.platform});if(!d.ok)return{ok:!1,state:n.currentState,reason:d.reason};let u=await Ome(s,a,n.editorRuntime,n.runnerId);if(!u.ok)return{ok:!1,state:n.currentState,reason:"code_server_spawn_failed"};ye("process.spawn",{command:d.command,args:d.args,cwd:t.cwd,purpose:"local_editor.code_server"},{sessionId:n.runnerId});let c=ak(d.command,[...d.args],{cwd:t.cwd,env:zme(process.env,t.cwd,a.userDataDir,u.collaboration),stdio:["ignore","inherit","inherit"]});ye("process.spawned",{command:d.command,args:d.args,cwd:t.cwd,pid:c.pid,purpose:"local_editor.code_server"},{sessionId:n.runnerId}),c.once("exit",(x,v)=>{ye("process.exit",{command:d.command,args:d.args,cwd:t.cwd,pid:c.pid,code:x,signal:v,purpose:"local_editor.code_server"},{sessionId:n.runnerId})});let l=uF(c);if(await cF(c)==="failed")return u.collaboration?.process.kill("SIGINT"),{ok:!1,state:n.currentState,reason:"code_server_spawn_failed"};let[m,p]=await Promise.all([Nme(o,l),u.ready]);return m==="failed"||p==="failed"?(c.kill("SIGINT"),u.collaboration?.process.kill("SIGINT"),{ok:!1,state:n.currentState,reason:"code_server_spawn_failed"}):(n.currentState.status==="running"&&(n.currentState.process.kill("SIGINT"),n.currentState.collaboration?.process.kill("SIGINT")),{ok:!0,state:{status:"running",cwd:t.cwd,port:o,process:c,collaboration:u.collaboration,exited:l},event:{cwd:t.cwd,port:o,startedAt:new Date().toISOString(),collaboration:sk(u.collaboration)}})}function vme(e,n){let t=e.browserBaseUrl??n.browserBaseUrl;return t===void 0||t.trim()===""?void 0:t.trim().replace(/\/+$/,"")}function aF(e,n,t,r){return["--bind-addr",`127.0.0.1:${e}`,"--auth","none","--disable-telemetry","--disable-update-check","--disable-workspace-trust","--disable-getting-started-override","--app-name","Kandan","--user-data-dir",t,...r===void 0?[]:["--extensions-dir",r],n]}function Sme(e,n){try{let t=gme(Xn(_me(),"kandan-local-editor-")),r=Xn(t,"extensions"),o=Xn(t,"collaboration-server"),i=Xn(t,"tmp"),s=Xn(t,"User");return qa(s,{recursive:!0}),qa(r,{recursive:!0}),qa(o,{recursive:!0}),qa(i,{recursive:!0}),n!==void 0&&(kme(n),Lme(n.assets.documentStateExtensionDir,Xn(r,"kandan.document-state-telemetry"))),xme(Xn(s,"settings.json"),JSON.stringify($me(e),null,2)),{ok:!0,userDataDir:t,extensionsDir:r,collaborationServerDir:o}}catch{return{ok:!1,reason:"code_server_spawn_failed"}}}function kme(e){let n=Cme(e);[{source:Xn(n,"extensions","git-base","dist","extension.js"),target:Xn(n,"extensions","git-base","dist","browser","extension.js"),required:!0},{source:Xn(n,"extensions","git-base","dist","extension.js.map"),target:Xn(n,"extensions","git-base","dist","browser","extension.js.map"),required:!1},{source:Xn(n,"extensions","merge-conflict","dist","mergeConflictMain.js"),target:Xn(n,"extensions","merge-conflict","dist","browser","mergeConflictMain.js"),required:!0},{source:Xn(n,"extensions","merge-conflict","dist","mergeConflictMain.js.map"),target:Xn(n,"extensions","merge-conflict","dist","browser","mergeConflictMain.js.map"),required:!1}].forEach(({source:r,target:o,required:i})=>{switch(!0){case uy(o):return;case(!i&&!uy(r)):return;default:qa(Zi(o),{recursive:!0}),mme(r,o);return}})}function Cme(e){let n=dF([Xn(e.root,"lib","vscode"),Xn(Zi(Zi(e.codeServerBin)),"lib","vscode"),...Tme(e.codeServerBin).map(o=>Xn(Zi(Zi(o)),"lib","vscode"))]),t=n.find(o=>Pme(o).every(i=>uy(i))),r=n[0];if(r===void 0)throw new Error("code-server runtime did not include a VS Code root candidate");return t??r}function Tme(e){try{let t=yme(e,"utf8").match(/exec\s+(?:"([^"]+)"|'([^']+)'|([^\s]+))\s+"\$@"/u),r=t?.[1]??t?.[2]??t?.[3];return r===void 0||r.trim()===""?[]:[r]}catch{return[]}}function Pme(e){return[Xn(e,"extensions","git-base","dist","extension.js"),Xn(e,"extensions","merge-conflict","dist","mergeConflictMain.js")]}function Ime(e){let n=e.platform??process.platform;if(n==="linux")return Rme(e);if(n!=="darwin")return cy();let t=ik(e.codeServerBin,e.envPath??process.env.PATH??"");return t.ok?{ok:!0,command:t.command,args:aF(e.port,e.cwd,e.userDataDir,e.extensionsDir)}:cy()}function Rme(e){let n=ik(e.bubblewrapBin??"bwrap",e.envPath??process.env.PATH??"");if(!n.ok)return cy();let t=ik(e.codeServerBin,e.envPath??process.env.PATH??"");if(!t.ok)return cy();let r=dF(["/usr","/bin","/sbin","/lib","/lib64","/etc","/nix","/opt",...e.codeServerRuntimeRoot===void 0?[]:Mme(e.codeServerRuntimeRoot),t.directory]),o=["--die-with-parent","--proc","/proc","--dev-bind","/dev","/dev","--tmpfs","/tmp","--setenv","HOME",e.cwd,"--setenv","PWD",e.cwd,"--setenv","XDG_DATA_HOME",Xn(e.userDataDir,"data"),"--setenv","XDG_CONFIG_HOME",Xn(e.userDataDir,"config"),...r.flatMap(i=>["--ro-bind-try",i,i]),"--bind",e.cwd,e.cwd,"--bind",e.userDataDir,e.userDataDir,...e.extensionsDir===void 0?[]:["--bind",e.extensionsDir,e.extensionsDir],"--chdir",e.cwd,"--",t.command,...aF(e.port,e.cwd,e.userDataDir,e.extensionsDir)];return{ok:!0,command:n.command,args:o}}function cy(){return{ok:!1,reason:"local_editor_filesystem_sandbox_unavailable"}}function ik(e,n){if(Eme(e)){let t=Dme(e);return t===void 0?{ok:!1}:{ok:!0,command:e,directory:t}}for(let t of n.split(wme)){if(t.trim()==="")continue;let r=Xn(t,e);if(!uy(r))continue;let o=dk(r);return{ok:!0,command:o,directory:Zi(o)}}return{ok:!1}}function Eme(e){return e.includes("/")||e.includes("\\")}function Dme(e){try{let n=Zi(dk(e));return n==="/"?void 0:n}catch{let t=Zi(e);return t==="."||t==="/"?void 0:t}}function Mme(e){try{return[e,dk(e)]}catch{return[e]}}function dF(e){return Array.from(new Set(e.filter(n=>n.length>0)))}function Ame(e,n,t,r){if(e===void 0||t===void 0)return;let o=`/local-codex-runners/${encodeURIComponent(n)}/forwards/${t}/preview-target`,i=new URL(o,`${r}/`).toString(),s=`/api/v2/editor/sessions/${e.editorSessionId}/collaboration-state`,a=e.bootstrapToken===void 0||e.bootstrapToken===""?void 0:`${o}/_kandan-collaboration/${encodeURIComponent(e.bootstrapToken)}`,d=a===void 0?s:`${a}${s}`,u=a===void 0?i:new URL(a,`${r}/`).toString();return{...e,serverPort:t,serverUrl:i,bootstrapServerUrl:u,collaborationStateUrl:d}}function $me(e){return{"extensions.autoCheckUpdates":!1,"extensions.autoUpdate":!1,"extensions.ignoreRecommendations":!0,"extensions.showRecommendationsOnlyOnDemand":!0,"oct.alwaysAskToOverrideServerUrl":!1,"oct.joinAcceptMode":"auto",...e===void 0?{}:{"oct.kandanEditorSessionId":e.editorSessionId,"oct.kandanCollaborationStateUrl":e.collaborationStateUrl,"oct.serverUrl":e.bootstrapServerUrl},"security.workspace.trust.enabled":!1,"telemetry.telemetryLevel":"off","workbench.secondarySideBar.defaultVisibility":"hidden","workbench.startupEditor":"none","workbench.welcomePage.walkthroughs.openOnInstall":!1}}async function Ome(e,n,t,r){if(e===void 0)return{ok:!0,ready:Promise.resolve("ready")};try{await Promise.all([rF(t.assets.collaborationExtensionTarball,n.extensionsDir),rF(t.assets.collaborationServerTarball,n.collaborationServerDir)]);let o=jme(),i=[Xn(n.collaborationServerDir,"open-collaboration-server","bundle","app.js"),"--hostname","127.0.0.1","--port",String(e.serverPort)];ye("process.spawn",{command:o,args:i,purpose:"local_editor.collaboration_sidecar",editorSessionId:e.editorSessionId,runtimeSessionId:e.runtimeSessionId},{sessionId:r});let s=ak(o,i,{env:{...process.env,OCT_ACTIVATE_SIMPLE_LOGIN:"true",OCT_SERVER_OWNER:"Kandan"},stdio:["ignore","inherit","inherit"]});ye("process.spawned",{command:o,args:i,pid:s.pid,purpose:"local_editor.collaboration_sidecar",editorSessionId:e.editorSessionId,runtimeSessionId:e.runtimeSessionId},{sessionId:r}),s.once("exit",(c,l)=>{ye("process.exit",{command:o,args:i,pid:s.pid,code:c,signal:l,purpose:"local_editor.collaboration_sidecar",editorSessionId:e.editorSessionId,runtimeSessionId:e.runtimeSessionId},{sessionId:r})});let a=uF(s);return await cF(s)==="failed"?{ok:!1}:{ok:!0,ready:Ume(e.serverPort,a),collaboration:{provider:e.provider,editorSessionId:e.editorSessionId,runtimeSessionId:e.runtimeSessionId,roomId:e.roomId,serverPort:e.serverPort,serverUrl:e.serverUrl,bootstrapServerUrl:e.bootstrapServerUrl,collaborationStateUrl:e.collaborationStateUrl,process:s,exited:a}}}catch{return{ok:!1}}}function jme(e=process.env,n=process.execPath){let t=e.LINZUMI_NODE_BIN?.trim();return t!==void 0&&t!==""?t:bme(n).toLowerCase().includes("bun")?"node":n}async function rF(e,n){qa(n,{recursive:!0}),await Fme("tar",["-xzf",e,"-C",n])}function Lme(e,n){qa(Zi(n),{recursive:!0}),hme(e,n,{recursive:!0})}function zme(e,n,t,r){let{PORT:o,...i}=e,s={...i,PWD:n};return r===void 0?s:{...s,KANDAN_EDITOR_COLLABORATION_DEPLOYMENT_SHAPE:"local_runner_sidecar",KANDAN_EDITOR_COLLABORATION_ENTRY_MODE:"kandan_auto_host_or_join",KANDAN_EDITOR_COLLABORATION_ROOM_ID:r.roomId,KANDAN_EDITOR_COLLABORATION_SERVER_URL:r.bootstrapServerUrl,KANDAN_EDITOR_COLLABORATION_AUTO_HOST_CLAIM_PATH:Xn(t,"kandan-oct-auto-host.lock")}}function sk(e){if(e!==void 0)return{provider:e.provider,editorSessionId:e.editorSessionId,runtimeSessionId:e.runtimeSessionId,roomId:e.roomId,serverPort:e.serverPort,serverUrl:e.serverUrl}}function qme(e,n){return e===void 0||n===void 0?e===void 0&&n===void 0:e.editorSessionId===n.editorSessionId&&e.runtimeSessionId===n.runtimeSessionId&&e.roomId===n.roomId}function Fme(e,n){return new Promise((t,r)=>{ye("process.spawn",{command:e,args:n,purpose:"local_editor.install_process"});let o=ak(e,[...n],{stdio:["ignore","ignore","inherit"]});ye("process.spawned",{command:e,args:n,pid:o.pid,purpose:"local_editor.install_process"}),o.once("error",r),o.once("exit",(i,s)=>{ye("process.exit",{command:e,args:n,pid:o.pid,code:i,signal:s,purpose:"local_editor.install_process"}),i===0?t():r(new Error(`${e} exited with ${i??"unknown"}`))})})}function uF(e){return new Promise(n=>{let t=!1,r=()=>{e.off("exit",o),e.off("close",o)},o=()=>{t||(t=!0,r(),n())};e.once("exit",o),e.once("close",o),(e.exitCode!==null||e.signalCode!==null)&&o()})}function Nme(e,n,t=1e4){let r=Date.now()+t,o=`http://127.0.0.1:${e}/`;return new Promise(i=>{let s=!1,a,d=l=>{s||(s=!0,a!==void 0&&clearTimeout(a),i(l))},u=()=>{a=setTimeout(c,50)},c=async()=>{if(Date.now()>r){d("failed");return}try{if((await fetch(o)).status<500){d("ready");return}}catch{u();return}u()};n.then(()=>d("failed")),c()})}function Ume(e,n,t=1e4){let r=Date.now()+t,o=`http://127.0.0.1:${e}/api/login/initial`;return new Promise(i=>{let s=!1,a,d=l=>{s||(s=!0,a!==void 0&&clearTimeout(a),i(l))},u=()=>{a=setTimeout(c,50)},c=async()=>{if(Date.now()>r){d("failed");return}try{if((await fetch(o,{method:"POST"})).status<500){d("ready");return}}catch{u();return}u()};n.then(()=>d("failed")),c()})}function cF(e){return new Promise(n=>{let t=!1,r=()=>{e.off("spawn",o),e.off("error",i)},o=()=>{t||(t=!0,r(),n("spawned"))},i=()=>{t||(t=!0,r(),n("failed"))};e.once("spawn",o),e.once("error",i),setImmediate(()=>{!t&&e.pid!==void 0&&o()})})}var lF=j(()=>{"use strict";Ra();Es();kr()});import{spawn as Bme}from"node:child_process";import{createHash as mF}from"node:crypto";import{createReadStream as Jme,createWriteStream as Kme,existsSync as Zu,mkdirSync as zp,mkdtempSync as Vme,readFileSync as hF,renameSync as Wme,rmSync as pF,writeFileSync as gF}from"node:fs";import{homedir as Hme}from"node:os";import{dirname as ly,join as Rt,resolve as Zme}from"node:path";import{Readable as Gme}from"node:stream";import{pipeline as Qme}from"node:stream/promises";async function Gu(e){if(e.customCodeServerBin!==void 0)return{codeServerBin:e.customCodeServerBin,status:{status:"custom",mode:"custom",codeServerBin:e.customCodeServerBin}};let n=Xme(e.platform??process.platform,e.arch??process.arch);if(n===void 0)return uk("unsupported_platform");let t=await Yme({kandanUrl:e.kandanUrl,token:e.token,platform:n,fetchImpl:e.fetchImpl??fetch});if(!t.ok)return uk(t.reason);let r=e.cacheRoot??mhe(),o=rhe(r,t.manifest);if(o.ok)return fF(t.manifest,o.runtime,!1);let i=await ohe({kandanUrl:e.kandanUrl,token:e.token,manifest:t.manifest,cacheRoot:r,fetchImpl:e.fetchImpl??fetch,extractArchive:e.extractArchive??uhe});return i.ok?fF(t.manifest,i.runtime,!0):uk(i.reason)}function yF(e){switch(e.status){case"ready":return{status:"ready",mode:e.mode,version:e.version,platform:e.platform,archiveSha256:e.archiveSha256,codeServerVersion:e.codeServerVersion,updated:e.updated};case"custom":return{status:"custom",mode:e.mode,codeServerBin:e.codeServerBin};case"unavailable":return{status:"unavailable",mode:e.mode,reason:e.reason}}}function Xme(e,n){switch(`${e}-${n}`){case"darwin-arm64":return"darwin-arm64";case"darwin-x64":return"darwin-x64";case"linux-x64":return"linux-x64";default:return}}function uk(e){return{status:{status:"unavailable",mode:"server_managed",reason:e}}}function fF(e,n,t){return{codeServerBin:n.codeServerBin,runtime:n,status:{status:"ready",mode:"server_managed",version:e.version,platform:e.platform,archiveSha256:e.archiveSha256,codeServerVersion:e.codeServerVersion,codeServerBin:n.codeServerBin,updated:t}}}async function Yme(e){let n=new URL(`/api/v2/local-codex-runner/editor-runtime/${encodeURIComponent(e.platform)}/manifest`,Nn(e.kandanUrl)),t=await e.fetchImpl(n,{headers:{authorization:`Bearer ${e.token}`}}).catch(()=>{});if(t===void 0)return{ok:!1,reason:"manifest_unavailable"};if(t.status!==200)return{ok:!1,reason:t.status===401?await ehe(t):"manifest_unavailable"};let r=await t.json();return!Z(r)||r.ok!==!0||!Z(r.runtime)?{ok:!1,reason:"manifest_unavailable"}:nhe(r.runtime)}async function ehe(e){let n=await e.json().catch(()=>{});return Z(n)&&n.error==="token_expired"?"auth_expired":"auth_unauthorized"}function nhe(e){let n=gi(e.version),t=gi(e.platform),r=gi(e.archiveUrl),o=bF(e.archiveSha256),i=gi(e.codeServerVersion),s=gi(e.codeServerBinPath)??"bin/code-server",a=gi(e.manifestPath)??"linzumi-editor-runtime.json",d=the(e.assets);return n===void 0||t===void 0||r===void 0||o===void 0||i===void 0||d===void 0?{ok:!1,reason:"manifest_unavailable"}:{ok:!0,manifest:{version:n,platform:t,archiveUrl:r,archiveSha256:o,codeServerVersion:i,codeServerBinPath:s,manifestPath:a,assets:d}}}function the(e){if(!Array.isArray(e))return;let n=[];for(let t of e){if(!Z(t))return;let r=gi(t.path),o=bF(t.sha256),i=gi(t.url),s=gi(t.contentBase64);if(r===void 0||o===void 0)return;n.push({path:r,sha256:o,...i===void 0?{}:{url:i},...s===void 0?{}:{contentBase64:s}})}return n}function rhe(e,n){let t=xF(e,n),r=Rt(t,n.manifestPath),o=Rt(t,n.codeServerBinPath),i=_F(t,n);if(!Zu(r)||!Zu(o)||i===void 0)return{ok:!1};try{let s=JSON.parse(hF(r,"utf8"));if(Z(s)&&s.version===n.version&&s.platform===n.platform&&(s.archiveSha256===void 0||s.archiveSha256===n.archiveSha256))return{ok:!0,runtime:{mode:"server_managed",root:t,codeServerBin:o,assets:i}}}catch{return{ok:!1}}return{ok:!1}}async function ohe(e){zp(e.cacheRoot,{recursive:!0});let n=Vme(Rt(e.cacheRoot,".install-")),t=Rt(n,"runtime.tar.gz"),r=Rt(n,"runtime");try{let o=await ahe({kandanUrl:e.kandanUrl,token:e.token,manifest:e.manifest,archivePath:t,fetchImpl:e.fetchImpl});if(!o.ok)return o;if(zp(r,{recursive:!0}),!await e.extractArchive(t,r))return{ok:!1,reason:"archive_extract_failed"};if(!await ihe({kandanUrl:e.kandanUrl,manifest:e.manifest,runtimeRoot:r,fetchImpl:e.fetchImpl}))return{ok:!1,reason:"install_failed"};let s=Rt(r,e.manifest.manifestPath),a=Rt(r,e.manifest.codeServerBinPath),d=_F(r,e.manifest);if(!Zu(a)||d===void 0)return{ok:!1,reason:"invalid_archive"};zp(ly(s),{recursive:!0}),gF(s,JSON.stringify({version:e.manifest.version,platform:e.manifest.platform,archiveSha256:e.manifest.archiveSha256,codeServerVersion:e.manifest.codeServerVersion,codeServerBinPath:e.manifest.codeServerBinPath,manifestPath:e.manifest.manifestPath,assets:e.manifest.assets},null,2));let u=xF(e.cacheRoot,e.manifest);return pF(u,{recursive:!0,force:!0}),zp(ly(u),{recursive:!0}),Wme(r,u),{ok:!0,runtime:{mode:"server_managed",root:u,codeServerBin:Rt(u,e.manifest.codeServerBinPath),assets:{collaborationExtensionTarball:Rt(u,"kandan","editor_extensions","typefox.open-collaboration-tools.tar.gz"),collaborationServerTarball:Rt(u,"kandan","editor_servers","open-collaboration-server.tar.gz"),documentStateExtensionDir:Rt(u,"kandan","editor_extensions","kandan.document-state-telemetry")}}}}catch{return{ok:!1,reason:"install_failed"}}finally{pF(n,{recursive:!0,force:!0})}}async function ihe(e){for(let n of e.manifest.assets){let t=Rt(e.runtimeRoot,n.path);try{let r=await she({kandanUrl:e.kandanUrl,asset:n,fetchImpl:e.fetchImpl});if(r===void 0)continue;zp(ly(t),{recursive:!0}),gF(t,r)}catch{return!1}}return!0}async function she(e){if(e.asset.contentBase64!==void 0)return Buffer.from(e.asset.contentBase64,"base64");if(e.asset.url!==void 0){let n=new URL(e.asset.url,Nn(e.kandanUrl)),t=await e.fetchImpl(n);return t.status!==200?void 0:Buffer.from(await t.arrayBuffer())}}async function ahe(e){let n=Nn(e.kandanUrl),t=new URL(e.manifest.archiveUrl,n),r=await e.fetchImpl(t,{...dhe(t,new URL(n))?{headers:{authorization:`Bearer ${e.token}`}}:{}});return r.status!==200||r.body===null?{ok:!1,reason:"download_failed"}:(await Qme(Gme.fromWeb(r.body),Kme(e.archivePath)),await che(e.archivePath)!==e.manifest.archiveSha256?{ok:!1,reason:"checksum_mismatch"}:{ok:!0})}function dhe(e,n){return e.protocol===n.protocol&&e.host===n.host}function uhe(e,n){return new Promise(t=>{let o=["-xzf",e,"-C",n];ye("process.spawn",{command:"tar",args:o,purpose:"editor_runtime.extract"});let i=Bme("tar",o,{stdio:["ignore","ignore","ignore"]});ye("process.spawned",{command:"tar",args:o,pid:i.pid,purpose:"editor_runtime.extract"}),i.on("error",()=>t(!1)),i.on("exit",(s,a)=>{ye("process.exit",{command:"tar",args:o,pid:i.pid,code:s,signal:a,purpose:"editor_runtime.extract"}),t(s===0)})})}function che(e){return new Promise((n,t)=>{let r=mF("sha256"),o=Jme(e);o.on("error",t),o.on("data",i=>r.update(i)),o.on("end",()=>n(r.digest("hex")))})}function xF(e,n){return Zme(e,n.platform,n.archiveSha256)}function _F(e,n){let t=Rt(e,"kandan","editor_extensions","typefox.open-collaboration-tools.tar.gz"),r=Rt(e,"kandan","editor_servers","open-collaboration-server.tar.gz"),o=Rt(e,"kandan","editor_extensions","kandan.document-state-telemetry"),i=lhe(n.codeServerBinPath),s=[n.codeServerBinPath,Rt(i,"lib","vscode","node_modules","vsda","rust","web","vsda.js"),Rt(i,"lib","vscode","node_modules","vsda","rust","web","vsda_bg.wasm"),"kandan/editor_extensions/typefox.open-collaboration-tools.tar.gz","kandan/editor_servers/open-collaboration-server.tar.gz","kandan/editor_extensions/kandan.document-state-telemetry/package.json","kandan/editor_extensions/kandan.document-state-telemetry/out/extension.js"],a=phe(n.assets);for(let d of s){let u=a.get(d);if(u===void 0&&d!==n.codeServerBinPath)return;let c=Rt(e,d);if(!Zu(c)||u!==void 0&&fhe(c)!==u)return}if(!(!Zu(t)||!Zu(r)))return{collaborationExtensionTarball:t,collaborationServerTarball:r,documentStateExtensionDir:o}}function lhe(e){let n=e.replaceAll("\\","/");return n==="bin/code-server"?".":n.endsWith("/bin/code-server")?n.slice(0,-16)||".":ly(n)}function phe(e){let n=new Map;for(let t of e)n.set(t.path,t.sha256);return n}function fhe(e){return mF("sha256").update(hF(e)).digest("hex")}function mhe(){return Rt(Hme(),".linzumi","editor-runtimes")}function gi(e){return typeof e=="string"&&e.trim()!==""?e.trim():void 0}function bF(e){let n=gi(e);return n!==void 0&&/^[a-f0-9]{64}$/i.test(n)?n.toLowerCase():void 0}var py=j(()=>{"use strict";so();kr();Rn()});import{spawn as hhe,spawnSync as ghe}from"node:child_process";import{existsSync as yhe}from"node:fs";import{delimiter as xhe,dirname as _he,join as fy}from"node:path";function pk(e){return!bhe.has(e??"")}function Gi(e,n,t=1e3){return new Promise(r=>{let o=["--version"];ye("process.spawn",{command:e,args:o,cwd:n,purpose:"dependency_probe"});let i=hhe(e,o,{cwd:n,stdio:["ignore","pipe","pipe"],detached:process.platform!=="win32"});ye("process.spawned",{command:e,args:o,cwd:n,pid:i.pid,purpose:"dependency_probe"});let s="",a="",d=!1,u=l=>{d||(d=!0,clearTimeout(c),r(l))},c=setTimeout(()=>{vhe(i.pid),ye("process.exit",{command:e,args:o,cwd:n,pid:i.pid,code:null,signal:"SIGKILL",purpose:"dependency_probe"}),u({command:e,available:!1,failure:"probe_timeout",failureDetail:ck(a,s),failureTransient:!0})},t);i.stdout?.on("data",l=>{s+=l.toString()}),i.stderr?.on("data",l=>{a+=l.toString()}),i.on("error",l=>{ye("process.exit",{command:e,args:o,cwd:n,pid:i.pid,code:null,signal:null,error:"spawn_failed",purpose:"dependency_probe"});let f=l.code,m=f==="ENOENT"&&yhe(n);u({command:e,available:!1,failure:m?"binary_missing":"probe_failed",failureDetail:ck(l.message,a,s),failureTransient:m?!1:pk(f)})}),i.on("exit",(l,f)=>{if(ye("process.exit",{command:e,args:o,cwd:n,pid:i.pid,code:l,signal:f,purpose:"dependency_probe"}),l!==0){u({command:e,available:!1,failure:"probe_failed",failureDetail:ck(a,s),failureTransient:l===null});return}let m=CF(s,a);u(m===void 0?{command:e,available:!0}:{command:e,available:!0,version:m})})})}function ck(...e){for(let n of e){let t=n?.replace(/\s+/g," ").trim();if(t!==void 0&&t!=="")return t.slice(-whe)}}function vhe(e){if(e!==void 0)try{process.kill(process.platform==="win32"?e:-e,"SIGKILL")}catch{try{process.kill(e,"SIGKILL")}catch{}}}async function As(e){tg();let[n,t,r]=await Promise.all([Gi(process.execPath,e.cwd),She(e),Ehe(e)]);return{node:n,codex:t,codeServer:r,editorRuntime:e.editorRuntime}}function vF(e,n){let t=e.codex.available&&!n.codex.available&&(n.codex.failure==="probe_timeout"||n.codex.failure==="probe_failed"&&n.codex.failureTransient===!0);return{status:t?{...n,codex:e.codex}:n,codexDowngradeSkipped:t}}async function She(e){let n=await Gi(e.codexBin,e.cwd);if(n.available)return n;let t=n,r=a=>{a.failure!=="binary_missing"&&(t=a)},o=!e.codexBin.includes("/")&&!e.codexBin.includes("\\"),i=o?(e.resolveAgentBinaryPath??rg)(e.codexBin):void 0;if(i!==void 0&&i!==e.codexBin){let a=await Gi(i,e.cwd);if(a.available)return a;r(a)}let s=Che({cwd:e.cwd,codexBin:e.codexBin,env:e.env??process.env});if(s!==void 0){let a=await Gi(s,e.cwd);if(a.available)return a;r(a)}return o&&khe(e.codexBin,t.failureDetail),t}function khe(e,n){if(wF)return;wF=!0;let t=n===void 0?"":` Probe error: ${n}`;process.stderr.write(`Warning: ${xj(e,"--codex-bin")}${t}
1314
1314
  `)}function Che(e){return SF(Phe(e),e)}function SF(e,n){let[t,...r]=e;if(t===void 0)return;let o=The(t,n);return o===void 0?SF(r,n):o}function The(e,n){let t=ghe(e,["which","codex"],{cwd:n.cwd,env:n.env??process.env,encoding:"utf8",timeout:1e3});if(t.status===0)return CF(t.stdout?.toString())}function Phe(e){let n=e.env??process.env;return Array.from(new Set([Ihe(e.codexBin),n.VOLTA_HOME===void 0?void 0:fy(n.VOLTA_HOME,"bin","volta"),n.HOME===void 0?void 0:fy(n.HOME,".volta","bin","volta"),...Rhe(n.PATH)].filter(t=>t!==void 0)))}function Ihe(e){return e.replaceAll("\\","/").endsWith("/.volta/bin/codex")?fy(_he(e),"volta"):void 0}function Rhe(e){return e===void 0?[]:e.split(xhe).filter(n=>n!=="").map(n=>fy(n,"volta"))}function Ehe(e){switch(e.editorRuntime?.status){case"ready":return Promise.resolve({command:e.codeServerBin??e.editorRuntime.codeServerBin,available:!0,version:e.editorRuntime.codeServerVersion});case"unavailable":return Promise.resolve({command:e.codeServerBin??"code-server",available:!1,reason:"editor_runtime_unavailable"});case"custom":case void 0:break}return e.codeServerBin===void 0?Promise.resolve({command:"code-server",available:!1,reason:"not_configured"}):Gi(e.codeServerBin,e.cwd)}function kF(e){if($s(e),!e.codex.available)throw new Error(`Codex is not available at ${e.codex.command}. Install Codex or pass --codex-bin <path>.`)}function $s(e){if(!e.node.available)throw new Error("Node.js is not available. Install Node.js 20+, then rerun the bootstrap command.");if(e.editorRuntime?.status==="unavailable"||e.codeServer?.available===!1&&e.codeServer.reason!=="not_configured"){if(e.editorRuntime?.status==="unavailable")switch(e.editorRuntime.reason){case"auth_expired":throw new Error("Linzumi authentication expired. Sign in again, then reconnect the local runner.");case"auth_unauthorized":throw new Error("Linzumi authentication was rejected. Sign in again, then reconnect the local runner.");default:break}throw new Error("The Linzumi editor runtime is not available. Reconnect when the runtime update finishes or pass --code-server-bin <path> for a custom development runtime.")}}function fk(e){let n=e.codeServer??Dhe();return{bun:lk(e.node),codex:lk(e.codex),codeServer:lk(n),editorRuntime:e.editorRuntime===void 0?null:yF(e.editorRuntime)}}function Dhe(){return{command:"code-server",available:!1,reason:"not_configured"}}function lk(e){return{command:e.command,available:e.available,version:e.version??null,reason:e.reason??null}}function CF(...e){for(let n of e){let t=n?.trim();if(t!==void 0&&t!=="")return t}}var bhe,whe,wF,my=j(()=>{"use strict";rv();py();kr();bhe=new Set(["EACCES","EPERM","ENOTDIR"]);whe=500;wF=!1});import{closeSync as Mhe,openSync as Ahe,readSync as $he,statSync as Ohe}from"node:fs";function mk(e){return typeof e!="string"||e===""?e:jhe.reduce((n,t)=>t.source.startsWith("\\beyJ")?n.replace(t,"<redacted>"):n.replace(t,"$1<redacted>"),e)}function Nhe(e,n){let t;try{let{size:r}=Ohe(e),o=r>n?r-n:0,i=r-o;if(i<=0)return"";let s=Buffer.allocUnsafe(i);t=Ahe(e,"r");let a=$he(t,s,0,i,o);return s.subarray(0,a).toString("utf8")}catch{return""}finally{if(t!==void 0)try{Mhe(t)}catch{}}}function TF(e){let n=e.now??Date.now,t=e.setIntervalImpl??setInterval,r=e.clearIntervalImpl??clearInterval,o=e.readTail??Nhe,i=Math.max(zhe,e.intervalMs??Lhe),s=Math.max(1,e.maxTailBytes??qhe),a=Math.max(1,e.maxLifecycleEvents??Fhe),d=[],u=!1,c,l=v=>{try{for(d.push(v);d.length>a;)d.shift()}catch{}},f=()=>{try{let v=e.backendStderrSnapshot?.();if(typeof v!="string"||v==="")return;let S=v.length>s?v.slice(v.length-s):v;return mk(S)}catch{return}},m=()=>{let v=mk(o(e.runnerLogFile,s)),S=f(),b={kind:"runner_diagnostic_log",captured_at:new Date(n()).toISOString(),lifecycle:d.map(w=>({event:w.event,at:w.atIso,...w.closeCode===void 0?{}:{close_code:w.closeCode},...w.closeReason===void 0?{}:{close_reason:mk(w.closeReason)},...w.previousSessionDurationMs===void 0?{}:{previous_session_duration_ms:w.previousSessionDurationMs},...w.reconnectCount===void 0?{}:{reconnect_count:w.reconnectCount}})),runner_log_tail:v,...S===void 0?{}:{backend_stderr:S}};return{bundle_name:"runner-diagnostics",exported_at:new Date(n()).toISOString(),diagnostics:b,telemetry_ndjson:d.map(w=>JSON.stringify(w)).join(`
1315
- `)}},p=async()=>{let v=d.length;try{await Promise.resolve(e.upload(m())),d.splice(0,v)}catch(S){try{e.log?.("runner_diagnostics.upload_failed",{buffered_events:d.length,error:S instanceof Error?S.message:String(S)})}catch{}}},y=()=>{u||c!==void 0||(c=t(()=>{p()},i),c.unref?.())},x=()=>{u=!0,c!==void 0&&(r(c),c=void 0)};try{e.log?.("runner_diagnostics.enabled",{destination:"linzumi",runner_log_file:e.runnerLogFile,interval_ms:i,note:"runner lifecycle + runner-log tail + backend stderr are uploaded to Linzumi for support diagnostics (auto-deleted after 4 days)"})}catch{}return y(),{recordLifecycle:l,flushNow:p,stop:x}}var jhe,Lhe,zhe,qhe,Fhe,PF=j(()=>{"use strict";jhe=[/(--token[=\s]+)\S+/gi,/(bearer\s+)[^\s,;"'\]\}]+/gi,/((?:access[_-]?token|api[_-]?key|auth[_-]?token|authorization|secret|password|refresh[_-]?token|session[_-]?token|jwt|token)["']?\s*[:=]\s*["']?)[^\s,;"'\]\}]+/gi,/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g];Lhe=45e3,zhe=5e3,qhe=64*1024,Fhe=200});var jt,hk,Os=j(()=>{"use strict";jt="1.0.54",hk=`linzumi ${jt}`});import{closeSync as RF,existsSync as xk,mkdirSync as Uhe,openSync as EF,readFileSync as DF,renameSync as Bhe,unlinkSync as qp,writeFileSync as Jhe,writeSync as MF}from"node:fs";import{dirname as AF,join as Khe}from"node:path";function OF(e){return e instanceof Fa||e instanceof Error&&e.name===$F&&"lockPath"in e&&"heldBy"in e}function jF(e,n=Un(),t){let r=t===void 0?encodeURIComponent(e):$a(t);return Khe(AF(n),"runners",`${r}.lock`)}function LF(e){let n=jF(e.machineId,e.configPath,e.linzumiUrl),t=e.isPidAlive??sge,r=e.now??(()=>new Date),o=e.killPid??age,i=r().toISOString(),s={version:1,machineId:e.machineId,runnerId:e.runnerId,pid:e.pid??process.pid,cwd:e.cwd,workspace:e.workspace,...e.linzumiUrl===void 0?{}:{linzumiUrl:Nn(e.linzumiUrl)},...e.launchSource===void 0?{}:{launchSource:e.launchSource},startedAt:i,heartbeatAt:i,cliVersion:e.cliVersion??jt};Qhe(e.machineId,e.configPath,e.linzumiUrl,t,r,o,e.onTakeover),Xhe(n,s,t,r,o,e.onTakeover,e.beforeReadExistingLock,e.beforeReplaceStaleLock);let a=()=>Hhe(n,s,r),d=setInterval(a,Vhe);return d.unref(),{path:n,record:s,heartbeat:a,release:()=>{clearInterval(d),ege(n,s)}}}function Hhe(e,n,t){try{let r=gy(e);if(r===void 0||r.machineId!==n.machineId||r.runnerId!==n.runnerId||r.pid!==n.pid||r.startedAt!==n.startedAt)return;let o={...r,heartbeatAt:t().toISOString()},i=`${e}.tmp`;Jhe(i,`${JSON.stringify(o,null,2)}
1315
+ `)}},p=async()=>{let v=d.length;try{await Promise.resolve(e.upload(m())),d.splice(0,v)}catch(S){try{e.log?.("runner_diagnostics.upload_failed",{buffered_events:d.length,error:S instanceof Error?S.message:String(S)})}catch{}}},y=()=>{u||c!==void 0||(c=t(()=>{p()},i),c.unref?.())},x=()=>{u=!0,c!==void 0&&(r(c),c=void 0)};try{e.log?.("runner_diagnostics.enabled",{destination:"linzumi",runner_log_file:e.runnerLogFile,interval_ms:i,note:"runner lifecycle + runner-log tail + backend stderr are uploaded to Linzumi for support diagnostics (auto-deleted after 4 days)"})}catch{}return y(),{recordLifecycle:l,flushNow:p,stop:x}}var jhe,Lhe,zhe,qhe,Fhe,PF=j(()=>{"use strict";jhe=[/(--token[=\s]+)\S+/gi,/(bearer\s+)[^\s,;"'\]\}]+/gi,/((?:access[_-]?token|api[_-]?key|auth[_-]?token|authorization|secret|password|refresh[_-]?token|session[_-]?token|jwt|token)["']?\s*[:=]\s*["']?)[^\s,;"'\]\}]+/gi,/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g];Lhe=45e3,zhe=5e3,qhe=64*1024,Fhe=200});var jt,hk,Os=j(()=>{"use strict";jt="1.0.56",hk=`linzumi ${jt}`});import{closeSync as RF,existsSync as xk,mkdirSync as Uhe,openSync as EF,readFileSync as DF,renameSync as Bhe,unlinkSync as qp,writeFileSync as Jhe,writeSync as MF}from"node:fs";import{dirname as AF,join as Khe}from"node:path";function OF(e){return e instanceof Fa||e instanceof Error&&e.name===$F&&"lockPath"in e&&"heldBy"in e}function jF(e,n=Un(),t){let r=t===void 0?encodeURIComponent(e):$a(t);return Khe(AF(n),"runners",`${r}.lock`)}function LF(e){let n=jF(e.machineId,e.configPath,e.linzumiUrl),t=e.isPidAlive??sge,r=e.now??(()=>new Date),o=e.killPid??age,i=r().toISOString(),s={version:1,machineId:e.machineId,runnerId:e.runnerId,pid:e.pid??process.pid,cwd:e.cwd,workspace:e.workspace,...e.linzumiUrl===void 0?{}:{linzumiUrl:Nn(e.linzumiUrl)},...e.launchSource===void 0?{}:{launchSource:e.launchSource},startedAt:i,heartbeatAt:i,cliVersion:e.cliVersion??jt};Qhe(e.machineId,e.configPath,e.linzumiUrl,t,r,o,e.onTakeover),Xhe(n,s,t,r,o,e.onTakeover,e.beforeReadExistingLock,e.beforeReplaceStaleLock);let a=()=>Hhe(n,s,r),d=setInterval(a,Vhe);return d.unref(),{path:n,record:s,heartbeat:a,release:()=>{clearInterval(d),ege(n,s)}}}function Hhe(e,n,t){try{let r=gy(e);if(r===void 0||r.machineId!==n.machineId||r.runnerId!==n.runnerId||r.pid!==n.pid||r.startedAt!==n.startedAt)return;let o={...r,heartbeatAt:t().toISOString()},i=`${e}.tmp`;Jhe(i,`${JSON.stringify(o,null,2)}
1316
1316
  `,"utf8"),Bhe(i,e)}catch{}}function Qu(e,n,t){if(!n(e.pid))return{state:"dead"};let r=e.heartbeatAt??e.startedAt,o=Date.parse(r);return Number.isNaN(o)||t().getTime()-o>Whe?{state:"wedged",reason:e.heartbeatAt===void 0?"missing_heartbeat":"stale_heartbeat"}:{state:"live"}}function zF(e,n,t,r){return t!==hy||e.launchSource!==hy?!1:r.state!=="live"?!0:Zhe(n,e.cliVersion)>0}function Zhe(e,n){let t=IF(e),r=IF(n);for(let o=0;o<3;o++){let i=t.core[o],s=r.core[o];if(i===void 0||s===void 0)throw new Error(`compareCliVersions: unexpected undefined at core index ${o}`);if(i!==s)return i>s?1:-1}return t.prerelease.length===0&&r.prerelease.length===0?0:t.prerelease.length===0?1:r.prerelease.length===0?-1:Ghe(t.prerelease,r.prerelease)}function IF(e){let n=e.trim().replace(/^v/i,"").split("+",1)[0]??"",t=n.indexOf("-"),r=t===-1?n:n.slice(0,t),o=t===-1?"":n.slice(t+1),i=r.split("."),s=[gk(i[0]),gk(i[1]),gk(i[2])],a=o===""?[]:o.split(".").filter(d=>d!=="");return{core:s,prerelease:a}}function gk(e){let n=Number.parseInt(e??"",10);return Number.isInteger(n)&&n>=0?n:0}function Ghe(e,n){let t=Math.max(e.length,n.length);for(let r=0;r<t;r++){let o=e[r],i=n[r];if(o===void 0)return-1;if(i===void 0)return 1;let s=Number.parseInt(o,10),a=Number.parseInt(i,10),d=s.toString()===o,u=a.toString()===i;if(d&&u){if(s!==a)return s>a?1:-1}else{if(d!==u)return d?-1:1;if(o!==i)return o>i?1:-1}}return 0}function qF(e,n,t,r,o){try{r(n.pid)}catch(i){let s=i!==null&&typeof i=="object"&&"code"in i?i.code:void 0;if(s!=="ESRCH")throw s==="EPERM"||s==="EACCES"?new Error(`Cannot take over the runner lock at ${e}: its holder process (pid ${n.pid}) is owned by another user and cannot be stopped. Stop that process, or remove the lock file, then retry.`):i}o?.({lockPath:e,holderPid:n.pid,holderRunnerId:n.runnerId,reason:t})}function Qhe(e,n,t,r,o,i,s){if(t===void 0||rr(t)!==rr($t))return;let a=jF(e,n),d=gy(a);if(d!==void 0){if(Qu(d,r,o).state==="live")throw new Fa(a,d);FF(a,r,()=>{let u=xk(a)?bk(a):void 0;if(u===void 0)return;let c=Qu(u,r,o);if(c.state==="live")throw new Fa(a,u);c.state==="wedged"&&qF(a,u,c.reason,i,s),qp(a)})}}function Xhe(e,n,t,r,o,i,s,a){if(yk(e,n))return;s?.();let d=gy(e);if(d===void 0){if(yk(e,n))return;throw new Error(`another Linzumi runner lock appeared while starting: ${e}`)}if(Qu(d,t,r).state==="live")throw new Fa(e,d);a?.(),FF(e,t,()=>{let u=xk(e)?bk(e):void 0;if(u!==void 0){let c=Qu(u,t,r);if(c.state==="live")throw new Fa(e,u);c.state==="wedged"&&qF(e,u,c.reason,o,i),qp(e)}if(!yk(e,n))throw new Error(`another Linzumi runner lock appeared while starting: ${e}`)})}function yk(e,n){Uhe(AF(e),{recursive:!0});try{let t=EF(e,"wx");try{MF(t,`${JSON.stringify(n,null,2)}
1317
1317
  `)}finally{RF(t)}return!0}catch(t){if(Xu(t,"EEXIST"))return!1;throw t}}function FF(e,n,t){let r=`${e}.replace`;for(;;)try{let o=EF(r,"wx");try{MF(o,`${process.pid}
1318
1318
  `),t()}finally{RF(o),qp(r)}return}catch(o){if(Xu(o,"EEXIST")){let i=Yhe(r);if(i===void 0)continue;if(n(i))throw new Error(["another Linzumi runner is already replacing a stale runner lock",`lock: ${e}`,"Wait for that startup to finish, then retry."].join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linzumi/cli",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "Linzumi CLI \u2014 point a Codex agent at the real code on your laptop, with your team watching and steering from shared threads.",
5
5
  "type": "module",
6
6
  "bin": {