9remote 2.0.73 → 2.0.77
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/dist/cli.cjs +2 -2
- package/dist/ptyDaemon.cjs +7 -7
- package/dist/server.cjs +81 -81
- package/dist/ui/assets/index-DWrz-evW.js +54031 -0
- package/dist/ui/assets/{index-B9PikATf.css → index-vQVARods.css} +542 -10
- package/dist/ui/index.html +2 -2
- package/package.json +15 -1
- package/dist/ui/assets/index-PW3GPJh6.js +0 -19762
package/dist/cli.cjs
CHANGED
|
@@ -9,7 +9,7 @@ Right-click to open / quit`}function qi(){let{port:e,tunnelUrl:n}=Nt,r=process.p
|
|
|
9
9
|
`}l||(t+=p)}else{var v=to(cr).times(o.getModuleCount()+3);t+=v+`
|
|
10
10
|
`,o.modules.forEach(function(T){t+=cr,t+=T.map(Ac).join(""),t+=cr+`
|
|
11
11
|
`}),t+=v}r?r(t):console.log(t)},setErrorLevel:function(e){this.error=xs[e]||this.error}}});var kn=require("fs"),Vt=require("path"),mo=require("url"),ho=A(require("os"),1);var An=A(require("dns"),1),_e=A(require("path"),1),ao=A(require("os"),1),ne="9remote",pr=process.env.NREMOTE_REGISTRY||`https://registry.npmjs.org/${ne}/latest`,Pe=`${ne}@latest`,Fe=_e.default.join(ao.default.homedir(),".9remote"),re={ROOT:Fe,LOGS:_e.default.join(Fe,"logs"),STATE:_e.default.join(Fe,"state"),CONFIG:_e.default.join(Fe,"config"),BIN:_e.default.join(Fe,"bin"),PIDS:_e.default.join(Fe,"pids"),BUFFERS:_e.default.join(Fe,"buffers"),DAEMON:_e.default.join(Fe,"daemon")},co=new An.default.promises.Resolver;co.setServers(["1.1.1.1","1.0.0.1","8.8.8.8"]);var fr=An.default.lookup,Js=/^(\d{1,3}\.){3}\d{1,3}$|^::1$|^[0-9a-f:]+$/i;An.default.lookup=(e,n,r)=>{if(typeof n=="function"&&(r=n,n={}),e==="localhost"||Js.test(e))return fr(e,n,r);co.resolve4(e).then(o=>{if(!o?.length)return fr(e,n,r);n.all?r(null,o.map(t=>({address:t,family:4}))):r(null,o[0],4)}).catch(()=>fr(e,n,r))};var I=2208,so=5173;var qc=[`http://localhost:${I}`,`http://127.0.0.1:${I}`,`http://localhost:${so}`,`http://127.0.0.1:${so}`],Wt={fileName:"agent.log",rotatedName:"agent.log.1",maxBytes:2*1024*1024,cleanupAfterDays:7},lo=60,C={STOPPED:0,PREPARING:1,CONNECTING:2,TUNNELING:3,VERIFYING:4,READY:5},uo={showTunnelUrlInMenu:!1};var fo={CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN:"1"};var po={checkIntervalMs:3e4,requestTimeoutMs:5e3},le={server:{strategy:"exp",baseMs:1e3,maxMs:6e4},tunnelRestart:{strategy:"exp",baseMs:2e3,maxMs:3e5},tunnelSpawn:{strategy:"linear",baseMs:5e3,maxMs:6e4},internet:{strategy:"linear",baseMs:3e3,maxMs:6e4},sse:{strategy:"linear",baseMs:2e3,maxMs:2e3},urlSync:{strategy:"linear",baseMs:5e3,maxMs:6e4}},Qs={Accept:"application/json, text/plain, */*","Accept-Language":"en-US,en;q=0.9","Cache-Control":"no-cache",Pragma:"no-cache","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"};function G(e,n={}){return fetch(e,{...n,headers:{...Qs,...n.headers}})}var Xs=(0,Vt.dirname)((0,mo.fileURLToPath)(__importMetaUrl)),Zs=[(0,Vt.join)(ho.default.homedir(),".9remote",".env"),(0,Vt.join)(Xs,"..",".env")];function zs(e){for(let n of e.split(`
|
|
12
|
-
`)){let r=n.trim();if(!r||r.startsWith("#"))continue;let o=r.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*"?(.*?)"?$/);o&&!process.env[o[1]]&&(process.env[o[1]]=o[2])}}for(let e of Zs)if((0,kn.existsSync)(e))try{zs((0,kn.readFileSync)(e,"utf8"))}catch{}for(let[e,n]of Object.entries(fo))process.env[e]||(process.env[e]=n);var yr=A(require("path"),1),To=A(require("fs"),1),xo=require("url");var yo=A(go(),1),mr=A(require("crypto"),1),{machineIdSync:ea}=yo.default;async function vt(e=null){let n=e||process.env.MACHINE_ID_SALT||"9remote-salt";try{let r=ea();return mr.default.createHash("sha256").update(r+n).digest("hex").substring(0,16)}catch(r){return console.error("Error getting machine ID:",r),mr.default.randomUUID().replace(/-/g,"").substring(0,16)}}var wo=A(require("crypto"),1),ta=process.env.API_KEY_SECRET||"9remote-api-key-secret";function na(){let e="abcdefghijklmnopqrstuvwxyz0123456789",n="";for(let r=0;r<4;r++)n+=e.charAt(Math.floor(Math.random()*e.length));return n}function ra(e,n){return wo.default.createHmac("sha256",ta).update(e+n).digest("hex").slice(0,6)}function St(e){let n=e.slice(0,8),r=na(),o=ra(n,r);return{key:`sk-${n}-${r}-${o}`,keyId:r}}function _n(e){return!e||e.length<8?"sk-***":`${e.slice(0,3)}***${e.slice(-4)}`}var ae=A(require("fs"),1),qt=A(require("path"),1);var el=re.STATE,hr=qt.default.join(re.STATE,"state.json"),gr=qt.default.join(re.ROOT,"keys.json"),Pn=qt.default.join(re.STATE,"cmd.json"),tl=qt.default.join(re.STATE,"settings.json");function In(){for(let e of[re.ROOT,re.STATE])ae.default.existsSync(e)||ae.default.mkdirSync(e,{recursive:!0})}function On(e){try{In(),ae.default.writeFileSync(hr,JSON.stringify(e,null,2),{mode:384})}catch(n){console.error("Error saving state:",n)}}function vo(){try{ae.default.existsSync(hr)&&ae.default.unlinkSync(hr)}catch{}}function Cn(){try{return In(),ae.default.existsSync(gr)?JSON.parse(ae.default.readFileSync(gr,"utf8")):{machineId:null,key:null,name:"Default",createdAt:null}}catch{return{machineId:null,key:null,name:"Default",createdAt:null}}}function Et(e){try{In(),ae.default.writeFileSync(Pn,JSON.stringify({cmd:e,ts:Date.now()}))}catch{}}function So(){try{if(!ae.default.existsSync(Pn))return null;let e=JSON.parse(ae.default.readFileSync(Pn,"utf8"));return ae.default.unlinkSync(Pn),e.cmd}catch{return null}}function nt(e,n,r="Default"){try{In();let o={machineId:e,key:n,name:r,createdAt:new Date().toISOString()};return ae.default.writeFileSync(gr,JSON.stringify(o,null,2),{mode:384}),o}catch(o){return console.error("Error saving key:",o),null}}function Eo(){return process.env.CODESPACES==="true"}var oa=yr.default.dirname((0,xo.fileURLToPath)(__importMetaUrl));async function Ue(){let e=await vt();if(Eo()&&process.env.NREMOTE_API_KEY)return nt(e,process.env.NREMOTE_API_KEY,"Codespace");let n=Cn();if(!n.key){let{key:r}=St(e);n=nt(e,r,"Default")}return n}function Se(){return"2.0.
|
|
12
|
+
`)){let r=n.trim();if(!r||r.startsWith("#"))continue;let o=r.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*"?(.*?)"?$/);o&&!process.env[o[1]]&&(process.env[o[1]]=o[2])}}for(let e of Zs)if((0,kn.existsSync)(e))try{zs((0,kn.readFileSync)(e,"utf8"))}catch{}for(let[e,n]of Object.entries(fo))process.env[e]||(process.env[e]=n);var yr=A(require("path"),1),To=A(require("fs"),1),xo=require("url");var yo=A(go(),1),mr=A(require("crypto"),1),{machineIdSync:ea}=yo.default;async function vt(e=null){let n=e||process.env.MACHINE_ID_SALT||"9remote-salt";try{let r=ea();return mr.default.createHash("sha256").update(r+n).digest("hex").substring(0,16)}catch(r){return console.error("Error getting machine ID:",r),mr.default.randomUUID().replace(/-/g,"").substring(0,16)}}var wo=A(require("crypto"),1),ta=process.env.API_KEY_SECRET||"9remote-api-key-secret";function na(){let e="abcdefghijklmnopqrstuvwxyz0123456789",n="";for(let r=0;r<4;r++)n+=e.charAt(Math.floor(Math.random()*e.length));return n}function ra(e,n){return wo.default.createHmac("sha256",ta).update(e+n).digest("hex").slice(0,6)}function St(e){let n=e.slice(0,8),r=na(),o=ra(n,r);return{key:`sk-${n}-${r}-${o}`,keyId:r}}function _n(e){return!e||e.length<8?"sk-***":`${e.slice(0,3)}***${e.slice(-4)}`}var ae=A(require("fs"),1),qt=A(require("path"),1);var el=re.STATE,hr=qt.default.join(re.STATE,"state.json"),gr=qt.default.join(re.ROOT,"keys.json"),Pn=qt.default.join(re.STATE,"cmd.json"),tl=qt.default.join(re.STATE,"settings.json");function In(){for(let e of[re.ROOT,re.STATE])ae.default.existsSync(e)||ae.default.mkdirSync(e,{recursive:!0})}function On(e){try{In(),ae.default.writeFileSync(hr,JSON.stringify(e,null,2),{mode:384})}catch(n){console.error("Error saving state:",n)}}function vo(){try{ae.default.existsSync(hr)&&ae.default.unlinkSync(hr)}catch{}}function Cn(){try{return In(),ae.default.existsSync(gr)?JSON.parse(ae.default.readFileSync(gr,"utf8")):{machineId:null,key:null,name:"Default",createdAt:null}}catch{return{machineId:null,key:null,name:"Default",createdAt:null}}}function Et(e){try{In(),ae.default.writeFileSync(Pn,JSON.stringify({cmd:e,ts:Date.now()}))}catch{}}function So(){try{if(!ae.default.existsSync(Pn))return null;let e=JSON.parse(ae.default.readFileSync(Pn,"utf8"));return ae.default.unlinkSync(Pn),e.cmd}catch{return null}}function nt(e,n,r="Default"){try{In();let o={machineId:e,key:n,name:r,createdAt:new Date().toISOString()};return ae.default.writeFileSync(gr,JSON.stringify(o,null,2),{mode:384}),o}catch(o){return console.error("Error saving key:",o),null}}function Eo(){return process.env.CODESPACES==="true"}var oa=yr.default.dirname((0,xo.fileURLToPath)(__importMetaUrl));async function Ue(){let e=await vt();if(Eo()&&process.env.NREMOTE_API_KEY)return nt(e,process.env.NREMOTE_API_KEY,"Codespace");let n=Cn();if(!n.key){let{key:r}=St(e);n=nt(e,r,"Default")}return n}function Se(){return"2.0.77"}var Ee=A(require("fs"),1),vr=A(require("path"),1);var $n=re.LOGS,Qt=vr.default.join($n,Wt.fileName),Ln=vr.default.join($n,Wt.rotatedName),Ro=!1,bo=null;function ia(){Ee.default.existsSync($n)||Ee.default.mkdirSync($n,{recursive:!0})}function sa(){try{if(Ee.default.statSync(Qt).size<Wt.maxBytes)return;try{Ee.default.rmSync(Ln,{force:!0})}catch{}Ee.default.renameSync(Qt,Ln)}catch{}}function aa(){try{let e=Ee.default.statSync(Ln);Date.now()-e.mtimeMs>Wt.cleanupAfterDays*864e5&&Ee.default.rmSync(Ln,{force:!0})}catch{}}function Sr(e){try{sa(),Ee.default.appendFileSync(Qt,e+`
|
|
13
13
|
`)}catch{}}function wr(e){return e.map(n=>{if(n instanceof Error)return n.stack||n.message;if(typeof n=="object")try{return JSON.stringify(n)}catch{return String(n)}return String(n)}).join(" ")}function Ao(){let e=new Date,n=(r,o=2)=>String(r).padStart(o,"0");return`${n(e.getHours())}:${n(e.getMinutes())}:${n(e.getSeconds())}.${n(e.getMilliseconds(),3)}`}var ca=/\x1b\[[0-9;]*m/g,la=/https?:\/\/[^\s]+/g;function ua(e){return String(e).replace(ca,"").replace(la,"").replace(/\s+$/g,"")}function Jt(e,n,r){let o=ua(r);if(!o)return;let t=n==="info"?e:`${e}:${n}`,i=`${Ao()} [${t}] ${o}`;if(Sr(i),bo)try{bo(i)}catch{}}function fa(){process.on("uncaughtException",e=>Jt("crash","error",`uncaughtException: ${e?.stack||e?.message||e}`)),process.on("unhandledRejection",e=>{let n=e instanceof Error?e.stack||e.message:String(e);Jt("crash","error",`unhandledRejection: ${n}`)}),process.on("exit",e=>Sr(`${Ao()} [exit] code=${e} pid=${process.pid}`))}function ko(){Ro||(Ro=!0,ia(),aa(),Sr(`
|
|
14
14
|
=== SESSION ${new Date().toISOString()} pid=${process.pid} argv=${process.argv.slice(2).join(" ")} ===`),fa())}function _o(e=60){try{return Ee.default.readFileSync(Qt,"utf8").split(`
|
|
15
15
|
`).filter(Boolean).slice(-e)}catch{return[]}}function q(e){return{info:(...n)=>Jt(e,"info",wr(n)),warn:(...n)=>Jt(e,"warn",wr(n)),error:(...n)=>Jt(e,"error",wr(n))}}var Xt=Qt;var Po=(e=0)=>n=>`\x1B[${n+e}m`,Io=(e=0)=>n=>`\x1B[${38+e};5;${n}m`,Oo=(e=0)=>(n,r,o)=>`\x1B[${38+e};2;${n};${r};${o}m`,M={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},fl=Object.keys(M.modifier),pa=Object.keys(M.color),da=Object.keys(M.bgColor),pl=[...pa,...da];function ma(){let e=new Map;for(let[n,r]of Object.entries(M)){for(let[o,t]of Object.entries(r))M[o]={open:`\x1B[${t[0]}m`,close:`\x1B[${t[1]}m`},r[o]=M[o],e.set(t[0],t[1]);Object.defineProperty(M,n,{value:r,enumerable:!1})}return Object.defineProperty(M,"codes",{value:e,enumerable:!1}),M.color.close="\x1B[39m",M.bgColor.close="\x1B[49m",M.color.ansi=Po(),M.color.ansi256=Io(),M.color.ansi16m=Oo(),M.bgColor.ansi=Po(10),M.bgColor.ansi256=Io(10),M.bgColor.ansi16m=Oo(10),Object.defineProperties(M,{rgbToAnsi256:{value(n,r,o){return n===r&&r===o?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(r/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(n){let r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(n.toString(16));if(!r)return[0,0,0];let[o]=r;o.length===3&&(o=[...o].map(i=>i+i).join(""));let t=Number.parseInt(o,16);return[t>>16&255,t>>8&255,t&255]},enumerable:!1},hexToAnsi256:{value:n=>M.rgbToAnsi256(...M.hexToRgb(n)),enumerable:!1},ansi256ToAnsi:{value(n){if(n<8)return 30+n;if(n<16)return 90+(n-8);let r,o,t;if(n>=232)r=((n-232)*10+8)/255,o=r,t=r;else{n-=16;let a=n%36;r=Math.floor(n/36)/5,o=Math.floor(a/6)/5,t=a%6/5}let i=Math.max(r,o,t)*2;if(i===0)return 30;let s=30+(Math.round(t)<<2|Math.round(o)<<1|Math.round(r));return i===2&&(s+=60),s},enumerable:!1},rgbToAnsi:{value:(n,r,o)=>M.ansi256ToAnsi(M.rgbToAnsi256(n,r,o)),enumerable:!1},hexToAnsi:{value:n=>M.ansi256ToAnsi(M.hexToAnsi256(n)),enumerable:!1}}),M}var ha=ma(),he=ha;var Nn=A(require("node:process"),1),$o=A(require("node:os"),1),Er=A(require("node:tty"),1);function ue(e,n=globalThis.Deno?globalThis.Deno.args:Nn.default.argv){let r=e.startsWith("-")?"":e.length===1?"-":"--",o=n.indexOf(r+e),t=n.indexOf("--");return o!==-1&&(t===-1||o<t)}var{env:N}=Nn.default,Mn;ue("no-color")||ue("no-colors")||ue("color=false")||ue("color=never")?Mn=0:(ue("color")||ue("colors")||ue("color=true")||ue("color=always"))&&(Mn=1);function ga(){if("FORCE_COLOR"in N)return N.FORCE_COLOR==="true"?1:N.FORCE_COLOR==="false"?0:N.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(N.FORCE_COLOR,10),3)}function ya(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function wa(e,{streamIsTTY:n,sniffFlags:r=!0}={}){let o=ga();o!==void 0&&(Mn=o);let t=r?Mn:o;if(t===0)return 0;if(r){if(ue("color=16m")||ue("color=full")||ue("color=truecolor"))return 3;if(ue("color=256"))return 2}if("TF_BUILD"in N&&"AGENT_NAME"in N)return 1;if(e&&!n&&t===void 0)return 0;let i=t||0;if(N.TERM==="dumb")return i;if(Nn.default.platform==="win32"){let s=$o.default.release().split(".");return Number(s[0])>=10&&Number(s[2])>=10586?Number(s[2])>=14931?3:2:1}if("CI"in N)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(s=>s in N)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(s=>s in N)||N.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in N)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(N.TEAMCITY_VERSION)?1:0;if(N.COLORTERM==="truecolor"||N.TERM==="xterm-kitty"||N.TERM==="xterm-ghostty"||N.TERM==="wezterm")return 3;if("TERM_PROGRAM"in N){let s=Number.parseInt((N.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(N.TERM_PROGRAM){case"iTerm.app":return s>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(N.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(N.TERM)||"COLORTERM"in N?1:i}function Co(e,n={}){let r=wa(e,{streamIsTTY:e&&e.isTTY,...n});return ya(r)}var va={stdout:Co({isTTY:Er.default.isatty(1)}),stderr:Co({isTTY:Er.default.isatty(2)})},Lo=va;function Mo(e,n,r){let o=e.indexOf(n);if(o===-1)return e;let t=n.length,i=0,s="";do s+=e.slice(i,o)+n+r,i=o+t,o=e.indexOf(n,i);while(o!==-1);return s+=e.slice(i),s}function No(e,n,r,o){let t=0,i="";do{let s=e[o-1]==="\r";i+=e.slice(t,s?o-1:o)+n+(s?`\r
|
|
@@ -71,7 +71,7 @@ StandardError=append:${Hn}
|
|
|
71
71
|
|
|
72
72
|
[Install]
|
|
73
73
|
WantedBy=default.target
|
|
74
|
-
`}function Na(e){try{return(0,it.execFileSync)("systemctl",["--user",...e],{stdio:"ignore"}),!0}catch{return!1}}function Da(){return(0,$.existsSync)(J.linux)||(0,$.existsSync)(J.linuxSystemd)}async function Fa(){try{if(process.platform==="darwin")return Ia();if(process.platform==="win32")return await $a();if(process.platform==="linux")return Da()}catch{}return!1}async function Jo(){try{if(process.platform==="win32"&&Ca(),!await Fa())return!1;if(process.platform==="darwin"){let e=Pa(je(),st());return((0,$.existsSync)(J.darwin)?(0,$.readFileSync)(J.darwin,"utf8"):"")===e?!1:((0,$.writeFileSync)(J.darwin,e),!0)}if(process.platform==="win32"){let e=Oa();return((0,$.existsSync)(J.win)?(0,$.readFileSync)(J.win,"utf8"):"")===e?!1:((0,$.writeFileSync)(J.win,e),!0)}if(process.platform==="linux"){if((0,$.existsSync)(J.linuxSystemd)){let e=Ma();return(0,$.readFileSync)(J.linuxSystemd,"utf8")===e?!1:((0,$.writeFileSync)(J.linuxSystemd,e),Na(["daemon-reload"]),!0)}if((0,$.existsSync)(J.linux)){let e=La();return(0,$.readFileSync)(J.linux,"utf8")===e?!1:((0,$.writeFileSync)(J.linux,e),!0)}}}catch{}return!1}var D="https://9remote.cc",Qo=3e4,Xo=500,Pr=300,ge={cmdMs:1e3,pendingApprovalMs:3e3,statsMs:5e3,serverReadyIntervalMs:200,serverReadyTimeoutMs:5e3,bgServerReadyTimeoutMs:15e3,bgServerReadyIntervalMs:300},Ke={intervalMs:2e3,timeoutMs:18e4,fetchTimeoutMs:5e3,dnsTimeoutMs:2e3,maxLogEntries:80,postReadyHoldMs:2e3},oe={killCloudflaredMs:500,killCloudflaredTuiMs:300,serverBootMs:2e3,trayReadyMs:1e3,postReadyHoldMs:2e3,bgSpawnFlushMs:400},Ie={maxLogLines:200,headerWidth:44},bt={checkIntervalMs:36e5,connectCheckDebounceMs:9e5,maxRetry:3,retryDelayMs:3e3,verifyTimeoutMs:15e3,lockTtlMs:3e5,lockFile:"update.lock"},Zo=5e3,zo=2,ei=3e4,fe={orange:m.rgb(230,138,110),orangeDim:m.rgb(200,120,95)};var Ua=Oe.default.dirname((0,ti.fileURLToPath)(__importMetaUrl)),ni=3e3;var Wn=2208,Ir=Oe.default.join(At.default.homedir(),".9remote","cloudflared.pid");function Ba(){try{Ko()}catch{}try{if((0,Q.existsSync)(Ir)){let e=parseInt((0,Q.readFileSync)(Ir,"utf8"));if(Number.isFinite(e))try{process.kill(e)}catch{}try{(0,Q.unlinkSync)(Ir)}catch{}}}catch{}try{process.platform==="win32"?(0,tn.execSync)(`for /f "tokens=5" %a in ('netstat -aon ^| findstr :${Wn}') do taskkill /F /PID %a`,{stdio:"ignore",windowsHide:!0}):(0,tn.execSync)(`lsof -ti:${Wn} | xargs kill -9 2>/dev/null || true`,{stdio:"ignore"})}catch{}if(process.platform==="win32"){let e=Date.now()+1500;for(;Date.now()<e;);}}function ri(){return"2.0.
|
|
74
|
+
`}function Na(e){try{return(0,it.execFileSync)("systemctl",["--user",...e],{stdio:"ignore"}),!0}catch{return!1}}function Da(){return(0,$.existsSync)(J.linux)||(0,$.existsSync)(J.linuxSystemd)}async function Fa(){try{if(process.platform==="darwin")return Ia();if(process.platform==="win32")return await $a();if(process.platform==="linux")return Da()}catch{}return!1}async function Jo(){try{if(process.platform==="win32"&&Ca(),!await Fa())return!1;if(process.platform==="darwin"){let e=Pa(je(),st());return((0,$.existsSync)(J.darwin)?(0,$.readFileSync)(J.darwin,"utf8"):"")===e?!1:((0,$.writeFileSync)(J.darwin,e),!0)}if(process.platform==="win32"){let e=Oa();return((0,$.existsSync)(J.win)?(0,$.readFileSync)(J.win,"utf8"):"")===e?!1:((0,$.writeFileSync)(J.win,e),!0)}if(process.platform==="linux"){if((0,$.existsSync)(J.linuxSystemd)){let e=Ma();return(0,$.readFileSync)(J.linuxSystemd,"utf8")===e?!1:((0,$.writeFileSync)(J.linuxSystemd,e),Na(["daemon-reload"]),!0)}if((0,$.existsSync)(J.linux)){let e=La();return(0,$.readFileSync)(J.linux,"utf8")===e?!1:((0,$.writeFileSync)(J.linux,e),!0)}}}catch{}return!1}var D="https://9remote.cc",Qo=3e4,Xo=500,Pr=300,ge={cmdMs:1e3,pendingApprovalMs:3e3,statsMs:5e3,serverReadyIntervalMs:200,serverReadyTimeoutMs:5e3,bgServerReadyTimeoutMs:15e3,bgServerReadyIntervalMs:300},Ke={intervalMs:2e3,timeoutMs:18e4,fetchTimeoutMs:5e3,dnsTimeoutMs:2e3,maxLogEntries:80,postReadyHoldMs:2e3},oe={killCloudflaredMs:500,killCloudflaredTuiMs:300,serverBootMs:2e3,trayReadyMs:1e3,postReadyHoldMs:2e3,bgSpawnFlushMs:400},Ie={maxLogLines:200,headerWidth:44},bt={checkIntervalMs:36e5,connectCheckDebounceMs:9e5,maxRetry:3,retryDelayMs:3e3,verifyTimeoutMs:15e3,lockTtlMs:3e5,lockFile:"update.lock"},Zo=5e3,zo=2,ei=3e4,fe={orange:m.rgb(230,138,110),orangeDim:m.rgb(200,120,95)};var Ua=Oe.default.dirname((0,ti.fileURLToPath)(__importMetaUrl)),ni=3e3;var Wn=2208,Ir=Oe.default.join(At.default.homedir(),".9remote","cloudflared.pid");function Ba(){try{Ko()}catch{}try{if((0,Q.existsSync)(Ir)){let e=parseInt((0,Q.readFileSync)(Ir,"utf8"));if(Number.isFinite(e))try{process.kill(e)}catch{}try{(0,Q.unlinkSync)(Ir)}catch{}}}catch{}try{process.platform==="win32"?(0,tn.execSync)(`for /f "tokens=5" %a in ('netstat -aon ^| findstr :${Wn}') do taskkill /F /PID %a`,{stdio:"ignore",windowsHide:!0}):(0,tn.execSync)(`lsof -ti:${Wn} | xargs kill -9 2>/dev/null || true`,{stdio:"ignore"})}catch{}if(process.platform==="win32"){let e=Date.now()+1500;for(;Date.now()<e;);}}function ri(){return"2.0.77"}function oi(e,n){let r=e.split(".").map(Number),o=n.split(".").map(Number);for(let t=0;t<3;t++){if(o[t]>r[t])return!0;if(o[t]<r[t])return!1}return!1}function Ha(){return process.env.CODESPACES==="true"||process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN?"GitHub Codespaces":(0,Q.existsSync)("/.dockerenv")?"Docker":null}function Vn(){Ba()}async function ii(){try{let e=ri();if(!e)return null;let n=await G(pr,{signal:AbortSignal.timeout(ni)});if(!n.ok)return null;let{version:r}=await n.json();return r&&oi(e,r)?{current:e,latest:r}:null}catch{return null}}var Gn=Oe.default.join(re.STATE,bt.lockFile);function ja(){try{if((0,Q.existsSync)(Gn)){let{pid:e,ts:n}=JSON.parse((0,Q.readFileSync)(Gn,"utf8")),r=Date.now()-n<bt.lockTtlMs,o=!1;try{process.kill(e,0),o=!0}catch{}if(r&&o)return!1}}catch{}try{(0,Q.writeFileSync)(Gn,JSON.stringify({pid:process.pid,ts:Date.now()}))}catch{}return!0}async function Ka(){try{let e=await G(pr,{signal:AbortSignal.timeout(ni)});if(!e.ok)return null;let{version:n}=await e.json();return n||null}catch{return null}}function Ga(){try{if(process.env.NREMOTE_REGISTRY)return`--registry ${new URL(process.env.NREMOTE_REGISTRY).origin}`}catch{}return""}function Wa({currentVersion:e,latest:n,agentPid:r}){let o=Go(),t=Ga(),i=je(),s=st(),a=Gn,c=`--prefer-online --no-audit --no-fund ${t}`.trim();if(process.platform==="win32"){let f=Oe.default.join(At.default.tmpdir(),`${ne}-restart.vbs`),p=`@echo off
|
|
75
75
|
setlocal EnableDelayedExpansion
|
|
76
76
|
set "NODE=${i}"
|
|
77
77
|
set "CLI=${s}"
|
package/dist/ptyDaemon.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const __importMetaUrl = require('url').pathToFileURL(__filename).href;
|
|
3
|
-
var
|
|
4
|
-
`;try{
|
|
5
|
-
`),
|
|
6
|
-
`;for(let t of O)try{t.write(r)}catch{}}function
|
|
7
|
-
`)}catch{}}function
|
|
8
|
-
`;setTimeout(()=>{try{
|
|
9
|
-
`);o=
|
|
3
|
+
var T=Object.create;var L=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of q(r))!j.call(e,s)&&s!==t&&L(e,s,{get:()=>r[s],enumerable:!(o=z(r,s))||o.enumerable});return e};var b=(e,r,t)=>(t=e!=null?T(F(e)):{},H(r||!e||!e.__esModule?L(t,"default",{value:e,enumerable:!0}):t,e));var _=b(require("net"),1),c=b(require("fs"),1),d=b(require("path"),1),R=b(require("os"),1),M=b(require("node-pty"),1);var k={win32:[{id:"cmd",label:"Command Prompt",path:"cmd.exe",args:[]},{id:"powershell",label:"PowerShell",path:"powershell.exe",args:["-NoLogo"]},{id:"pwsh",label:"PowerShell Core",path:"pwsh.exe",args:["-NoLogo"]}],unix:[{id:"bash",label:"Bash",path:"/bin/bash",args:["-l"]},{id:"zsh",label:"Zsh",path:"/bin/zsh",args:["-l"]},{id:"sh",label:"Sh",path:"/bin/sh",args:["-l"]}]};function C(e){if(process.platform==="win32"){let o=e?k.win32.find(n=>n.id===e):null;if(o)return o;let s=process.env.COMSPEC;return s?{id:"cmd",label:"Command Prompt",path:s,args:[]}:k.win32[0]}let r=process.env.SHELL||"/bin/bash",t=r.split("/").pop();return{id:t,label:t,path:r,args:["-l"]}}var E=d.default.join(R.default.homedir(),".9remote"),y=process.platform==="win32"?"\\\\.\\pipe\\9remote-pty":d.default.join(E,"pty-daemon.sock"),x=d.default.join(E,"pids","ptyDaemon.pid"),u=new Map,O=new Set,N=2*1024*1024,Z=256*1024,U=5*1024*1024;function A(e,r){if(!e?.length||r<=0)return"";let t=r,o=[];for(let s=e.length-1;s>=0&&t>0;s--){let n=e[s];n.length<=t?(o.push(n),t-=n.length):(o.push(n.slice(n.length-t)),t=0)}return o.reverse(),o.join("")}var P=d.default.join(E,"logs"),w=d.default.join(P,"daemon.log");try{c.default.existsSync(P)||c.default.mkdirSync(P,{recursive:!0})}catch{}function B(){try{if(c.default.existsSync(w)&&c.default.statSync(w).size>U){let t=c.default.readFileSync(w,"utf8").slice(-1024*1024);c.default.writeFileSync(w,t)}}catch{}}function m(e,r=null){B();let o=`[${new Date().toISOString()}] ERROR: ${e}`;r&&(o+=` - ${r.message||r}`),o+=`
|
|
4
|
+
`;try{c.default.appendFileSync(w,o)}catch{}console.error(o.trim())}function J(){return process.env.CODESPACES==="true"?process.env.CODESPACE_VSCODE_FOLDER||"/workspaces":process.env.HOME||process.env.USERPROFILE||R.default.homedir()}function W(e){let r={...process.env,TERM:"xterm-256color",COLORTERM:"truecolor",LANG:process.env.LANG||"en_US.UTF-8"};delete r.PORT;let t=e.includes("zsh"),o=e.includes("bash"),s=null;if(t){s=c.default.mkdtempSync(d.default.join(R.default.tmpdir(),"9remote-zsh-"));let n=d.default.join(s,".zshrc"),i=r.HOME?d.default.join(r.HOME,".zshrc"):null,l='precmd() { print -Pn "\\e]7;file://%m${PWD}\\e\\\\" }\n';i&&c.default.existsSync(i)&&(l+=`[ -f "${i}" ] && source "${i}"
|
|
5
|
+
`),c.default.writeFileSync(n,l),r.ZDOTDIR=s}else if(o){let n=r.PROMPT_COMMAND||"";r.PROMPT_COMMAND=`printf "\\e]7;file://%s\\a" "\${HOSTNAME}\${PWD}"${n?`; ${n}`:""}`}return{env:r,zdotDir:s}}function D(e){let r=JSON.stringify(e)+`
|
|
6
|
+
`;for(let t of O)try{t.write(r)}catch{}}function h(e,r){try{e.write(JSON.stringify(r)+`
|
|
7
|
+
`)}catch{}}function V(e,r,t=80,o=24,s=null,n=null){if(u.has(e))return{success:!1,error:"Session already exists"};let i=C(s);(!n||!c.default.existsSync(n))&&(n=J());try{let{env:l,zdotDir:I}=W(i.path);l.NINE_REMOTE_SESSION_ID=e;let S=M.default.spawn(i.path,i.args,{name:"xterm-256color",cols:t,rows:o,cwd:n,env:l,useConpty:process.platform==="win32"});if(i.id==="powershell"||i.id==="pwsh"){let f=`function prompt { $p = $PWD.Path -replace '\\\\','/'; "$([char]27)]7;file://$([System.Net.Dns]::GetHostName())$p$([char]27)\\PS $($PWD.Path)> " }\r
|
|
8
|
+
`;setTimeout(()=>{try{S.write(f)}catch{}},500)}let p={pty:S,buffer:[],name:r,createdAt:Date.now(),cwd:n,shellId:i.id,shellLabel:i.label,zdotDir:I};return S.onData(f=>{p.buffer.push(f);let g=f.match(/\x1b\]7;file:\/\/[^/]*([^\x07\x1b]*)/);if(g){let a;try{a=decodeURIComponent(g[1])}catch{a=g[1]}a&&a!==p.cwd&&(p.cwd=a,D({type:"cwdChange",sessionId:e,cwd:a}))}p.buffer.reduce((a,$)=>a+$.length,0)>N&&(p.buffer=[A(p.buffer,N)]),D({type:"output",sessionId:e,data:Buffer.from(f).toString("base64")})}),S.onExit(()=>{u.delete(e),p.zdotDir&&c.default.rm(p.zdotDir,{recursive:!0,force:!0},()=>{}),D({type:"sessionClosed",sessionId:e})}),u.set(e,p),{success:!0,sessionId:e,cwd:n,shellId:i.id,shellLabel:i.label}}catch(l){return m("Failed to create session",l),{success:!1,error:l.message}}}function K(e,r){let{type:t,sessionId:o,...s}=r;switch(t){case"ping":h(e,{type:"pong",version:"22",requestId:s.requestId});break;case"listSessions":let n=Array.from(u.entries()).map(([v,a])=>({id:v,name:a.name,createdAt:a.createdAt,shellId:a.shellId,shellLabel:a.shellLabel,cwd:a.cwd}));h(e,{type:"sessionList",sessions:n,requestId:s.requestId});break;case"createSession":let i=V(o||`session-${Date.now()}`,s.name,s.cols,s.rows,s.shellId,s.cwd);h(e,{type:"createResult",...i,requestId:s.requestId});break;case"joinSession":let l=u.get(o);if(!l){h(e,{type:"joinResult",success:!1,error:"Session not found",requestId:s.requestId});return}let I=A(l.buffer,Z);I&&h(e,{type:"output",sessionId:o,data:Buffer.from(I).toString("base64")}),h(e,{type:"joinResult",success:!0,name:l.name,cwd:l.cwd,shellId:l.shellId,shellLabel:l.shellLabel,requestId:s.requestId});break;case"input":let S=u.get(o);S?.pty&&S.pty.write(s.data);break;case"resize":let p=u.get(o);if(p?.pty)try{p.pty.resize(s.cols,s.rows)}catch{}break;case"deleteSession":let f=u.get(o);f?(f.pty&&f.pty.kill(),u.delete(o),D({type:"sessionClosed",sessionId:o}),h(e,{type:"deleteResult",success:!0,requestId:s.requestId})):h(e,{type:"deleteResult",success:!1,error:"Session not found",requestId:s.requestId});break;case"getCwd":let g=u.get(o);h(e,{type:"cwdResult",cwd:g?.cwd||null,requestId:s.requestId});break;default:m(`Unknown message type: ${t}`)}}function X(){if(!c.default.existsSync(E))try{c.default.mkdirSync(E,{recursive:!0})}catch(t){m("Failed to create socket directory",t),process.exit(1)}if(process.platform!=="win32"&&c.default.existsSync(y))try{c.default.unlinkSync(y)}catch(t){m("Failed to remove stale socket",t),process.exit(1)}let e=_.default.createServer(t=>{O.add(t);let o="";t.on("data",s=>{o+=s.toString();let n=o.split(`
|
|
9
|
+
`);o=n.pop()||"";for(let i of n)if(i.trim())try{let l=JSON.parse(i);K(t,l)}catch{m("Invalid message",i)}}),t.on("close",()=>{O.delete(t)}),t.on("error",s=>{m("Client error",s),O.delete(t)})});e.on("error",t=>{m("Server error",t),t.code==="EADDRINUSE"&&m("Socket already in use, exiting"),process.exit(1)}),e.listen(y,()=>{if(process.platform!=="win32")try{c.default.chmodSync(y,384)}catch{}});try{c.default.mkdirSync(d.default.dirname(x),{recursive:!0}),c.default.writeFileSync(x,String(process.pid),{mode:384})}catch{}let r=()=>{for(let[,t]of u)if(t.pty)try{t.pty.kill()}catch{}try{e.close()}catch{}if(process.platform!=="win32"&&c.default.existsSync(y))try{c.default.unlinkSync(y)}catch{}try{c.default.unlinkSync(x)}catch{}process.exit(0)};process.on("SIGTERM",r),process.on("SIGINT",r)}X();
|