typescript-virtual-container 1.4.5 → 1.4.6

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.
Files changed (81) hide show
  1. package/README.md +1 -1
  2. package/builds/self-standalone.js +2 -2
  3. package/builds/self-standalone.js.map +2 -2
  4. package/builds/standalone-wo-sftp.js +38 -37
  5. package/builds/standalone-wo-sftp.js.map +3 -3
  6. package/builds/standalone.cjs +491 -0
  7. package/builds/standalone.cjs.map +7 -0
  8. package/builds/standalone.js +2 -1
  9. package/builds/standalone.js.map +3 -3
  10. package/dist/commands/man.js +1 -1
  11. package/dist/commands/man.js.map +1 -1
  12. package/dist/self-standalone.js +1 -0
  13. package/dist/self-standalone.js.map +1 -1
  14. package/dist/standalone.js +7 -3
  15. package/dist/standalone.js.map +1 -1
  16. package/docs/classes/HoneyPot.html +8 -8
  17. package/docs/classes/SshClient.html +18 -18
  18. package/docs/classes/VirtualFileSystem.html +29 -29
  19. package/docs/classes/VirtualPackageManager.html +12 -12
  20. package/docs/classes/VirtualSftpServer.html +3 -3
  21. package/docs/classes/VirtualShell.html +22 -22
  22. package/docs/classes/VirtualSshServer.html +5 -5
  23. package/docs/classes/VirtualUserManager.html +26 -26
  24. package/docs/functions/assertDiff.html +1 -1
  25. package/docs/functions/diffSnapshots.html +1 -1
  26. package/docs/functions/formatDiff.html +1 -1
  27. package/docs/functions/getArg.html +1 -1
  28. package/docs/functions/getFlag.html +1 -1
  29. package/docs/functions/ifFlag.html +1 -1
  30. package/docs/index.html +1 -1
  31. package/docs/interfaces/AuditLogEntry.html +2 -2
  32. package/docs/interfaces/CommandContext.html +11 -11
  33. package/docs/interfaces/CommandResult.html +12 -12
  34. package/docs/interfaces/ExecStream.html +5 -5
  35. package/docs/interfaces/HoneyPotStats.html +2 -2
  36. package/docs/interfaces/InstalledPackage.html +10 -10
  37. package/docs/interfaces/NanoEditorSession.html +4 -4
  38. package/docs/interfaces/PackageDefinition.html +13 -13
  39. package/docs/interfaces/PackageFile.html +4 -4
  40. package/docs/interfaces/RemoveOptions.html +2 -2
  41. package/docs/interfaces/ShellEnv.html +3 -3
  42. package/docs/interfaces/ShellModule.html +7 -7
  43. package/docs/interfaces/ShellProperties.html +4 -4
  44. package/docs/interfaces/ShellStream.html +6 -6
  45. package/docs/interfaces/SudoChallenge.html +8 -8
  46. package/docs/interfaces/VfsBaseNode.html +6 -6
  47. package/docs/interfaces/VfsDiff.html +5 -5
  48. package/docs/interfaces/VfsDiffEntry.html +3 -3
  49. package/docs/interfaces/VfsDiffModified.html +5 -5
  50. package/docs/interfaces/VfsDirectoryNode.html +7 -7
  51. package/docs/interfaces/VfsFileNode.html +8 -8
  52. package/docs/interfaces/VfsOptions.html +3 -3
  53. package/docs/interfaces/VfsSnapshot.html +2 -2
  54. package/docs/interfaces/VfsSnapshotBaseNode.html +3 -3
  55. package/docs/interfaces/VfsSnapshotDirectoryNode.html +4 -4
  56. package/docs/interfaces/VfsSnapshotFileNode.html +5 -5
  57. package/docs/interfaces/WriteFileOptions.html +3 -3
  58. package/docs/types/CommandMode.html +1 -1
  59. package/docs/types/CommandOutcome.html +1 -1
  60. package/docs/types/VfsNodeStats.html +1 -1
  61. package/docs/types/VfsNodeType.html +1 -1
  62. package/docs/types/VfsPersistenceMode.html +1 -1
  63. package/docs/types/VfsSnapshotNode.html +1 -1
  64. package/package.json +4 -4
  65. package/src/commands/man.ts +1 -1
  66. package/src/self-standalone.ts +1 -1
  67. package/src/standalone.ts +8 -3
  68. package/docs/docs/.nojekyll +0 -1
  69. package/docs/docs/assets/hierarchy.js +0 -1
  70. package/docs/docs/assets/highlight.css +0 -162
  71. package/docs/docs/assets/icons.js +0 -18
  72. package/docs/docs/assets/icons.svg +0 -1
  73. package/docs/docs/assets/main.js +0 -60
  74. package/docs/docs/assets/navigation.js +0 -1
  75. package/docs/docs/assets/search.js +0 -1
  76. package/docs/docs/assets/style.css +0 -1633
  77. package/docs/docs/hierarchy.html +0 -1
  78. package/docs/docs/index.html +0 -1842
  79. package/docs/docs/media/LICENSE +0 -21
  80. package/docs/docs/modules.html +0 -1
  81. package/typedoc.json +0 -8
package/README.md CHANGED
@@ -219,7 +219,7 @@ console.log(r.stdout);
219
219
 
220
220
  ---
221
221
 
222
- <details open>
222
+ <details>
223
223
  <summary><strong>API Reference</strong></summary>
224
224
 
225
225
  ### `VirtualSshServer`
@@ -111,7 +111,7 @@ ${u.join(`
111
111
  `,exitCode:0}}};var On={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:e,shell:t})=>{let n=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",o="1.0";try{let d=t.vfs.readFile("/etc/os-release");for(let m of d.split(`
112
112
  `))m.startsWith("PRETTY_NAME=")&&(n=m.slice(12).replace(/^"|"$/g,"").trim()),m.startsWith("VERSION_CODENAME=")&&(r=m.slice(17).trim()),m.startsWith("VERSION_ID=")&&(o=m.slice(11).replace(/^"|"$/g,"").trim())}catch{}let s=w(e,["-a","--all"]),i=w(e,["-i","--id"]),a=w(e,["-d","--description"]),c=w(e,["-r","--release"]),l=w(e,["-c","--codename"]);if(s||e.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${n}`,`Release: ${o}`,`Codename: ${r}`].join(`
113
113
  `),exitCode:0};let u=[];return i&&u.push("Distributor ID: Fortune"),a&&u.push(`Description: ${n}`),c&&u.push(`Release: ${o}`),l&&u.push(`Codename: ${r}`),{stdout:u.join(`
114
- `),exitCode:0}}};var Xs={gunzip:"gzip"},te=new Map,to=new URL("./manuals/",import.meta.url);async function eo(e){return new Function("moduleName","return import(moduleName)")(e)}async function no(e){let t=e.toLowerCase(),n=Xs[t]??t,r=`builtin:${n}`;if(te.has(r))return te.get(r)??null;try{let o=await eo("node:fs/promises"),s=new URL(`${n}.txt`,to),a=(await o.readFile(s,"utf8")).replace(/\n$/,"");return te.set(r,a),a}catch{return te.set(r,null),null}}var Wn={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:e,shell:t})=>{let n=e[0];if(!n)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${n}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let o=await no(n);return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${n}`,exitCode:16}}};var jn={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let o=0;o<r.length;o++){let s=bt(r,o);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let i=k(n,s);z(e,i,"mkdir"),t.vfs.mkdir(i)}return{exitCode:0}}};var Hn={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{let o=r.filter(l=>!l.startsWith("-")),[s,i]=o;if(!s||!i)return{stderr:"mv: missing operand",exitCode:1};let a=k(n,s),c=k(n,i);try{if(z(e,a,"mv"),z(e,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let l=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${s.split("/").pop()}`:c;return t.vfs.move(a,l),{exitCode:0}}catch(l){return{stderr:`mv: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};import*as qn from"node:path";var Kn={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{let o=r[0];if(!o)return{stderr:"nano: missing file operand",exitCode:1};let s=k(n,o);z(e,s,"nano");let i=t.vfs.exists(s)?t.vfs.readFile(s):"",a=qn.posix.basename(s)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:c,initialContent:i},exitCode:0}}};import{existsSync as tr,readdirSync as ro,readFileSync as Ce}from"node:fs";import*as nt from"node:os";import*as er from"node:path";function so(e){let t=Math.max(1,Math.floor(e/60)),n=Math.floor(t/1440),r=Math.floor(t%1440/60),o=t%60,s=[];return n>0&&s.push(`${n} day${n>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(o>0||s.length===0)&&s.push(`${o} min${o>1?"s":""}`),s.join(", ")}function Gn(e){return`\x1B[${e}m \x1B[0m`}function oo(){let e=[40,41,42,43,44,45,46,47].map(Gn).join(""),t=[100,101,102,103,104,105,106,107].map(Gn).join("");return[e,t]}function Zn(e,t,n){if(e.trim().length===0)return e;let r={r:255,g:255,b:255},o={r:168,g:85,b:247},s=n<=1?0:t/(n-1),i=Math.round(r.r+(o.r-r.r)*s),a=Math.round(r.g+(o.g-r.g)*s),c=Math.round(r.b+(o.b-r.b)*s);return`\x1B[38;2;${i};${a};${c}m${e}\x1B[0m`}function io(e){if(e.trim().length===0)return e;let t=e.indexOf(":");if(t===-1)return e.includes("@")?Jn(e):e;let n=e.substring(0,t+1),r=e.substring(t+1);return Jn(n)+r}function Jn(e){let t=new RegExp("\x1B\\[[\\d;]*m","g"),n=e.replace(t,"");if(n.trim().length===0)return e;let r={r:255,g:255,b:255},o={r:168,g:85,b:247},s="";for(let i=0;i<n.length;i+=1){let a=n.length<=1?0:i/(n.length-1),c=Math.round(r.r+(o.r-r.r)*a),l=Math.round(r.g+(o.g-r.g)*a),u=Math.round(r.b+(o.b-r.b)*a);s+=`\x1B[38;2;${c};${l};${u}m${n[i]}\x1B[0m`}return s}function Yn(e){return Math.max(0,Math.round(e/(1024*1024)))}function Qn(){try{let e=Ce("/etc/os-release","utf8");for(let t of e.split(`
114
+ `),exitCode:0}}};var Xs={gunzip:"gzip"},te=new Map,to=`${__dirname}/manuals/`;async function eo(e){return new Function("moduleName","return import(moduleName)")(e)}async function no(e){let t=e.toLowerCase(),n=Xs[t]??t,r=`builtin:${n}`;if(te.has(r))return te.get(r)??null;try{let o=await eo("node:fs/promises"),s=new URL(`${n}.txt`,to),a=(await o.readFile(s,"utf8")).replace(/\n$/,"");return te.set(r,a),a}catch{return te.set(r,null),null}}var Wn={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:e,shell:t})=>{let n=e[0];if(!n)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${n}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let o=await no(n);return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${n}`,exitCode:16}}};var jn={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let o=0;o<r.length;o++){let s=bt(r,o);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let i=k(n,s);z(e,i,"mkdir"),t.vfs.mkdir(i)}return{exitCode:0}}};var Hn={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{let o=r.filter(l=>!l.startsWith("-")),[s,i]=o;if(!s||!i)return{stderr:"mv: missing operand",exitCode:1};let a=k(n,s),c=k(n,i);try{if(z(e,a,"mv"),z(e,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let l=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${s.split("/").pop()}`:c;return t.vfs.move(a,l),{exitCode:0}}catch(l){return{stderr:`mv: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};import*as qn from"node:path";var Kn={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:e,shell:t,cwd:n,args:r})=>{let o=r[0];if(!o)return{stderr:"nano: missing file operand",exitCode:1};let s=k(n,o);z(e,s,"nano");let i=t.vfs.exists(s)?t.vfs.readFile(s):"",a=qn.posix.basename(s)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:c,initialContent:i},exitCode:0}}};import{existsSync as tr,readdirSync as ro,readFileSync as Ce}from"node:fs";import*as nt from"node:os";import*as er from"node:path";function so(e){let t=Math.max(1,Math.floor(e/60)),n=Math.floor(t/1440),r=Math.floor(t%1440/60),o=t%60,s=[];return n>0&&s.push(`${n} day${n>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(o>0||s.length===0)&&s.push(`${o} min${o>1?"s":""}`),s.join(", ")}function Gn(e){return`\x1B[${e}m \x1B[0m`}function oo(){let e=[40,41,42,43,44,45,46,47].map(Gn).join(""),t=[100,101,102,103,104,105,106,107].map(Gn).join("");return[e,t]}function Zn(e,t,n){if(e.trim().length===0)return e;let r={r:255,g:255,b:255},o={r:168,g:85,b:247},s=n<=1?0:t/(n-1),i=Math.round(r.r+(o.r-r.r)*s),a=Math.round(r.g+(o.g-r.g)*s),c=Math.round(r.b+(o.b-r.b)*s);return`\x1B[38;2;${i};${a};${c}m${e}\x1B[0m`}function io(e){if(e.trim().length===0)return e;let t=e.indexOf(":");if(t===-1)return e.includes("@")?Jn(e):e;let n=e.substring(0,t+1),r=e.substring(t+1);return Jn(n)+r}function Jn(e){let t=new RegExp("\x1B\\[[\\d;]*m","g"),n=e.replace(t,"");if(n.trim().length===0)return e;let r={r:255,g:255,b:255},o={r:168,g:85,b:247},s="";for(let i=0;i<n.length;i+=1){let a=n.length<=1?0:i/(n.length-1),c=Math.round(r.r+(o.r-r.r)*a),l=Math.round(r.g+(o.g-r.g)*a),u=Math.round(r.b+(o.b-r.b)*a);s+=`\x1B[38;2;${c};${l};${u}m${n[i]}\x1B[0m`}return s}function Yn(e){return Math.max(0,Math.round(e/(1024*1024)))}function Qn(){try{let e=Ce("/etc/os-release","utf8");for(let t of e.split(`
115
115
  `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function Xn(e){try{let t=Ce(e,"utf8").split(`
116
116
  `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function ao(e){let t=Xn("/sys/devices/virtual/dmi/id/sys_vendor"),n=Xn("/sys/devices/virtual/dmi/id/product_name");return t&&n?`${t} ${n}`:n||e}function co(){let e=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of e)if(tr(t))try{return Ce(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function lo(){let e=["/snap","/var/lib/snapd/snaps"];for(let t of e)if(tr(t))try{return ro(t,{withFileTypes:!0}).filter(o=>o.isDirectory()).length}catch{}}function uo(){let e=co(),t=lo();return e!==void 0&&t!==void 0?`${e} (dpkg), ${t} (snap)`:e!==void 0?`${e} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function mo(){let e=nt.cpus();if(e.length===0)return"unknown";let t=e[0];if(!t)return"unknown";let n=(t.speed/1e3).toFixed(2);return`${t.model} (${e.length}) @ ${n}GHz`}function po(e){return!e||e.trim().length===0?"unknown":er.posix.basename(e.trim())}function fo(e){let t=nt.totalmem(),n=nt.freemem(),r=Math.max(0,t-n),o=e.shellProps,s=process.uptime();return e.uptimeSeconds===void 0&&(e.uptimeSeconds=Math.round(s)),{user:e.user,host:e.host,osName:o?.os??e.osName??`${Qn()??nt.type()} ${nt.arch()}`,kernel:o?.kernel??e.kernel??nt.release(),uptimeSeconds:e.uptimeSeconds??nt.uptime(),packages:e.packages??uo(),shell:po(e.shell),shellProps:e.shellProps??{kernel:e.kernel??nt.release(),os:e.osName??`${Qn()??nt.type()} ${nt.arch()}`,arch:nt.arch()},resolution:e.resolution??"n/a (ssh)",terminal:e.terminal??"unknown",cpu:e.cpu??mo(),gpu:e.gpu??"n/a",memoryUsedMiB:e.memoryUsedMiB??Yn(r),memoryTotalMiB:e.memoryTotalMiB??Yn(t)}}function nr(e){let t=fo(e),n=so(t.uptimeSeconds),r=oo(),o=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${ao(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${n}`,`Packages: ${t.packages}`,`Shell: ${t.shell}`,`Resolution: ${t.resolution}`,`Terminal: ${t.terminal}`,`CPU: ${t.cpu}`,`GPU: ${t.gpu}`,`Memory: ${t.memoryUsedMiB}MiB / ${t.memoryTotalMiB}MiB`,"",r[0],r[1]],i=Math.max(o.length,s.length),a=[];for(let c=0;c<i;c+=1){let l=o[c]??"",u=s[c]??"";if(u.length>0){let d=Zn(l.padEnd(31," "),c,o.length),m=io(u);a.push(`${d} ${m}`);continue}a.push(Zn(l,c,o.length))}return a.join(`
117
117
  `)}var rr={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:e,authUser:t,hostname:n,shell:r,env:o})=>r.packageManager.isInstalled("neofetch")?w(e,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:w(e,"--off")?{stdout:`${t}@${n}`,exitCode:0}:{stdout:nr({user:t,host:n,shell:o.vars.SHELL,shellProps:r.properties,terminal:o.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
@@ -463,7 +463,7 @@ Sorry, try again.\r
463
463
  `),T.stderr&&t.write(`${jt(T.stderr)}\r
464
464
  `),T.closeSession){t.write(`logout\r
465
465
  `),t.exit(T.exitCode??0),t.end();return}T.nextCwd&&(p=T.nextCwd),T.switchUser&&(n=T.switchUser,p=T.nextCwd??`/home/${n}`,a.users.updateSession(o,n,s),c="",l=0),await a.vfs.flushMirror()}E();continue}if(D==="\x7F"||D==="\b"){l>0&&(c=`${c.slice(0,l-1)}${c.slice(l)}`,l-=1,E());continue}C(D)}}),t.on("close",()=>{y&&(y.process.kill("SIGTERM"),y=null)})}function di(e,t){let n=`/home/${t}/.bash_history`;return e.exists(n)?e.readFile(n).split(`
466
- `).map(o=>o.trim()).filter(o=>o.length>0):(e.writeFile(n,""),[])}function pi(e){return typeof e=="object"&&e!==null&&"vfsInstance"in e&&Ps(e.vfsInstance)}function Ps(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.restoreMirror=="function"&&typeof t.flushMirror=="function"&&typeof t.writeFile=="function"&&typeof t.readFile=="function"&&typeof t.mkdir=="function"&&typeof t.exists=="function"&&typeof t.stat=="function"&&typeof t.list=="function"&&typeof t.remove=="function"&&typeof t.copy=="function"&&typeof t.move=="function"&&typeof t.touch=="function"}var fi={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Ht=he("VirtualShell");function hi(){let e=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return e?!["0","false","no","off"].includes(e.toLowerCase()):!0}var we=class extends mi{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,n,r){super(),Ht.mark("constructor"),this.hostname=t,this.properties=n||fi,this.startTime=Date.now(),Ps(r)?this.vfs=r:pi(r)?this.vfs=r.vfsInstance:this.vfs=new xs(r??{}),this.users=new Se(this.vfs,hi()),this.packageManager=new ye(this.vfs,this.users);let o=this.vfs,s=this.users,i=this.packageManager,a=this.properties,c=this.hostname,l=this.startTime;this.initialized=(async()=>{await o.restoreMirror(),await s.initialize(),ls(o,s,c,a,l),i.load(),this.emit("initialized")})()}async ensureInitialized(){Ht.mark("ensureInitialized"),await this.initialized}addCommand(t,n,r){let o=t.trim().toLowerCase();if(o.length===0||/\s/.test(o))throw new Error("Command name must be non-empty and contain no spaces");Me(Ae(o,n,r))}executeCommand(t,n,r){Ht.mark("executeCommand"),G(t,n,this.hostname,"shell",r,this),this.emit("command",{command:t,user:n,cwd:r})}startInteractiveSession(t,n,r,o,s){Ht.mark("startInteractiveSession"),this.emit("session:start",{user:n,sessionId:r,remoteAddress:o}),Cs(this.properties,t,n,this.hostname,r,o,s,this),this.refreshProcSessions()}refreshProcFs(){fe(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,n,r={}){this.vfs.mount(t,n,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){fe(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Ve(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,n,r){Ht.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,n,r),this.vfs.writeFile(n,r)}};var Rt=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Oe=process.argv.slice(2);function bi(){for(let e=0;e<Oe.length;e+=1){let t=Oe[e];if(t==="--user"){let n=Oe[e+1];if(!n||n.startsWith("--"))throw new Error("self-standalone: --user requires a value");return n}if(t?.startsWith("--user="))return t.slice(7)||"root"}return"root"}var $i=bi(),Z=new we(Rt,void 0,{mode:"fs",snapshotPath:".vfs"});function vi(e){let t=`/home/${e}/.lastlog`;if(!Z.vfs.exists(t))return null;try{return JSON.parse(Z.vfs.readFile(t))}catch{return null}}function Ci(e,t){Z.vfs.writeFile(`/home/${e}/.lastlog`,JSON.stringify({at:new Date().toISOString(),from:t}))}async function qt(){await Z.vfs.flushMirror()}function Pi(e){let t=`/home/${e}/.bash_history`;return Z.vfs.exists(t)?Z.vfs.readFile(t).split(`
466
+ `).map(o=>o.trim()).filter(o=>o.length>0):(e.writeFile(n,""),[])}function pi(e){return typeof e=="object"&&e!==null&&"vfsInstance"in e&&Ps(e.vfsInstance)}function Ps(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.restoreMirror=="function"&&typeof t.flushMirror=="function"&&typeof t.writeFile=="function"&&typeof t.readFile=="function"&&typeof t.mkdir=="function"&&typeof t.exists=="function"&&typeof t.stat=="function"&&typeof t.list=="function"&&typeof t.remove=="function"&&typeof t.copy=="function"&&typeof t.move=="function"&&typeof t.touch=="function"}var fi={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Ht=he("VirtualShell");function hi(){let e=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return e?!["0","false","no","off"].includes(e.toLowerCase()):!0}var we=class extends mi{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,n,r){super(),Ht.mark("constructor"),this.hostname=t,this.properties=n||fi,this.startTime=Date.now(),Ps(r)?this.vfs=r:pi(r)?this.vfs=r.vfsInstance:this.vfs=new xs(r??{}),this.users=new Se(this.vfs,hi()),this.packageManager=new ye(this.vfs,this.users);let o=this.vfs,s=this.users,i=this.packageManager,a=this.properties,c=this.hostname,l=this.startTime;this.initialized=(async()=>{await o.restoreMirror(),await s.initialize(),ls(o,s,c,a,l),i.load(),this.emit("initialized")})()}async ensureInitialized(){Ht.mark("ensureInitialized"),await this.initialized}addCommand(t,n,r){let o=t.trim().toLowerCase();if(o.length===0||/\s/.test(o))throw new Error("Command name must be non-empty and contain no spaces");Me(Ae(o,n,r))}executeCommand(t,n,r){Ht.mark("executeCommand"),G(t,n,this.hostname,"shell",r,this),this.emit("command",{command:t,user:n,cwd:r})}startInteractiveSession(t,n,r,o,s){Ht.mark("startInteractiveSession"),this.emit("session:start",{user:n,sessionId:r,remoteAddress:o}),Cs(this.properties,t,n,this.hostname,r,o,s,this),this.refreshProcSessions()}refreshProcFs(){fe(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,n,r={}){this.vfs.mount(t,n,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){fe(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Ve(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,n,r){Ht.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,n,r),this.vfs.writeFile(n,r)}};var Rt=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Oe=process.argv.slice(2);console.clear();function bi(){for(let e=0;e<Oe.length;e+=1){let t=Oe[e];if(t==="--user"){let n=Oe[e+1];if(!n||n.startsWith("--"))throw new Error("self-standalone: --user requires a value");return n}if(t?.startsWith("--user="))return t.slice(7)||"root"}return"root"}var $i=bi(),Z=new we(Rt,void 0,{mode:"fs",snapshotPath:".vfs"});function vi(e){let t=`/home/${e}/.lastlog`;if(!Z.vfs.exists(t))return null;try{return JSON.parse(Z.vfs.readFile(t))}catch{return null}}function Ci(e,t){Z.vfs.writeFile(`/home/${e}/.lastlog`,JSON.stringify({at:new Date().toISOString(),from:t}))}async function qt(){await Z.vfs.flushMirror()}function Pi(e){let t=`/home/${e}/.bash_history`;return Z.vfs.exists(t)?Z.vfs.readFile(t).split(`
467
467
  `).map(n=>n.trim()).filter(n=>n.length>0):(Z.vfs.writeFile(t,""),[])}function ki(e,t){let n=e.length>0?`${e.join(`
468
468
  `)}
469
469
  `:"";Z.vfs.writeFile(`/home/${t}/.bash_history`,n)}function Mi(e,t,n){let r=n.lastIndexOf("/"),o=r>=0?n.slice(0,r+1):"",s=r>=0?n.slice(r+1):n,i=ue(t,o||".");try{return e.list(i).filter(a=>!a.startsWith(".")&&a.startsWith(s)).map(a=>{let c=ks.posix.join(i,a),l=e.stat(c);return`${o}${a}${l.type==="directory"?"/":""}`}).sort()}catch{return[]}}function Ai(e){let t=Array.from(new Set(Bt())).sort();return(n,r)=>{let{cwd:o}=e(),s=n.split(/\s+/).at(-1)??"",a=n.trimStart()===s?t.filter(u=>u.startsWith(s)):[],c=Mi(Z.vfs,o,s),l=Array.from(new Set([...a,...c])).sort();r(null,[l,s])}}function Kt(e,t){return new Promise(n=>{if(!ct.isTTY||!st.isTTY){e.question(t,n);return}let r=!!ct.isRaw,o="",s=()=>{ct.off("data",a),r||ct.setRawMode(!1)},i=c=>{s(),st.write(`