typescript-virtual-container 1.4.7 → 1.4.8

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 (120) hide show
  1. package/README.md +0 -1
  2. package/benchmark-results.txt +21 -21
  3. package/builds/self-standalone.js +979 -167
  4. package/builds/self-standalone.js.map +4 -4
  5. package/builds/standalone-wo-sftp.js +982 -172
  6. package/builds/standalone-wo-sftp.js.map +4 -4
  7. package/builds/standalone.cjs +990 -179
  8. package/builds/standalone.cjs.map +4 -4
  9. package/dist/SSHMimic/index.d.ts.map +1 -1
  10. package/dist/SSHMimic/index.js +2 -0
  11. package/dist/SSHMimic/index.js.map +1 -1
  12. package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
  13. package/dist/VirtualFileSystem/binaryPack.js +21 -9
  14. package/dist/VirtualFileSystem/binaryPack.js.map +1 -1
  15. package/dist/VirtualFileSystem/index.d.ts +25 -0
  16. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  17. package/dist/VirtualFileSystem/index.js +152 -47
  18. package/dist/VirtualFileSystem/index.js.map +1 -1
  19. package/dist/VirtualFileSystem/internalTypes.d.ts +19 -4
  20. package/dist/VirtualFileSystem/internalTypes.d.ts.map +1 -1
  21. package/dist/VirtualFileSystem/path.js +1 -1
  22. package/dist/VirtualFileSystem/path.js.map +1 -1
  23. package/dist/VirtualShell/idleManager.d.ts +65 -0
  24. package/dist/VirtualShell/idleManager.d.ts.map +1 -0
  25. package/dist/VirtualShell/idleManager.js +106 -0
  26. package/dist/VirtualShell/idleManager.js.map +1 -0
  27. package/dist/VirtualShell/index.d.ts +28 -0
  28. package/dist/VirtualShell/index.d.ts.map +1 -1
  29. package/dist/VirtualShell/index.js +48 -0
  30. package/dist/VirtualShell/index.js.map +1 -1
  31. package/dist/commands/man.d.ts.map +1 -1
  32. package/dist/commands/man.js +5 -28
  33. package/dist/commands/man.js.map +1 -1
  34. package/dist/commands/manuals-bundle.d.ts +11 -0
  35. package/dist/commands/manuals-bundle.d.ts.map +1 -0
  36. package/dist/commands/manuals-bundle.js +898 -0
  37. package/dist/commands/manuals-bundle.js.map +1 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/modules/linuxRootfs.d.ts +8 -1
  43. package/dist/modules/linuxRootfs.d.ts.map +1 -1
  44. package/dist/modules/linuxRootfs.js +47 -14
  45. package/dist/modules/linuxRootfs.js.map +1 -1
  46. package/dist/self-standalone.js +15 -0
  47. package/dist/self-standalone.js.map +1 -1
  48. package/dist/standalone.js +22 -0
  49. package/dist/standalone.js.map +1 -1
  50. package/docs/assets/hierarchy.js +1 -1
  51. package/docs/assets/navigation.js +1 -1
  52. package/docs/assets/search.js +1 -1
  53. package/docs/classes/HoneyPot.html +8 -8
  54. package/docs/classes/IdleManager.html +159 -0
  55. package/docs/classes/SshClient.html +18 -18
  56. package/docs/classes/VirtualFileSystem.html +57 -32
  57. package/docs/classes/VirtualPackageManager.html +12 -12
  58. package/docs/classes/VirtualSftpServer.html +3 -3
  59. package/docs/classes/VirtualShell.html +40 -25
  60. package/docs/classes/VirtualSshServer.html +5 -5
  61. package/docs/classes/VirtualUserManager.html +26 -26
  62. package/docs/functions/assertDiff.html +1 -1
  63. package/docs/functions/diffSnapshots.html +1 -1
  64. package/docs/functions/formatDiff.html +1 -1
  65. package/docs/functions/getArg.html +1 -1
  66. package/docs/functions/getFlag.html +1 -1
  67. package/docs/functions/ifFlag.html +1 -1
  68. package/docs/hierarchy.html +1 -1
  69. package/docs/index.html +1 -2
  70. package/docs/interfaces/AuditLogEntry.html +2 -2
  71. package/docs/interfaces/CommandContext.html +11 -11
  72. package/docs/interfaces/CommandResult.html +12 -12
  73. package/docs/interfaces/ExecStream.html +5 -5
  74. package/docs/interfaces/HoneyPotStats.html +2 -2
  75. package/docs/interfaces/IdleManagerOptions.html +7 -0
  76. package/docs/interfaces/InstalledPackage.html +10 -10
  77. package/docs/interfaces/NanoEditorSession.html +4 -4
  78. package/docs/interfaces/PackageDefinition.html +13 -13
  79. package/docs/interfaces/PackageFile.html +4 -4
  80. package/docs/interfaces/RemoveOptions.html +2 -2
  81. package/docs/interfaces/ShellEnv.html +3 -3
  82. package/docs/interfaces/ShellModule.html +7 -7
  83. package/docs/interfaces/ShellProperties.html +4 -4
  84. package/docs/interfaces/ShellStream.html +6 -6
  85. package/docs/interfaces/SudoChallenge.html +8 -8
  86. package/docs/interfaces/VfsBaseNode.html +6 -6
  87. package/docs/interfaces/VfsDiff.html +5 -5
  88. package/docs/interfaces/VfsDiffEntry.html +3 -3
  89. package/docs/interfaces/VfsDiffModified.html +5 -5
  90. package/docs/interfaces/VfsDirectoryNode.html +7 -7
  91. package/docs/interfaces/VfsFileNode.html +8 -8
  92. package/docs/interfaces/VfsOptions.html +18 -4
  93. package/docs/interfaces/VfsSnapshot.html +2 -2
  94. package/docs/interfaces/VfsSnapshotBaseNode.html +3 -3
  95. package/docs/interfaces/VfsSnapshotDirectoryNode.html +4 -4
  96. package/docs/interfaces/VfsSnapshotFileNode.html +5 -5
  97. package/docs/interfaces/WriteFileOptions.html +3 -3
  98. package/docs/modules.html +1 -1
  99. package/docs/types/CommandMode.html +1 -1
  100. package/docs/types/CommandOutcome.html +1 -1
  101. package/docs/types/IdleState.html +1 -0
  102. package/docs/types/VfsNodeStats.html +1 -1
  103. package/docs/types/VfsNodeType.html +1 -1
  104. package/docs/types/VfsPersistenceMode.html +1 -1
  105. package/docs/types/VfsSnapshotNode.html +1 -1
  106. package/package.json +5 -4
  107. package/scripts/generate-manuals-bundle.mjs +49 -0
  108. package/src/SSHMimic/index.ts +2 -0
  109. package/src/VirtualFileSystem/binaryPack.ts +21 -9
  110. package/src/VirtualFileSystem/index.ts +151 -53
  111. package/src/VirtualFileSystem/internalTypes.ts +20 -4
  112. package/src/VirtualFileSystem/path.ts +1 -1
  113. package/src/VirtualShell/idleManager.ts +133 -0
  114. package/src/VirtualShell/index.ts +48 -0
  115. package/src/commands/man.ts +5 -37
  116. package/src/commands/manuals-bundle.ts +898 -0
  117. package/src/index.ts +2 -0
  118. package/src/modules/linuxRootfs.ts +58 -14
  119. package/src/self-standalone.ts +13 -0
  120. package/src/standalone.ts +23 -0
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import{readFile as Po,unlink as ko,writeFile as Mo}from"node:fs/promises";import*as _s from"node:path";import{basename as Eo}from"node:path";import{stdin as ut,stdout as ot}from"node:process";import{createInterface as Ao}from"node:readline";var Ge={name:"adduser",description:"Add a new user",category:"users",params:["<username>"],run:({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:`adduser: permission denied
2
+ import{readFile as Mo,unlink as ko,writeFile as Io}from"node:fs/promises";import*as Ts from"node:path";import{basename as Ao}from"node:path";import{stdin as ut,stdout as ot}from"node:process";import{createInterface as Oo}from"node:readline";var Ze={name:"adduser",description:"Add a new user",category:"users",params:["<username>"],run:({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:`adduser: permission denied
3
3
  `,exitCode:1};let r=e[0];if(!r)return{stderr:`Usage: adduser <username>
4
4
  `,exitCode:1};if(t.users.listUsers().includes(r))return{stderr:`adduser: user '${r}' already exists
5
5
  `,exitCode:1};let i="",s="new";return{sudoChallenge:{username:r,targetUser:r,commandLine:null,loginShell:!1,prompt:"New password: ",mode:"passwd",onPassword:async(a,l)=>s==="new"?a.length<1?{result:{stderr:`adduser: password cannot be empty
6
6
  `,exitCode:1}}:(i=a,s="retype",{result:null,nextPrompt:"Retype new password: "}):a!==i?{result:{stderr:`adduser: passwords do not match \u2014 user not created
7
7
  `,exitCode:1}}:(await l.users.addUser(r,i),{result:{stdout:`${[`Adding user '${r}' ...`,`Adding new group '${r}' (1001) ...`,`Adding new user '${r}' (1001) with group '${r}' ...`,`Creating home directory '/home/${r}' ...`,`passwd: password set for '${r}'`,"adduser: done."].join(`
8
8
  `)}
9
- `,exitCode:0}})},exitCode:0}}};function Je(n){return Array.isArray(n)?n:[n]}function Yt(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:t.length===2&&t.startsWith("-")&&!t.startsWith("--")&&n.startsWith(t)&&n.length>t.length?{matched:!0,inlineValue:n.slice(t.length)}:{matched:!1,inlineValue:null}}function Is(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),i=[],s=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(s){i.push(a);continue}if(a==="--"){s=!0;continue}let l=!1;for(let c of e){let{matched:u}=Yt(a,c);if(u){l=!0;break}}if(!l){for(let c of r){let u=Yt(a,c);if(u.matched){l=!0,u.inlineValue===null&&o+1<n.length&&(o+=1);break}}l||i.push(a)}}return i}function w(n,t){let e=Je(t);for(let r of n)for(let i of e)if(Yt(r,i).matched)return!0;return!1}function ct(n,t){let e=Je(t);for(let r=0;r<n.length;r+=1){let i=n[r];for(let s of e){let o=Yt(i,s);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function Ct(n,t,e={}){return Is(n,e)[t]}function at(n,t={}){let e=new Set,r=new Map,i=[],s=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let l=0;l<n.length;l+=1){let c=n[l];if(a){i.push(c);continue}if(c==="--"){a=!0;continue}if(s.has(c)){e.add(c);continue}if(o.has(c)){let d=n[l+1];d&&!d.startsWith("-")?(r.set(c,d),l+=1):r.set(c,"");continue}let u=Array.from(o).find(d=>c.startsWith(`${d}=`));if(u){r.set(u,c.slice(u.length+1));continue}i.push(c)}return{flags:e,flagsWithValues:r,positionals:i}}var Ze={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(n.length===0)return{stdout:Object.entries(t.vars).filter(([i])=>i.startsWith("__alias_")).map(([i,s])=>`alias ${i.slice(8)}='${s}'`).join(`
9
+ `,exitCode:0}})},exitCode:0}}};function Qe(n){return Array.isArray(n)?n:[n]}function Qt(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:t.length===2&&t.startsWith("-")&&!t.startsWith("--")&&n.startsWith(t)&&n.length>t.length?{matched:!0,inlineValue:n.slice(t.length)}:{matched:!1,inlineValue:null}}function _s(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),i=[],s=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(s){i.push(a);continue}if(a==="--"){s=!0;continue}let l=!1;for(let c of e){let{matched:u}=Qt(a,c);if(u){l=!0;break}}if(!l){for(let c of r){let u=Qt(a,c);if(u.matched){l=!0,u.inlineValue===null&&o+1<n.length&&(o+=1);break}}l||i.push(a)}}return i}function w(n,t){let e=Qe(t);for(let r of n)for(let i of e)if(Qt(r,i).matched)return!0;return!1}function ct(n,t){let e=Qe(t);for(let r=0;r<n.length;r+=1){let i=n[r];for(let s of e){let o=Qt(i,s);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function Ct(n,t,e={}){return _s(n,e)[t]}function at(n,t={}){let e=new Set,r=new Map,i=[],s=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let l=0;l<n.length;l+=1){let c=n[l];if(a){i.push(c);continue}if(c==="--"){a=!0;continue}if(s.has(c)){e.add(c);continue}if(o.has(c)){let d=n[l+1];d&&!d.startsWith("-")?(r.set(c,d),l+=1):r.set(c,"");continue}let u=Array.from(o).find(d=>c.startsWith(`${d}=`));if(u){r.set(u,c.slice(u.length+1));continue}i.push(c)}return{flags:e,flagsWithValues:r,positionals:i}}var Xe={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(n.length===0)return{stdout:Object.entries(t.vars).filter(([i])=>i.startsWith("__alias_")).map(([i,s])=>`alias ${i.slice(8)}='${s}'`).join(`
10
10
  `)||"",exitCode:0};let e=[];for(let r of n){let i=r.indexOf("=");if(i===-1){let s=t.vars[`__alias_${r}`];if(s)e.push(`alias ${r}='${s}'`);else return{stderr:`alias: ${r}: not found`,exitCode:1}}else{let s=r.slice(0,i),o=r.slice(i+1).replace(/^['"]|['"]$/g,"");t.vars[`__alias_${s}`]=o}}return{stdout:e.join(`
11
- `)||void 0,exitCode:0}}},Ye={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(w(n,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of n)delete t.vars[`__alias_${e}`];return{exitCode:0}}};import*as pt from"node:path";var Rs=["/.virtual-env-js/.auth","/etc/htpasswd"];function k(n,t){return!t||t.trim()===""?n:t.startsWith("~")?pt.posix.normalize(`/home/${t.slice(1)}`):t.startsWith("/")?pt.posix.normalize(t):pt.posix.normalize(pt.posix.join(n,t))}function Vs(n){let t=n.startsWith("/")?pt.posix.normalize(n):pt.posix.normalize(`/${n}`);return Rs.some(e=>t===e||t.startsWith(`${e}/`))}function L(n,t,e){if(n!=="root"&&Vs(t))throw new Error(`${e}: permission denied: ${t}`)}function Qe(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Ds(n,t){let e=Array.from({length:n.length+1},()=>Array(t.length+1).fill(0));for(let r=0;r<=n.length;r+=1)e[r][0]=r;for(let r=0;r<=t.length;r+=1)e[0][r]=r;for(let r=1;r<=n.length;r+=1)for(let i=1;i<=t.length;i+=1){let s=n[r-1]===t[i-1]?0:1;e[r][i]=Math.min(e[r-1][i]+1,e[r][i-1]+1,e[r-1][i-1]+s)}return e[n.length][t.length]}function Xe(n,t,e){let r=k(t,e);if(n.exists(r))return r;let i=pt.posix.dirname(r),s=pt.posix.basename(r),o=n.list(i),a=o.filter(c=>c.toLowerCase()===s.toLowerCase());if(a.length===1)return pt.posix.join(i,a[0]);let l=o.filter(c=>Ds(c.toLowerCase(),s.toLowerCase())<=1);return l.length===1?pt.posix.join(i,l[0]):r}function At(n){return n.packageManager}var tn={name:"apt",aliases:["apt-get"],description:"Package manager",category:"package",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:n,shell:t,authUser:e})=>{let r=At(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let i=n[0]?.toLowerCase(),s=n.slice(1),o=w(s,["-q","--quiet","-qq"]),a=w(s,["--purge"]),l=s.filter(u=>!u.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(i??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
11
+ `)||void 0,exitCode:0}}},tn={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(w(n,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of n)delete t.vars[`__alias_${e}`];return{exitCode:0}}};import*as pt from"node:path";var Ds=["/.virtual-env-js/.auth","/etc/htpasswd"];function N(n,t){return!t||t.trim()===""?n:t.startsWith("~")?pt.posix.normalize(`/home/${t.slice(1)}`):t.startsWith("/")?pt.posix.normalize(t):pt.posix.normalize(pt.posix.join(n,t))}function Us(n){let t=n.startsWith("/")?pt.posix.normalize(n):pt.posix.normalize(`/${n}`);return Ds.some(e=>t===e||t.startsWith(`${e}/`))}function D(n,t,e){if(n!=="root"&&Us(t))throw new Error(`${e}: permission denied: ${t}`)}function en(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Ls(n,t){let e=Array.from({length:n.length+1},()=>Array(t.length+1).fill(0));for(let r=0;r<=n.length;r+=1)e[r][0]=r;for(let r=0;r<=t.length;r+=1)e[0][r]=r;for(let r=1;r<=n.length;r+=1)for(let i=1;i<=t.length;i+=1){let s=n[r-1]===t[i-1]?0:1;e[r][i]=Math.min(e[r-1][i]+1,e[r][i-1]+1,e[r-1][i-1]+s)}return e[n.length][t.length]}function nn(n,t,e){let r=N(t,e);if(n.exists(r))return r;let i=pt.posix.dirname(r),s=pt.posix.basename(r),o=n.list(i),a=o.filter(c=>c.toLowerCase()===s.toLowerCase());if(a.length===1)return pt.posix.join(i,a[0]);let l=o.filter(c=>Ls(c.toLowerCase(),s.toLowerCase())<=1);return l.length===1?pt.posix.join(i,l[0]):r}function At(n){return n.packageManager}var rn={name:"apt",aliases:["apt-get"],description:"Package manager",category:"package",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:n,shell:t,authUser:e})=>{let r=At(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let i=n[0]?.toLowerCase(),s=n.slice(1),o=w(s,["-q","--quiet","-qq"]),a=w(s,["--purge"]),l=s.filter(u=>!u.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(i??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
12
12
  E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(i){case"install":{if(l.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:u,exitCode:d}=r.install(l,{quiet:o});return{stdout:u||void 0,exitCode:d}}case"remove":case"purge":{if(l.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:u,exitCode:d}=r.remove(l,{purge:i==="purge"||a,quiet:o});return{stdout:u||void 0,exitCode:d}}case"update":return{stdout:["Hit:1 fortune://packages.fortune.local aurora InRelease","Hit:2 fortune://security.fortune.local aurora-security InRelease","Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","All packages are up to date."].join(`
13
13
  `),exitCode:0};case"upgrade":return{stdout:["Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","Calculating upgrade... Done","0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."].join(`
14
14
  `),exitCode:0};case"search":{let u=l[0];if(!u)return{stderr:"apt: search requires a term",exitCode:1};let d=r.search(u);return d.length===0?{stdout:`Sorting... Done
@@ -23,23 +23,23 @@ ${p.map(y=>`${y.name}/${y.section} ${y.version} ${y.architecture} [installed]`).
23
23
  `)}`,exitCode:0}}return{stdout:`Listing... Done
24
24
  ${r.listAvailable().map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64`).join(`
25
25
  `)}`,exitCode:0}}default:return{stdout:["Usage: apt [options] command","","Commands:"," install <pkg...> Install packages"," remove <pkg...> Remove packages"," purge <pkg...> Remove packages and config files"," update Refresh package index"," upgrade Upgrade all packages"," search <term> Search in package descriptions"," show <pkg> Show package details"," list [--installed] List packages"].join(`
26
- `),exitCode:0}}}},en={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=At(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),i=n[1];switch(r){case"search":return i?{stdout:e.search(i).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
26
+ `),exitCode:0}}}},sn={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=At(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),i=n[1];switch(r){case"search":return i?{stdout:e.search(i).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
27
27
  `)||"(no results)",exitCode:0}:{stderr:"Need a search term",exitCode:1};case"show":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.show(i);return s?{stdout:s,exitCode:0}:{stderr:`N: Unable to locate package ${i}`,exitCode:100}}case"policy":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.findInRegistry(i);if(!s)return{stderr:`N: Unable to locate package ${i}`,exitCode:100};let o=e.isInstalled(i);return{stdout:[`${i}:`,` Installed: ${o?s.version:"(none)"}`,` Candidate: ${s.version}`," Version table:",` ${s.version} 500`," 500 fortune://packages.fortune.local aurora/main amd64 Packages"].join(`
28
- `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var nn={name:"awk",description:"Pattern scanning and processing language",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({authUser:n,args:t,stdin:e,cwd:r,shell:i})=>{let s=ct(t,["-F"])??" ",o=t.filter(x=>!x.startsWith("-")&&x!==s),a=o[0],l=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let c=e??"";if(l){let x=k(r,l);try{L(n,x,"awk"),c=i.vfs.readFile(x)}catch{return{stderr:`awk: ${l}: No such file or directory`,exitCode:1}}}let u=c.split(`
29
- `);u[u.length-1]===""&&u.pop();let d=[],m=a.trim();if(!m.startsWith("{")&&!m.includes("{"))d.push({pattern:m,action:"print $0"});else{let x=/([^{]*)\{([^}]*)\}/g,E=x.exec(m);for(;E!==null;)d.push({pattern:E[1].trim(),action:E[2].trim()}),E=x.exec(m);d.length===0&&d.push({pattern:"",action:m.replace(/[{}]/g,"").trim()})}let p=[],h=d.find(x=>x.pattern==="BEGIN"),y=d.find(x=>x.pattern==="END"),f=d.filter(x=>x.pattern!=="BEGIN"&&x.pattern!=="END");function S(x){return s===" "?x.trim().split(/\s+/).filter(Boolean):x.split(s)}function F(x,E,N){let b=S(E),M=b.length,V=$=>{if($=$.trim(),$==="NR")return String(N);if($==="NF")return String(M);if($==="$0")return E;if($==="$NF")return b[M-1]??"";if(/^\$\d+$/.test($))return b[parseInt($.slice(1),10)-1]??"";let I=$.replace(/\bNR\b/g,String(N)).replace(/\bNF\b/g,String(M));if(/^[\d\s+\-*/()]+$/.test(I))try{return String(Function(`"use strict"; return (${I});`)())}catch{}return $.replace(/"/g,"")},P=x.split(";").map($=>$.trim()).filter(Boolean);for(let $ of P)if($==="print"||$==="print $0")p.push(E);else if($.startsWith("print ")){let I=$.slice(6).split(/\s*,\s*/);p.push(I.map(V).join(" "))}}function A(x,E,N){if(!x||x==="1")return!0;let b=x.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(b){let P=b[1],$=parseInt(b[2],10);switch(P){case"==":return N===$;case"!=":return N!==$;case">":return N>$;case">=":return N>=$;case"<":return N<$;case"<=":return N<=$}}let M=x.match(/^NR%(\d+)==(\d+)$/);if(M)return N%parseInt(M[1],10)===parseInt(M[2],10);if(x.startsWith("/")&&x.endsWith("/"))try{return new RegExp(x.slice(1,-1)).test(E)}catch{return!1}let V=x.match(/^\$(\d+)~\/(.*)\/$/);if(V){let $=S(E)[parseInt(V[1],10)-1]??"";try{return new RegExp(V[2]).test($)}catch{return!1}}return!1}h&&F(h.action,"",0);for(let x=1;x<=u.length;x++){let E=u[x-1];for(let N of f)A(N.pattern,E,x)&&F(N.action,E,x)}return y&&F(y.action,"",u.length+1),{stdout:p.join(`
28
+ `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var on={name:"awk",description:"Pattern scanning and processing language",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({authUser:n,args:t,stdin:e,cwd:r,shell:i})=>{let s=ct(t,["-F"])??" ",o=t.filter(b=>!b.startsWith("-")&&b!==s),a=o[0],l=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let c=e??"";if(l){let b=N(r,l);try{D(n,b,"awk"),c=i.vfs.readFile(b)}catch{return{stderr:`awk: ${l}: No such file or directory`,exitCode:1}}}let u=c.split(`
29
+ `);u[u.length-1]===""&&u.pop();let d=[],m=a.trim();if(!m.startsWith("{")&&!m.includes("{"))d.push({pattern:m,action:"print $0"});else{let b=/([^{]*)\{([^}]*)\}/g,M=b.exec(m);for(;M!==null;)d.push({pattern:M[1].trim(),action:M[2].trim()}),M=b.exec(m);d.length===0&&d.push({pattern:"",action:m.replace(/[{}]/g,"").trim()})}let p=[],h=d.find(b=>b.pattern==="BEGIN"),y=d.find(b=>b.pattern==="END"),f=d.filter(b=>b.pattern!=="BEGIN"&&b.pattern!=="END");function S(b){return s===" "?b.trim().split(/\s+/).filter(Boolean):b.split(s)}function I(b,M,A){let v=S(M),E=v.length,T=$=>{if($=$.trim(),$==="NR")return String(A);if($==="NF")return String(E);if($==="$0")return M;if($==="$NF")return v[E-1]??"";if(/^\$\d+$/.test($))return v[parseInt($.slice(1),10)-1]??"";let F=$.replace(/\bNR\b/g,String(A)).replace(/\bNF\b/g,String(E));if(/^[\d\s+\-*/()]+$/.test(F))try{return String(Function(`"use strict"; return (${F});`)())}catch{}return $.replace(/"/g,"")},P=b.split(";").map($=>$.trim()).filter(Boolean);for(let $ of P)if($==="print"||$==="print $0")p.push(M);else if($.startsWith("print ")){let F=$.slice(6).split(/\s*,\s*/);p.push(F.map(T).join(" "))}}function k(b,M,A){if(!b||b==="1")return!0;let v=b.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(v){let P=v[1],$=parseInt(v[2],10);switch(P){case"==":return A===$;case"!=":return A!==$;case">":return A>$;case">=":return A>=$;case"<":return A<$;case"<=":return A<=$}}let E=b.match(/^NR%(\d+)==(\d+)$/);if(E)return A%parseInt(E[1],10)===parseInt(E[2],10);if(b.startsWith("/")&&b.endsWith("/"))try{return new RegExp(b.slice(1,-1)).test(M)}catch{return!1}let T=b.match(/^\$(\d+)~\/(.*)\/$/);if(T){let $=S(M)[parseInt(T[1],10)-1]??"";try{return new RegExp(T[2]).test($)}catch{return!1}}return!1}h&&I(h.action,"",0);for(let b=1;b<=u.length;b++){let M=u[b-1];for(let A of f)k(A.pattern,M,b)&&I(A.action,M,b)}return y&&I(y.action,"",u.length+1),{stdout:p.join(`
30
30
  `)+(p.length>0?`
31
- `:""),exitCode:0}}};var rn={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=w(n,["-d","--decode"]),r=t??"";if(e)try{return{stdout:Buffer.from(r.trim(),"base64").toString("utf8"),exitCode:0}}catch{return{stderr:"base64: invalid input",exitCode:1}}return{stdout:Buffer.from(r).toString("base64"),exitCode:0}}};var sn={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-n","--number"]),o=w(r,["-b","--number-nonblank"]),a=r.filter(m=>!m.startsWith("-"));if(a.length===0&&i!==void 0)return{stdout:i,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let l=[];for(let m of a){let p=Xe(t.vfs,e,m);L(n,p,"cat"),l.push(t.vfs.readFile(p))}let c=l.join("");if(!s&&!o)return{stdout:c,exitCode:0};let u=1;return{stdout:c.split(`
31
+ `:""),exitCode:0}}};var an={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=w(n,["-d","--decode"]),r=t??"";if(e)try{return{stdout:Buffer.from(r.trim(),"base64").toString("utf8"),exitCode:0}}catch{return{stderr:"base64: invalid input",exitCode:1}}return{stdout:Buffer.from(r).toString("base64"),exitCode:0}}};var ln={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-n","--number"]),o=w(r,["-b","--number-nonblank"]),a=r.filter(m=>!m.startsWith("-"));if(a.length===0&&i!==void 0)return{stdout:i,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let l=[];for(let m of a){let p=nn(t.vfs,e,m);D(n,p,"cat"),l.push(t.vfs.readFile(p))}let c=l.join("");if(!s&&!o)return{stdout:c,exitCode:0};let u=1;return{stdout:c.split(`
32
32
  `).map(m=>o&&m.trim()===""?m:`${String(u++).padStart(6)} ${m}`).join(`
33
- `),exitCode:0}}};var on={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=k(e,r[0]??"~");return L(n,i,"cd"),t.vfs.stat(i).type!=="directory"?{stderr:`cd: not a directory: ${i}`,exitCode:1}:{nextCwd:i,exitCode:0}}};function Ls(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),i=n;for(let s of r){let o=s.trim().match(e);if(!o)return null;let[,a="a",l,c=""]=o,u=a===""||a==="a"?["u","g","o"]:a.split(""),d={u:{r:256,w:128,x:64},g:{r:32,w:16,x:8},o:{r:4,w:2,x:1}};for(let m of u)for(let p of c.split("")){let h=d[m]?.[p];if(h!==void 0){if(l==="+")i|=h;else if(l==="-")i&=~h;else if(l==="="){let y=Object.values(d[m]??{}).reduce((f,S)=>f|S,0);i=i&~y|h}}}}return i}var an={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[i,s]=r;if(!i||!s)return{stderr:"chmod: missing operand",exitCode:1};let o=k(e,s);try{if(L(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${s}: No such file or directory`,exitCode:1};let a,l=parseInt(i,8);if(!Number.isNaN(l)&&/^[0-7]+$/.test(i))a=l;else{let c=t.vfs.stat(o).mode,u=Ls(c,i);if(u===null)return{stderr:`chmod: invalid mode: ${i}`,exitCode:1};a=u}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var ln={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var cn={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-r","-R","--recursive"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let l=k(e,o),c=k(e,a);try{if(L(n,l,"cp"),L(n,c,"cp"),!t.vfs.exists(l))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(l).type==="directory"){if(!i)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let d=(p,h)=>{t.vfs.mkdir(h,493);for(let y of t.vfs.list(p)){let f=`${p}/${y}`,S=`${h}/${y}`;if(t.vfs.stat(f).type==="directory")d(f,S);else{let A=t.vfs.readFileRaw(f);t.writeFileAsUser(n,S,A)}}},m=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${o.split("/").pop()}`:c;d(l,m)}else{let d=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${o.split("/").pop()}`:c,m=t.vfs.readFileRaw(l);t.writeFileAsUser(n,d,m)}return{exitCode:0}}catch(u){return{stderr:`cp: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}};var un={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=at(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(w(e,["--help","-h"]))return{stdout:["Usage: curl [options] <url>"," -o, --output <file> Write to file"," -X, --request <method> HTTP method"," -d, --data <data> POST data"," -H, --header <hdr> Extra header"," -s, --silent Silent mode"," -I, --head Fetch headers only"," -L, --location Follow redirects"," -v, --verbose Verbose"].join(`
34
- `),exitCode:0};let o=s[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=i.get("-o")??i.get("--output")??null,l=(i.get("-X")??i.get("--request")??"GET").toUpperCase(),c=i.get("-d")??i.get("--data")??null,u=i.get("-H")??i.get("--header")??null,d=w(e,["-s","--silent"]),m=w(e,["-I","--head"]),p=w(e,["-L","--location"]),h=w(e,["-v","--verbose"]),y={"User-Agent":"curl/7.88.1"};if(u){let E=u.indexOf(":");E!==-1&&(y[u.slice(0,E).trim()]=u.slice(E+1).trim())}let f=c&&l==="GET"?"POST":l,S={method:f,headers:y,redirect:p?"follow":"manual"};c&&(y["Content-Type"]??="application/x-www-form-urlencoded",S.body=c);let F=[];h&&(F.push(`* Trying ${o}...`,"* Connected"),F.push(`> ${f} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let A;try{let E=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;A=await fetch(E,S)}catch(E){return{stderr:`curl: (6) Could not resolve host: ${E instanceof Error?E.message:String(E)}`,exitCode:6}}if(h&&F.push(`< HTTP/1.1 ${A.status} ${A.statusText}`),m){let E=[`HTTP/1.1 ${A.status} ${A.statusText}`];for(let[N,b]of A.headers.entries())E.push(`${N}: ${b}`);return{stdout:`${E.join(`\r
33
+ `),exitCode:0}}};var cn={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=N(e,r[0]??"~");return D(n,i,"cd"),t.vfs.stat(i).type!=="directory"?{stderr:`cd: not a directory: ${i}`,exitCode:1}:{nextCwd:i,exitCode:0}}};function Vs(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),i=n;for(let s of r){let o=s.trim().match(e);if(!o)return null;let[,a="a",l,c=""]=o,u=a===""||a==="a"?["u","g","o"]:a.split(""),d={u:{r:256,w:128,x:64},g:{r:32,w:16,x:8},o:{r:4,w:2,x:1}};for(let m of u)for(let p of c.split("")){let h=d[m]?.[p];if(h!==void 0){if(l==="+")i|=h;else if(l==="-")i&=~h;else if(l==="="){let y=Object.values(d[m]??{}).reduce((f,S)=>f|S,0);i=i&~y|h}}}}return i}var un={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[i,s]=r;if(!i||!s)return{stderr:"chmod: missing operand",exitCode:1};let o=N(e,s);try{if(D(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${s}: No such file or directory`,exitCode:1};let a,l=parseInt(i,8);if(!Number.isNaN(l)&&/^[0-7]+$/.test(i))a=l;else{let c=t.vfs.stat(o).mode,u=Vs(c,i);if(u===null)return{stderr:`chmod: invalid mode: ${i}`,exitCode:1};a=u}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var dn={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var mn={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-r","-R","--recursive"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let l=N(e,o),c=N(e,a);try{if(D(n,l,"cp"),D(n,c,"cp"),!t.vfs.exists(l))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(l).type==="directory"){if(!i)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let d=(p,h)=>{t.vfs.mkdir(h,493);for(let y of t.vfs.list(p)){let f=`${p}/${y}`,S=`${h}/${y}`;if(t.vfs.stat(f).type==="directory")d(f,S);else{let k=t.vfs.readFileRaw(f);t.writeFileAsUser(n,S,k)}}},m=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${o.split("/").pop()}`:c;d(l,m)}else{let d=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${o.split("/").pop()}`:c,m=t.vfs.readFileRaw(l);t.writeFileAsUser(n,d,m)}return{exitCode:0}}catch(u){return{stderr:`cp: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}};var pn={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=at(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(w(e,["--help","-h"]))return{stdout:["Usage: curl [options] <url>"," -o, --output <file> Write to file"," -X, --request <method> HTTP method"," -d, --data <data> POST data"," -H, --header <hdr> Extra header"," -s, --silent Silent mode"," -I, --head Fetch headers only"," -L, --location Follow redirects"," -v, --verbose Verbose"].join(`
34
+ `),exitCode:0};let o=s[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=i.get("-o")??i.get("--output")??null,l=(i.get("-X")??i.get("--request")??"GET").toUpperCase(),c=i.get("-d")??i.get("--data")??null,u=i.get("-H")??i.get("--header")??null,d=w(e,["-s","--silent"]),m=w(e,["-I","--head"]),p=w(e,["-L","--location"]),h=w(e,["-v","--verbose"]),y={"User-Agent":"curl/7.88.1"};if(u){let M=u.indexOf(":");M!==-1&&(y[u.slice(0,M).trim()]=u.slice(M+1).trim())}let f=c&&l==="GET"?"POST":l,S={method:f,headers:y,redirect:p?"follow":"manual"};c&&(y["Content-Type"]??="application/x-www-form-urlencoded",S.body=c);let I=[];h&&(I.push(`* Trying ${o}...`,"* Connected"),I.push(`> ${f} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let k;try{let M=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;k=await fetch(M,S)}catch(M){return{stderr:`curl: (6) Could not resolve host: ${M instanceof Error?M.message:String(M)}`,exitCode:6}}if(h&&I.push(`< HTTP/1.1 ${k.status} ${k.statusText}`),m){let M=[`HTTP/1.1 ${k.status} ${k.statusText}`];for(let[A,v]of k.headers.entries())M.push(`${A}: ${v}`);return{stdout:`${M.join(`\r
35
35
  `)}\r
36
- `,exitCode:0}}let x;try{x=await A.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let E=k(t,a);return L(n,E,"curl"),r.writeFileAsUser(n,E,x),d||F.push(` % Total % Received
37
- 100 ${x.length} 100 ${x.length}`),{stderr:F.join(`
38
- `)||void 0,exitCode:A.ok?0:22}}return{stdout:x,stderr:F.length>0?F.join(`
39
- `):void 0,exitCode:A.ok?0:22}}};var dn={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=ct(n,["-d"])??" ",i=(ct(n,["-f"])??"1").split(",").map(a=>{let[l,c]=a.split("-").map(Number);return c!==void 0?{from:(l??1)-1,to:c-1}:{from:(l??1)-1,to:(l??1)-1}});return{stdout:(t??"").split(`
36
+ `,exitCode:0}}let b;try{b=await k.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let M=N(t,a);return D(n,M,"curl"),r.writeFileAsUser(n,M,b),d||I.push(` % Total % Received
37
+ 100 ${b.length} 100 ${b.length}`),{stderr:I.join(`
38
+ `)||void 0,exitCode:k.ok?0:22}}return{stdout:b,stderr:I.length>0?I.join(`
39
+ `):void 0,exitCode:k.ok?0:22}}};var fn={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=ct(n,["-d"])??" ",i=(ct(n,["-f"])??"1").split(",").map(a=>{let[l,c]=a.split("-").map(Number);return c!==void 0?{from:(l??1)-1,to:c-1}:{from:(l??1)-1,to:(l??1)-1}});return{stdout:(t??"").split(`
40
40
  `).map(a=>{let l=a.split(e),c=[];for(let u of i)for(let d=u.from;d<=Math.min(u.to,l.length-1);d++)c.push(l[d]??"");return c.join(e)}).join(`
41
- `),exitCode:0}}};var mn={name:"date",description:"Print current date and time",category:"system",params:["[+format]"],run:({args:n})=>{let t=new Date,e=n[0];return e?.startsWith("+")?{stdout:e.slice(1).replace("%Y",String(t.getFullYear())).replace("%m",String(t.getMonth()+1).padStart(2,"0")).replace("%d",String(t.getDate()).padStart(2,"0")).replace("%H",String(t.getHours()).padStart(2,"0")).replace("%M",String(t.getMinutes()).padStart(2,"0")).replace("%S",String(t.getSeconds()).padStart(2,"0")).replace("%s",String(Math.floor(t.getTime()/1e3))),exitCode:0}:{stdout:t.toString(),exitCode:0}}};var pn={name:"declare",aliases:["local","typeset"],description:"Declare variables and give them attributes",category:"shell",params:["[-i] [-r] [-x] [-a] [name[=value]...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=w(n,["-i"]),r=w(n,["-r"]),i=w(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([l,c])=>`declare -- ${l}="${c}"`).join(`
42
- `),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let l=a.indexOf("=");if(l===-1)a in t.vars||(t.vars[a]="");else{let c=a.slice(0,l),u=a.slice(l+1);if(e){let d=parseInt(u,10);u=Number.isNaN(d)?"0":String(d)}t.vars[c]=u}}return{exitCode:0}}};var fn={name:"deluser",description:"Delete a user",category:"users",params:["[-f] <username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:`deluser: permission denied
41
+ `),exitCode:0}}};var hn={name:"date",description:"Print current date and time",category:"system",params:["[+format]"],run:({args:n})=>{let t=new Date,e=n[0];return e?.startsWith("+")?{stdout:e.slice(1).replace("%Y",String(t.getFullYear())).replace("%m",String(t.getMonth()+1).padStart(2,"0")).replace("%d",String(t.getDate()).padStart(2,"0")).replace("%H",String(t.getHours()).padStart(2,"0")).replace("%M",String(t.getMinutes()).padStart(2,"0")).replace("%S",String(t.getSeconds()).padStart(2,"0")).replace("%s",String(Math.floor(t.getTime()/1e3))),exitCode:0}:{stdout:t.toString(),exitCode:0}}};var gn={name:"declare",aliases:["local","typeset"],description:"Declare variables and give them attributes",category:"shell",params:["[-i] [-r] [-x] [-a] [name[=value]...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=w(n,["-i"]),r=w(n,["-r"]),i=w(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([l,c])=>`declare -- ${l}="${c}"`).join(`
42
+ `),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let l=a.indexOf("=");if(l===-1)a in t.vars||(t.vars[a]="");else{let c=a.slice(0,l),u=a.slice(l+1);if(e){let d=parseInt(u,10);u=Number.isNaN(d)?"0":String(d)}t.vars[c]=u}}return{exitCode:0}}};var yn={name:"deluser",description:"Delete a user",category:"users",params:["[-f] <username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:`deluser: permission denied
43
43
  `,exitCode:1};let r=t.includes("-f")||t.includes("--force")||t.includes("-y"),i=t.find(o=>!o.startsWith("-"));if(!i)return{stderr:`Usage: deluser [-f] <username>
44
44
  `,exitCode:1};if(!e.users.listUsers().includes(i))return{stderr:`deluser: user '${i}' does not exist
45
45
  `,exitCode:1};if(i==="root")return{stderr:`deluser: cannot remove the root account
@@ -49,92 +49,902 @@ deluser: done.
49
49
  `,exitCode:1}}:(await a.users.deleteUser(i),{result:{stdout:`Removing user '${i}' ...
50
50
  deluser: done.
51
51
  `,exitCode:0}});return{sudoChallenge:{username:i,targetUser:i,commandLine:null,loginShell:!1,prompt:`Warning: deleting user '${i}'.
52
- Type the username to confirm: `,mode:"confirm",onPassword:s},exitCode:0}}};var hn={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:n})=>{let e=(n.vfs.getUsageBytes()/1024).toFixed(0),r="1048576",i=String(Number(r)-Number(e)),s=Math.round(Number(e)/Number(r)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${r.padStart(9)} ${e.padStart(7)} ${i.padStart(9)} ${s}% /`;return{stdout:`${o}
53
- ${a}`,exitCode:0}}};var gn={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,i]=e;if(!r||!i)return{stderr:"diff: missing operand",exitCode:1};let s=k(t,r),o=k(t,i),a,l;try{a=n.vfs.readFile(s).split(`
52
+ Type the username to confirm: `,mode:"confirm",onPassword:s},exitCode:0}}};var Sn={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:n})=>{let e=(n.vfs.getUsageBytes()/1024).toFixed(0),r="1048576",i=String(Number(r)-Number(e)),s=Math.round(Number(e)/Number(r)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${r.padStart(9)} ${e.padStart(7)} ${i.padStart(9)} ${s}% /`;return{stdout:`${o}
53
+ ${a}`,exitCode:0}}};var wn={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,i]=e;if(!r||!i)return{stderr:"diff: missing operand",exitCode:1};let s=N(t,r),o=N(t,i),a,l;try{a=n.vfs.readFile(s).split(`
54
54
  `)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{l=n.vfs.readFile(o).split(`
55
55
  `)}catch{return{stderr:`diff: ${i}: No such file or directory`,exitCode:2}}let c=[],u=Math.max(a.length,l.length);for(let d=0;d<u;d++){let m=a[d],p=l[d];m!==p&&(m!==void 0&&c.push(`< ${m}`),p!==void 0&&c.push(`> ${p}`))}return{stdout:c.join(`
56
- `),exitCode:c.length>0?1:0}}};var yn={name:"dpkg",description:"Debian package manager low-level tool",category:"package",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:n,authUser:t,shell:e})=>{let r=At(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let i=w(n,["-l","--list"]),s=w(n,["-s","--status"]),o=w(n,["-L","--listfiles"]),a=w(n,["-r","--remove"]),l=w(n,["-P","--purge"]),{positionals:c}=at(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(i){let u=r.listInstalled();if(u.length===0)return{stdout:["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================","(no packages installed)"].join(`
56
+ `),exitCode:c.length>0?1:0}}};var bn={name:"dpkg",description:"Debian package manager low-level tool",category:"package",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:n,authUser:t,shell:e})=>{let r=At(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let i=w(n,["-l","--list"]),s=w(n,["-s","--status"]),o=w(n,["-L","--listfiles"]),a=w(n,["-r","--remove"]),l=w(n,["-P","--purge"]),{positionals:c}=at(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(i){let u=r.listInstalled();if(u.length===0)return{stdout:["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================","(no packages installed)"].join(`
57
57
  `),exitCode:0};let d=["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================"],m=u.map(p=>{let h=p.name.padEnd(14).slice(0,14),y=p.version.padEnd(15).slice(0,15),f=p.architecture.padEnd(12).slice(0,12),S=(p.description||"").slice(0,40);return`ii ${h} ${y} ${f} ${S}`});return{stdout:[...d,...m].join(`
58
58
  `),exitCode:0}}if(s){let u=c[0];if(!u)return{stderr:"dpkg: -s needs a package name",exitCode:1};let d=r.show(u);return d?{stdout:d,exitCode:0}:{stderr:`dpkg-query: package '${u}' is not installed and no information is available`,exitCode:1}}if(o){let u=c[0];if(!u)return{stderr:"dpkg: -L needs a package name",exitCode:1};let d=r.listInstalled().find(m=>m.name===u);return d?d.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:d.files.join(`
59
59
  `),exitCode:0}:{stderr:`dpkg-query: package '${u}' is not installed`,exitCode:1}}if(a||l){if(t!=="root")return{stderr:"dpkg: error: requested operation requires superuser privilege",exitCode:2};if(c.length===0)return{stderr:"dpkg: error: need an action option",exitCode:2};let{output:u,exitCode:d}=r.remove(c,{purge:l});return{stdout:u||void 0,exitCode:d}}return{stdout:["Usage: dpkg [<option>...] <command>","","Commands:"," -l, --list List packages matching given pattern"," -s, --status <pkg>... Report status of specified package"," -L, --listfiles <pkg>... List files owned by package"," -r, --remove <pkg>... Remove <pkg> but leave its configuration"," -P, --purge <pkg>... Remove <pkg> and its configuration"].join(`
60
- `),exitCode:0}}},Sn={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=At(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=w(n,["-l"]),i=w(n,["-W","--show"]),{positionals:s}=at(n,{flags:["-l","-W","--show"]});if(r||i){let o=e.listInstalled(),a=s[0],l=a?o.filter(u=>u.name.includes(a)):o;return i?{stdout:l.map(u=>`${u.name} ${u.version}`).join(`
60
+ `),exitCode:0}}},vn={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=At(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=w(n,["-l"]),i=w(n,["-W","--show"]),{positionals:s}=at(n,{flags:["-l","-W","--show"]});if(r||i){let o=e.listInstalled(),a=s[0],l=a?o.filter(u=>u.name.includes(a)):o;return i?{stdout:l.map(u=>`${u.name} ${u.version}`).join(`
61
61
  `),exitCode:0}:{stdout:l.map(u=>{let d=u.name.padEnd(14).slice(0,14),m=u.version.padEnd(15).slice(0,15);return`ii ${d} ${m} amd64 ${(u.description||"").slice(0,40)}`}).join(`
62
- `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var wn={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=w(e,["-h"]),i=w(e,["-s"]),s=e.find(u=>!u.startsWith("-"))??".",o=k(t,s),a=u=>r?`${(u/1024).toFixed(1)}K`:String(Math.ceil(u/1024));if(!n.vfs.exists(o))return{stderr:`du: ${s}: No such file or directory`,exitCode:1};if(i||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${s}`,exitCode:0};let l=[],c=(u,d)=>{let m=0;for(let p of n.vfs.list(u)){let h=`${u}/${p}`,y=`${d}/${p}`,f=n.vfs.stat(h);f.type==="directory"?m+=c(h,y):(m+=f.size,i||l.push(`${a(f.size)} ${y}`))}return l.push(`${a(m)} ${d}`),m};return c(o,s),{stdout:l.join(`
63
- `),exitCode:0}}};function zs(n,t){let e=[],r=0;for(;r<n.length;){let i=n[r];if(/\s/.test(i)){r++;continue}if(i==="+"){e.push({type:"plus"}),r++;continue}if(i==="-"){e.push({type:"minus"}),r++;continue}if(i==="*"){if(n[r+1]==="*"){e.push({type:"pow"}),r+=2;continue}e.push({type:"mul"}),r++;continue}if(i==="/"){e.push({type:"div"}),r++;continue}if(i==="%"){e.push({type:"mod"}),r++;continue}if(i==="("){e.push({type:"lparen"}),r++;continue}if(i===")"){e.push({type:"rparen"}),r++;continue}if(/\d/.test(i)){let s=r+1;for(;s<n.length&&/\d/.test(n[s]);)s++;e.push({type:"number",value:Number(n.slice(r,s))}),r=s;continue}if(/[A-Za-z_]/.test(i)){let s=r+1;for(;s<n.length&&/[A-Za-z0-9_]/.test(n[s]);)s++;let o=n.slice(r,s),a=t[o],l=a===void 0||a===""?0:Number(a);e.push({type:"number",value:Number.isFinite(l)?l:0}),r=s;continue}return[]}return e}function Ce(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=zs(e,t);if(r.length===0)return NaN;let i=0,s=()=>r[i],o=()=>r[i++],a=()=>{let p=o();if(!p)return NaN;if(p.type==="number")return p.value;if(p.type==="lparen"){let h=d();return r[i]?.type!=="rparen"?NaN:(i++,h)}return NaN},l=()=>{let p=s();return p?.type==="plus"?(o(),l()):p?.type==="minus"?(o(),-l()):a()},c=()=>{let p=l();for(;s()?.type==="pow";){o();let h=l();p=p**h}return p},u=()=>{let p=c();for(;;){let h=s();if(h?.type==="mul"){o(),p*=c();continue}if(h?.type==="div"){o();let y=c();p=y===0?NaN:p/y;continue}if(h?.type==="mod"){o();let y=c();p=y===0?NaN:p%y;continue}return p}},d=()=>{let p=u();for(;;){let h=s();if(h?.type==="plus"){o(),p+=u();continue}if(h?.type==="minus"){o(),p-=u();continue}return p}},m=d();return!Number.isFinite(m)||i!==r.length?NaN:Math.trunc(m)}function Ts(n,t){let e=[],r=0;for(;r<n.length;){let i=n.indexOf("'",r);if(i===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,i)));let s=n.indexOf("'",i+1);if(s===-1){e.push(n.slice(i));break}e.push(n.slice(i,s+1)),r=s+1}return e.join("")}function Xt(n){function r(i,s){if(s>8)return[i];let o=0,a=-1;for(let l=0;l<i.length;l++){let c=i[l];if(c==="{"&&i[l-1]!=="$")o===0&&(a=l),o++;else if(c==="}"&&(o--,o===0&&a!==-1)){let u=i.slice(0,a),d=i.slice(a+1,l),m=i.slice(l+1),p=d.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||d.match(/^([a-z])\.\.([a-z])$/);if(p){let S=[];if(/\d/.test(p[1])){let x=parseInt(p[1],10),E=parseInt(p[2],10),N=p[3]?parseInt(p[3],10):1,b=x<=E?N:-N;for(let M=x;x<=E?M<=E:M>=E;M+=b)S.push(String(M))}else{let x=p[1].charCodeAt(0),E=p[2].charCodeAt(0),N=x<=E?1:-1;for(let b=x;x<=E?b<=E:b>=E;b+=N)S.push(String.fromCharCode(b))}let F=S.map(x=>`${u}${x}${m}`),A=[];for(let x of F)if(A.push(...r(x,s+1)),A.length>256)return[i];return A}let h=[],y="",f=0;for(let S of d)S==="{"?(f++,y+=S):S==="}"?(f--,y+=S):S===","&&f===0?(h.push(y),y=""):y+=S;if(h.push(y),h.length>1){let S=[];for(let F of h)if(S.push(...r(`${u}${F}${m}`,s+1)),S.length>256)return[i];return S}break}}return[i]}return r(n,0)}function Us(n,t){let e="",r=0;for(;r<n.length;){if(n[r]==="$"&&n[r+1]==="("&&n[r+2]==="("){let i=r+3,s=0;for(;i<n.length;){let o=n[i];if(o==="(")s++;else if(o===")"){if(s>0)s--;else if(n[i+1]===")"){let a=n.slice(r+3,i),l=Ce(a,t);e+=Number.isNaN(l)?"0":String(l),r=i+2;break}}i++}if(i>=n.length){e+=n.slice(r);break}continue}e+=n[r],r++}return e}function Qt(n,t,e=0,r){let i=r??t.HOME??"/home/user";return Ts(n,s=>{let o=s;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,l,c)=>`${l}${i}${c}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=Us(o,t),o=o.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,l)=>String((t[l]??"").length)),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,l,c)=>t[l]!==void 0&&t[l]!==""?t[l]:c),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,l,c)=>((t[l]===void 0||t[l]==="")&&(t[l]=c),t[l])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,l,c)=>t[l]!==void 0&&t[l]!==""?c:""),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,l)=>t[l]??""),o=o.replace(/\$([A-Za-z_][A-Za-z0-9_]*|\d+)/g,(a,l)=>t[l]??""),o})}async function te(n,t,e,r){let i="__shellExpandDepth",o=Number(t[i]??"0");if(o>=8)return Qt(n,t,e);t[i]=String(o+1);try{if(n.includes("$(")){let a="",l=!1,c=0;for(;c<n.length;){let u=n[c];if(u==="'"&&!l){l=!0,a+=u,c++;continue}if(u==="'"&&l){l=!1,a+=u,c++;continue}if(!l&&u==="$"&&n[c+1]==="("){if(n[c+2]==="("){a+=u,c++;continue}let d=0,m=c+1;for(;m<n.length;){if(n[m]==="(")d++;else if(n[m]===")"&&(d--,d===0))break;m++}let p=n.slice(c+2,m).trim(),h=(await r(p)).replace(/\n$/,"");a+=h,c=m+1;continue}a+=u,c++}n=a}return Qt(n,t,e)}finally{o<=0?delete t[i]:t[i]=String(o)}}function Bs(n){return n.replace(/\\n/g,`
64
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\a/g,"\x07").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\v/g,"\v").replace(/\\0(\d{1,3})/g,(t,e)=>String.fromCharCode(parseInt(e,8)))}var xn={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:i}=at(n,{flags:["-n","-e","-E"]}),s=r.has("-n"),o=r.has("-e"),a=i.length>0?i.join(" "):t??"",l=Qt(a,e?.vars??{},e?.lastExitCode??0),c=o?Bs(l):l;return{stdout:s?c:`${c}
65
- `,exitCode:0}}};var bn={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:n,authUser:t})=>{let e={...n.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([r,i])=>`${r}=${i}`).join(`
66
- `),exitCode:0}}};var vn={name:"exit",aliases:["bye"],description:"Exit the shell session",category:"shell",params:["[code]"],run:({args:n})=>({closeSession:!0,exitCode:parseInt(n[0]??"0",10)||0})};var Cn={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0||n.length===1&&n[0]==="-p"){let e=Object.entries(t.vars).filter(([r])=>r&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)).map(([r,i])=>`declare -x ${r}="${i}"`).join(`
62
+ `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var xn={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=w(e,["-h"]),i=w(e,["-s"]),s=e.find(u=>!u.startsWith("-"))??".",o=N(t,s),a=u=>r?`${(u/1024).toFixed(1)}K`:String(Math.ceil(u/1024));if(!n.vfs.exists(o))return{stderr:`du: ${s}: No such file or directory`,exitCode:1};if(i||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${s}`,exitCode:0};let l=[],c=(u,d)=>{let m=0;for(let p of n.vfs.list(u)){let h=`${u}/${p}`,y=`${d}/${p}`,f=n.vfs.stat(h);f.type==="directory"?m+=c(h,y):(m+=f.size,i||l.push(`${a(f.size)} ${y}`))}return l.push(`${a(m)} ${d}`),m};return c(o,s),{stdout:l.join(`
63
+ `),exitCode:0}}};function zs(n,t){let e=[],r=0;for(;r<n.length;){let i=n[r];if(/\s/.test(i)){r++;continue}if(i==="+"){e.push({type:"plus"}),r++;continue}if(i==="-"){e.push({type:"minus"}),r++;continue}if(i==="*"){if(n[r+1]==="*"){e.push({type:"pow"}),r+=2;continue}e.push({type:"mul"}),r++;continue}if(i==="/"){e.push({type:"div"}),r++;continue}if(i==="%"){e.push({type:"mod"}),r++;continue}if(i==="("){e.push({type:"lparen"}),r++;continue}if(i===")"){e.push({type:"rparen"}),r++;continue}if(/\d/.test(i)){let s=r+1;for(;s<n.length&&/\d/.test(n[s]);)s++;e.push({type:"number",value:Number(n.slice(r,s))}),r=s;continue}if(/[A-Za-z_]/.test(i)){let s=r+1;for(;s<n.length&&/[A-Za-z0-9_]/.test(n[s]);)s++;let o=n.slice(r,s),a=t[o],l=a===void 0||a===""?0:Number(a);e.push({type:"number",value:Number.isFinite(l)?l:0}),r=s;continue}return[]}return e}function Pe(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=zs(e,t);if(r.length===0)return NaN;let i=0,s=()=>r[i],o=()=>r[i++],a=()=>{let p=o();if(!p)return NaN;if(p.type==="number")return p.value;if(p.type==="lparen"){let h=d();return r[i]?.type!=="rparen"?NaN:(i++,h)}return NaN},l=()=>{let p=s();return p?.type==="plus"?(o(),l()):p?.type==="minus"?(o(),-l()):a()},c=()=>{let p=l();for(;s()?.type==="pow";){o();let h=l();p=p**h}return p},u=()=>{let p=c();for(;;){let h=s();if(h?.type==="mul"){o(),p*=c();continue}if(h?.type==="div"){o();let y=c();p=y===0?NaN:p/y;continue}if(h?.type==="mod"){o();let y=c();p=y===0?NaN:p%y;continue}return p}},d=()=>{let p=u();for(;;){let h=s();if(h?.type==="plus"){o(),p+=u();continue}if(h?.type==="minus"){o(),p-=u();continue}return p}},m=d();return!Number.isFinite(m)||i!==r.length?NaN:Math.trunc(m)}function Bs(n,t){let e=[],r=0;for(;r<n.length;){let i=n.indexOf("'",r);if(i===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,i)));let s=n.indexOf("'",i+1);if(s===-1){e.push(n.slice(i));break}e.push(n.slice(i,s+1)),r=s+1}return e.join("")}function te(n){function r(i,s){if(s>8)return[i];let o=0,a=-1;for(let l=0;l<i.length;l++){let c=i[l];if(c==="{"&&i[l-1]!=="$")o===0&&(a=l),o++;else if(c==="}"&&(o--,o===0&&a!==-1)){let u=i.slice(0,a),d=i.slice(a+1,l),m=i.slice(l+1),p=d.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||d.match(/^([a-z])\.\.([a-z])$/);if(p){let S=[];if(/\d/.test(p[1])){let b=parseInt(p[1],10),M=parseInt(p[2],10),A=p[3]?parseInt(p[3],10):1,v=b<=M?A:-A;for(let E=b;b<=M?E<=M:E>=M;E+=v)S.push(String(E))}else{let b=p[1].charCodeAt(0),M=p[2].charCodeAt(0),A=b<=M?1:-1;for(let v=b;b<=M?v<=M:v>=M;v+=A)S.push(String.fromCharCode(v))}let I=S.map(b=>`${u}${b}${m}`),k=[];for(let b of I)if(k.push(...r(b,s+1)),k.length>256)return[i];return k}let h=[],y="",f=0;for(let S of d)S==="{"?(f++,y+=S):S==="}"?(f--,y+=S):S===","&&f===0?(h.push(y),y=""):y+=S;if(h.push(y),h.length>1){let S=[];for(let I of h)if(S.push(...r(`${u}${I}${m}`,s+1)),S.length>256)return[i];return S}break}}return[i]}return r(n,0)}function Ws(n,t){let e="",r=0;for(;r<n.length;){if(n[r]==="$"&&n[r+1]==="("&&n[r+2]==="("){let i=r+3,s=0;for(;i<n.length;){let o=n[i];if(o==="(")s++;else if(o===")"){if(s>0)s--;else if(n[i+1]===")"){let a=n.slice(r+3,i),l=Pe(a,t);e+=Number.isNaN(l)?"0":String(l),r=i+2;break}}i++}if(i>=n.length){e+=n.slice(r);break}continue}e+=n[r],r++}return e}function Xt(n,t,e=0,r){let i=r??t.HOME??"/home/user";return Bs(n,s=>{let o=s;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,l,c)=>`${l}${i}${c}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=Ws(o,t),o=o.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,l)=>String((t[l]??"").length)),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,l,c)=>t[l]!==void 0&&t[l]!==""?t[l]:c),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,l,c)=>((t[l]===void 0||t[l]==="")&&(t[l]=c),t[l])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,l,c)=>t[l]!==void 0&&t[l]!==""?c:""),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,l)=>t[l]??""),o=o.replace(/\$([A-Za-z_][A-Za-z0-9_]*|\d+)/g,(a,l)=>t[l]??""),o})}async function ee(n,t,e,r){let i="__shellExpandDepth",o=Number(t[i]??"0");if(o>=8)return Xt(n,t,e);t[i]=String(o+1);try{if(n.includes("$(")){let a="",l=!1,c=0;for(;c<n.length;){let u=n[c];if(u==="'"&&!l){l=!0,a+=u,c++;continue}if(u==="'"&&l){l=!1,a+=u,c++;continue}if(!l&&u==="$"&&n[c+1]==="("){if(n[c+2]==="("){a+=u,c++;continue}let d=0,m=c+1;for(;m<n.length;){if(n[m]==="(")d++;else if(n[m]===")"&&(d--,d===0))break;m++}let p=n.slice(c+2,m).trim(),h=(await r(p)).replace(/\n$/,"");a+=h,c=m+1;continue}a+=u,c++}n=a}return Xt(n,t,e)}finally{o<=0?delete t[i]:t[i]=String(o)}}function js(n){return n.replace(/\\n/g,`
64
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\a/g,"\x07").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\v/g,"\v").replace(/\\0(\d{1,3})/g,(t,e)=>String.fromCharCode(parseInt(e,8)))}var Cn={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:i}=at(n,{flags:["-n","-e","-E"]}),s=r.has("-n"),o=r.has("-e"),a=i.length>0?i.join(" "):t??"",l=Xt(a,e?.vars??{},e?.lastExitCode??0),c=o?js(l):l;return{stdout:s?c:`${c}
65
+ `,exitCode:0}}};var $n={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:n,authUser:t})=>{let e={...n.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([r,i])=>`${r}=${i}`).join(`
66
+ `),exitCode:0}}};var Pn={name:"exit",aliases:["bye"],description:"Exit the shell session",category:"shell",params:["[code]"],run:({args:n})=>({closeSession:!0,exitCode:parseInt(n[0]??"0",10)||0})};var Nn={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0||n.length===1&&n[0]==="-p"){let e=Object.entries(t.vars).filter(([r])=>r&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)).map(([r,i])=>`declare -x ${r}="${i}"`).join(`
67
67
  `);return{stdout:e?`${e}
68
- `:"",exitCode:0}}for(let e of n.filter(r=>r!=="-p"))if(e.includes("=")){let r=e.indexOf("="),i=e.slice(0,r),s=e.slice(r+1);t.vars[i]=s}return{exitCode:0}}};var $n={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=ct(r,["-name"]),s=ct(r,["-type"]),a=r.filter(m=>!m.startsWith("-")&&m!==i&&m!==s)[0]??".",l=k(e,a);try{if(L(n,l,"find"),!t.vfs.exists(l))return{stderr:`find: ${a}: No such file or directory`,exitCode:1}}catch(m){return{stderr:`find: ${m instanceof Error?m.message:String(m)}`,exitCode:1}}let c=i?new RegExp(`^${i.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,u=[],d=(m,p)=>{let h=t.vfs.stat(m),y=!s||s==="f"&&h.type==="file"||s==="d"&&h.type==="directory",f=!c||c.test(m.split("/").pop()??"");if(y&&f&&u.push(p),h.type==="directory")for(let S of t.vfs.list(m)){let F=`${m}/${S}`,A=`${p}/${S}`;d(F,A)}};return d(l,a),{stdout:u.join(`
69
- `),exitCode:0}}};import*as ee from"node:os";var Pn={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=w(n,["-h","--human"]),e=w(n,["-m"]),r=w(n,["-g"]),i=ee.totalmem(),s=ee.freemem(),o=i-s,a=Math.floor(i*.02),l=Math.floor(i*.05),c=Math.floor(s*.95),u=Math.floor(i*.5),d=y=>t?y>=1024*1024*1024?`${(y/(1024*1024*1024)).toFixed(1)}G`:y>=1024*1024?`${(y/(1024*1024)).toFixed(1)}M`:`${(y/1024).toFixed(1)}K`:String(Math.floor(r?y/(1024*1024*1024):e?y/(1024*1024):y/1024)),m=" total used free shared buff/cache available",p=`Mem: ${d(i).padStart(12)} ${d(o).padStart(11)} ${d(s).padStart(11)} ${d(a).padStart(11)} ${d(l).padStart(11)} ${d(c).padStart(11)}`,h=`Swap: ${d(u).padStart(12)} ${d(0).padStart(11)} ${d(u).padStart(11)}`;return{stdout:[m,p,h].join(`
70
- `),exitCode:0}}};var kn={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let{flags:s,positionals:o}=at(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=s.has("-i"),l=s.has("-v"),c=s.has("-n"),u=s.has("-r"),d=s.has("-c"),m=s.has("-l"),p=s.has("-q")||s.has("--quiet")||s.has("--silent"),h=o[0],y=o.slice(1);if(!h)return{stderr:"grep: no pattern specified",exitCode:1};let f;try{let x=a?"mi":"m";f=new RegExp(h,x)}catch{return{stderr:`grep: invalid regex: ${h}`,exitCode:1}}let S=(x,E="")=>{let N=x.split(`
71
- `),b=[];for(let M=0;M<N.length;M++){let V=N[M]??"",P=f.test(V);if(l?!P:P){let I=c?`${M+1}:`:"";b.push(`${E}${I}${V}`)}}return b},F=x=>{if(!t.vfs.exists(x))return[];if(t.vfs.stat(x).type==="file")return[x];if(!u)return[];let N=[],b=M=>{for(let V of t.vfs.list(M)){let P=`${M}/${V}`;t.vfs.stat(P).type==="file"?N.push(P):b(P)}};return b(x),N},A=[];if(y.length===0){if(!i)return{stdout:"",exitCode:1};let x=S(i);if(d)return{stdout:`${x.length}
72
- `,exitCode:x.length>0?0:1};if(p)return{exitCode:x.length>0?0:1};A.push(...x)}else{let x=y.flatMap(E=>{let N=k(e,E);return F(N).map(b=>({file:E,path:b}))});for(let{file:E,path:N}of x)try{L(n,N,"grep");let b=t.vfs.readFile(N),M=x.length>1?`${E}:`:"",V=S(b,M);d?A.push(x.length>1?`${E}:${V.length}`:String(V.length)):m?V.length>0&&A.push(E):A.push(...V)}catch{return{stderr:`grep: ${E}: No such file or directory`,exitCode:1}}}return{stdout:A.length>0?`${A.join(`
68
+ `:"",exitCode:0}}for(let e of n.filter(r=>r!=="-p"))if(e.includes("=")){let r=e.indexOf("="),i=e.slice(0,r),s=e.slice(r+1);t.vars[i]=s}return{exitCode:0}}};var En={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=ct(r,["-name"]),s=ct(r,["-type"]),a=r.filter(m=>!m.startsWith("-")&&m!==i&&m!==s)[0]??".",l=N(e,a);try{if(D(n,l,"find"),!t.vfs.exists(l))return{stderr:`find: ${a}: No such file or directory`,exitCode:1}}catch(m){return{stderr:`find: ${m instanceof Error?m.message:String(m)}`,exitCode:1}}let c=i?new RegExp(`^${i.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,u=[],d=(m,p)=>{let h=t.vfs.stat(m),y=!s||s==="f"&&h.type==="file"||s==="d"&&h.type==="directory",f=!c||c.test(m.split("/").pop()??"");if(y&&f&&u.push(p),h.type==="directory")for(let S of t.vfs.list(m)){let I=`${m}/${S}`,k=`${p}/${S}`;d(I,k)}};return d(l,a),{stdout:u.join(`
69
+ `),exitCode:0}}};import*as ne from"node:os";var Mn={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=w(n,["-h","--human"]),e=w(n,["-m"]),r=w(n,["-g"]),i=ne.totalmem(),s=ne.freemem(),o=i-s,a=Math.floor(i*.02),l=Math.floor(i*.05),c=Math.floor(s*.95),u=Math.floor(i*.5),d=y=>t?y>=1024*1024*1024?`${(y/(1024*1024*1024)).toFixed(1)}G`:y>=1024*1024?`${(y/(1024*1024)).toFixed(1)}M`:`${(y/1024).toFixed(1)}K`:String(Math.floor(r?y/(1024*1024*1024):e?y/(1024*1024):y/1024)),m=" total used free shared buff/cache available",p=`Mem: ${d(i).padStart(12)} ${d(o).padStart(11)} ${d(s).padStart(11)} ${d(a).padStart(11)} ${d(l).padStart(11)} ${d(c).padStart(11)}`,h=`Swap: ${d(u).padStart(12)} ${d(0).padStart(11)} ${d(u).padStart(11)}`;return{stdout:[m,p,h].join(`
70
+ `),exitCode:0}}};var kn={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let{flags:s,positionals:o}=at(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=s.has("-i"),l=s.has("-v"),c=s.has("-n"),u=s.has("-r"),d=s.has("-c"),m=s.has("-l"),p=s.has("-q")||s.has("--quiet")||s.has("--silent"),h=o[0],y=o.slice(1);if(!h)return{stderr:"grep: no pattern specified",exitCode:1};let f;try{let b=a?"mi":"m";f=new RegExp(h,b)}catch{return{stderr:`grep: invalid regex: ${h}`,exitCode:1}}let S=(b,M="")=>{let A=b.split(`
71
+ `),v=[];for(let E=0;E<A.length;E++){let T=A[E]??"",P=f.test(T);if(l?!P:P){let F=c?`${E+1}:`:"";v.push(`${M}${F}${T}`)}}return v},I=b=>{if(!t.vfs.exists(b))return[];if(t.vfs.stat(b).type==="file")return[b];if(!u)return[];let A=[],v=E=>{for(let T of t.vfs.list(E)){let P=`${E}/${T}`;t.vfs.stat(P).type==="file"?A.push(P):v(P)}};return v(b),A},k=[];if(y.length===0){if(!i)return{stdout:"",exitCode:1};let b=S(i);if(d)return{stdout:`${b.length}
72
+ `,exitCode:b.length>0?0:1};if(p)return{exitCode:b.length>0?0:1};k.push(...b)}else{let b=y.flatMap(M=>{let A=N(e,M);return I(A).map(v=>({file:M,path:v}))});for(let{file:M,path:A}of b)try{D(n,A,"grep");let v=t.vfs.readFile(A),E=b.length>1?`${M}:`:"",T=S(v,E);d?k.push(b.length>1?`${M}:${T.length}`:String(T.length)):m?T.length>0&&k.push(M):k.push(...T)}catch{return{stderr:`grep: ${M}: No such file or directory`,exitCode:1}}}return{stdout:k.length>0?`${k.join(`
73
73
  `)}
74
- `:"",exitCode:A.length>0?0:1}}};var Mn={name:"groups",description:"Print group memberships",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n;return{stdout:t.users.isSudoer(r)?`${r} sudo root`:r,exitCode:0}}};var En={name:"gzip",description:"Compress files",category:"archive",params:["[-k] [-d] <file>"],run:({shell:n,cwd:t,args:e})=>{if(!n.packageManager.isInstalled("gzip"))return{stderr:`bash: gzip: command not found
74
+ `:"",exitCode:k.length>0?0:1}}};var In={name:"groups",description:"Print group memberships",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n;return{stdout:t.users.isSudoer(r)?`${r} sudo root`:r,exitCode:0}}};var An={name:"gzip",description:"Compress files",category:"archive",params:["[-k] [-d] <file>"],run:({shell:n,cwd:t,args:e})=>{if(!n.packageManager.isInstalled("gzip"))return{stderr:`bash: gzip: command not found
75
75
  Hint: install it with: apt install gzip
76
76
  `,exitCode:127};let r=e.includes("-k")||e.includes("--keep"),i=e.includes("-d"),s=e.find(c=>!c.startsWith("-"));if(!s)return{stderr:`gzip: no file specified
77
- `,exitCode:1};let o=k(t,s);if(i){if(!s.endsWith(".gz"))return{stderr:`gzip: ${s}: unknown suffix -- ignored
77
+ `,exitCode:1};let o=N(t,s);if(i){if(!s.endsWith(".gz"))return{stderr:`gzip: ${s}: unknown suffix -- ignored
78
78
  `,exitCode:1};if(!n.vfs.exists(o))return{stderr:`gzip: ${s}: No such file or directory
79
79
  `,exitCode:1};let c=n.vfs.readFile(o),u=o.slice(0,-3);return n.vfs.writeFile(u,c),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${s}: No such file or directory
80
80
  `,exitCode:1};if(s.endsWith(".gz"))return{stderr:`gzip: ${s}: already has .gz suffix -- unchanged
81
- `,exitCode:1};let a=n.vfs.readFileRaw(o),l=`${o}.gz`;return n.vfs.writeFile(l,a,{compress:!0}),r||n.vfs.remove(o),{exitCode:0}}},An={name:"gunzip",description:"Decompress files",category:"archive",aliases:["zcat"],params:["[-k] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-k")||e.includes("--keep"),i=e.find(l=>!l.startsWith("-"));if(!i)return{stderr:`gunzip: no file specified
82
- `,exitCode:1};let s=k(t,i);if(!n.vfs.exists(s))return{stderr:`gunzip: ${i}: No such file or directory
81
+ `,exitCode:1};let a=n.vfs.readFileRaw(o),l=`${o}.gz`;return n.vfs.writeFile(l,a,{compress:!0}),r||n.vfs.remove(o),{exitCode:0}}},On={name:"gunzip",description:"Decompress files",category:"archive",aliases:["zcat"],params:["[-k] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-k")||e.includes("--keep"),i=e.find(l=>!l.startsWith("-"));if(!i)return{stderr:`gunzip: no file specified
82
+ `,exitCode:1};let s=N(t,i);if(!n.vfs.exists(s))return{stderr:`gunzip: ${i}: No such file or directory
83
83
  `,exitCode:1};if(!i.endsWith(".gz"))return{stderr:`gunzip: ${i}: unknown suffix -- ignored
84
84
  `,exitCode:1};let o=n.vfs.readFile(s),a=s.slice(0,-3);return n.vfs.writeFile(a,o),r||n.vfs.remove(s),{exitCode:0}}};var Fn={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ct(r,["-n"]),o=r.find(d=>/^-\d+$/.test(d)),a=typeof s=="string"?parseInt(s,10):o?parseInt(o.slice(1),10):10,l=r.filter(d=>!d.startsWith("-")&&d!==s&&d!==String(a)),c=d=>{let m=d.split(`
85
85
  `),p=m.slice(0,a);return p.join(`
86
86
  `)+(d.endsWith(`
87
87
  `)&&p.length===m.slice(0,a).length?`
88
- `:"")};if(l.length===0)return{stdout:c(i??""),exitCode:0};let u=[];for(let d of l){let m=k(e,d);try{L(n,m,"head"),u.push(c(t.vfs.readFile(m)))}catch{return{stderr:`head: ${d}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
89
- `),exitCode:0}}};var Nn=["navigation","files","text","archive","system","package","network","shell","users","misc"],In={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",package:"Package Management",network:"Network",shell:"Shell & Scripting",users:"Users & Permissions",misc:"Miscellaneous"},Rn="\x1B[1m",yt="\x1B[0m",Os="\x1B[36m",Ws="\x1B[33m",zt="\x1B[2m",js="\x1B[32m";function _n(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Hs(n){let t=n.aliases?.length?` ${zt}(${n.aliases.join(", ")})${yt}`:"";return` ${Os}${_n(n.name,16)}${yt}${t}${_n("",(n.aliases?.length,0))} ${n.description??""}`}function qs(n){let t={};for(let s of n){let o=s.category??"misc";t[o]||(t[o]=[]),t[o].push(s)}let e=[`${Rn}Available commands${yt}`,`${zt}Type 'help <command>' for detailed usage.${yt}`,""],r=[...Nn.filter(s=>t[s]),...Object.keys(t).filter(s=>!Nn.includes(s)).sort()];for(let s of r){let o=t[s];if(!o?.length)continue;e.push(`${Ws}${In[s]??s}${yt}`);let a=[...o].sort((l,c)=>l.name.localeCompare(c.name));for(let l of a)e.push(Hs(l));e.push("")}let i=n.length;return e.push(`${zt}${i} commands available.${yt}`),e.join(`
90
- `)}function Ks(n){let t=[];if(t.push(`${Rn}${n.name}${yt} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${zt}Aliases: ${n.aliases.join(", ")}${yt}`),t.push(""),t.push(`${js}Usage:${yt}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=In[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${zt}Category: ${e}${yt}`),t.join(`
91
- `)}function Vn(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=$e();if(t[0]){let r=t[0].toLowerCase(),i=e.find(s=>s.name===r||s.aliases?.includes(r));return i?{stdout:Ks(i),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:qs(e),exitCode:0}}}}var Dn={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t,authUser:e})=>{let r=`/home/${e}/.bash_history`;if(!t.vfs.exists(r))return{stdout:"",exitCode:0};let s=t.vfs.readFile(r).split(`
88
+ `:"")};if(l.length===0)return{stdout:c(i??""),exitCode:0};let u=[];for(let d of l){let m=N(e,d);try{D(n,m,"head"),u.push(c(t.vfs.readFile(m)))}catch{return{stderr:`head: ${d}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
89
+ `),exitCode:0}}};var Rn=["navigation","files","text","archive","system","package","network","shell","users","misc"],_n={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",package:"Package Management",network:"Network",shell:"Shell & Scripting",users:"Users & Permissions",misc:"Miscellaneous"},Dn="\x1B[1m",yt="\x1B[0m",Hs="\x1B[36m",qs="\x1B[33m",Lt="\x1B[2m",Ys="\x1B[32m";function Tn(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Ks(n){let t=n.aliases?.length?` ${Lt}(${n.aliases.join(", ")})${yt}`:"";return` ${Hs}${Tn(n.name,16)}${yt}${t}${Tn("",(n.aliases?.length,0))} ${n.description??""}`}function Gs(n){let t={};for(let s of n){let o=s.category??"misc";t[o]||(t[o]=[]),t[o].push(s)}let e=[`${Dn}Available commands${yt}`,`${Lt}Type 'help <command>' for detailed usage.${yt}`,""],r=[...Rn.filter(s=>t[s]),...Object.keys(t).filter(s=>!Rn.includes(s)).sort()];for(let s of r){let o=t[s];if(!o?.length)continue;e.push(`${qs}${_n[s]??s}${yt}`);let a=[...o].sort((l,c)=>l.name.localeCompare(c.name));for(let l of a)e.push(Ks(l));e.push("")}let i=n.length;return e.push(`${Lt}${i} commands available.${yt}`),e.join(`
90
+ `)}function Js(n){let t=[];if(t.push(`${Dn}${n.name}${yt} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${Lt}Aliases: ${n.aliases.join(", ")}${yt}`),t.push(""),t.push(`${Ys}Usage:${yt}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=_n[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${Lt}Category: ${e}${yt}`),t.join(`
91
+ `)}function Un(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=Ne();if(t[0]){let r=t[0].toLowerCase(),i=e.find(s=>s.name===r||s.aliases?.includes(r));return i?{stdout:Js(i),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:Gs(e),exitCode:0}}}}var Ln={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t,authUser:e})=>{let r=`/home/${e}/.bash_history`;if(!t.vfs.exists(r))return{stdout:"",exitCode:0};let s=t.vfs.readFile(r).split(`
92
92
  `).filter(Boolean),o=n[0],a=o?parseInt(o,10):null,l=a&&!Number.isNaN(a)?s.slice(-a):s,c=s.length-l.length+1;return{stdout:l.map((d,m)=>`${String(c+m).padStart(5)} ${d}`).join(`
93
- `),exitCode:0}}};var Ln={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var zn={name:"htop",description:"System monitor",category:"system",params:[],run:({mode:n})=>n==="exec"?{stderr:"htop: interactive terminal required",exitCode:1}:{openHtop:!0,exitCode:0}};var Tn={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,i=r==="root"?0:1e3,s=i,a=t.users.isSudoer(r)?`${s}(${r}),0(root)`:`${s}(${r})`;return{stdout:`uid=${i}(${r}) gid=${s}(${r}) groups=${a}`,exitCode:0}}};var Un={name:"kill",description:"Send signal to process",category:"system",params:["[-9] <pid>"],run:({args:n})=>n.find(e=>!e.startsWith("-"))?{stdout:"",exitCode:0}:{stderr:"kill: no pid specified",exitCode:1}};var Bn={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-s","--symbolic"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let l=k(e,a),c=i?o:k(e,o);try{if(L(n,l,"ln"),i)t.vfs.symlink(c,l);else{let u=k(e,o);if(L(n,u,"ln"),!t.vfs.exists(u))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let d=t.vfs.readFile(u);t.writeFileAsUser(n,l,d)}return{exitCode:0}}catch(u){return{stderr:`ln: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}},On={name:"readlink",description:"Print resolved path of symbolic link",category:"files",params:["[-f] <path>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-f")||e.includes("-e"),i=e.find(a=>!a.startsWith("-"));if(!i)return{stderr:`readlink: missing operand
94
- `,exitCode:1};let s=k(t,i);return n.vfs.exists(s)?n.vfs.isSymlink(s)?{stdout:`${n.vfs.resolveSymlink(s)}
93
+ `),exitCode:0}}};var Vn={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var zn={name:"htop",description:"System monitor",category:"system",params:[],run:({mode:n})=>n==="exec"?{stderr:"htop: interactive terminal required",exitCode:1}:{openHtop:!0,exitCode:0}};var Bn={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,i=r==="root"?0:1e3,s=i,a=t.users.isSudoer(r)?`${s}(${r}),0(root)`:`${s}(${r})`;return{stdout:`uid=${i}(${r}) gid=${s}(${r}) groups=${a}`,exitCode:0}}};var Wn={name:"kill",description:"Send signal to process",category:"system",params:["[-9] <pid>"],run:({args:n})=>n.find(e=>!e.startsWith("-"))?{stdout:"",exitCode:0}:{stderr:"kill: no pid specified",exitCode:1}};var jn={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-s","--symbolic"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let l=N(e,a),c=i?o:N(e,o);try{if(D(n,l,"ln"),i)t.vfs.symlink(c,l);else{let u=N(e,o);if(D(n,u,"ln"),!t.vfs.exists(u))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let d=t.vfs.readFile(u);t.writeFileAsUser(n,l,d)}return{exitCode:0}}catch(u){return{stderr:`ln: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}},Hn={name:"readlink",description:"Print resolved path of symbolic link",category:"files",params:["[-f] <path>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-f")||e.includes("-e"),i=e.find(a=>!a.startsWith("-"));if(!i)return{stderr:`readlink: missing operand
94
+ `,exitCode:1};let s=N(t,i);return n.vfs.exists(s)?n.vfs.isSymlink(s)?{stdout:`${n.vfs.resolveSymlink(s)}
95
95
  `,exitCode:0}:{stderr:`readlink: ${i}: not a symbolic link
96
96
  `,exitCode:1}:{stderr:`readlink: ${i}: No such file or directory
97
- `,exitCode:1}}};var Wn={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(d=>!d.startsWith("-")||/^-[\d.]/.test(d)).map(Number),e=(()=>{let d=n.indexOf("-s");return d!==-1?n[d+1]??`
97
+ `,exitCode:1}}};var qn={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(d=>!d.startsWith("-")||/^-[\d.]/.test(d)).map(Number),e=(()=>{let d=n.indexOf("-s");return d!==-1?n[d+1]??`
98
98
  `:`
99
99
  `})(),r=(()=>{let d=n.indexOf("-f");return d!==-1?n[d+1]??"%g":null})(),i=n.includes("-w"),s=1,o=1,a;if(t.length===1?a=t[0]:t.length===2?(s=t[0],a=t[1]):(s=t[0],o=t[1],a=t[2]),o===0)return{stderr:`seq: zero increment
100
100
  `,exitCode:1};if(o>0&&s>a||o<0&&s<a)return{stdout:"",exitCode:0};let l=[],c=1e5,u=0;for(let d=s;(o>0?d<=a:d>=a)&&!(++u>c);d=Math.round((d+o)*1e10)/1e10){let m;if(r?m=r.replace("%g",String(d)).replace("%f",d.toFixed(6)).replace("%d",String(Math.trunc(d))):m=Number.isInteger(d)?String(d):d.toPrecision(12).replace(/\.?0+$/,""),i){let p=String(Math.trunc(a)).length;m=m.padStart(p,"0")}l.push(m)}return{stdout:`${l.join(e)}
101
- `,exitCode:0}}};var jn={name:"stat",description:"Display file status",category:"files",params:["[-c <format>] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.findIndex(S=>S==="-c"||S==="--format"),i=r!==-1?e[r+1]:void 0,s=e.find(S=>!S.startsWith("-")&&S!==i);if(!s)return{stderr:`stat: missing operand
102
- `,exitCode:1};let o=k(t,s);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${s}': No such file or directory
103
- `,exitCode:1};let a=n.vfs.stat(o),l=a.type==="directory",c=n.vfs.isSymlink(o),u=n.vfs.isSymlink(o),d=S=>{let F=[256,128,64,32,16,8,4,2,1],A=["r","w","x","r","w","x","r","w","x"];return(l?"d":u?"l":"-")+F.map((x,E)=>S&x?A[E]:"-").join("")},m=a.mode.toString(8).padStart(4,"0"),p=d(a.mode),h="size"in a?a.size:0,y=S=>S.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return i?{stdout:`${i.replace("%n",s).replace("%s",String(h)).replace("%a",m.slice(1)).replace("%A",p).replace("%F",u?"symbolic link":l?"directory":"regular file").replace("%y",y(a.updatedAt)).replace("%z",y(a.updatedAt))}
101
+ `,exitCode:0}}};var Yn={name:"stat",description:"Display file status",category:"files",params:["[-c <format>] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.findIndex(S=>S==="-c"||S==="--format"),i=r!==-1?e[r+1]:void 0,s=e.find(S=>!S.startsWith("-")&&S!==i);if(!s)return{stderr:`stat: missing operand
102
+ `,exitCode:1};let o=N(t,s);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${s}': No such file or directory
103
+ `,exitCode:1};let a=n.vfs.stat(o),l=a.type==="directory",c=n.vfs.isSymlink(o),u=n.vfs.isSymlink(o),d=S=>{let I=[256,128,64,32,16,8,4,2,1],k=["r","w","x","r","w","x","r","w","x"];return(l?"d":u?"l":"-")+I.map((b,M)=>S&b?k[M]:"-").join("")},m=a.mode.toString(8).padStart(4,"0"),p=d(a.mode),h="size"in a?a.size:0,y=S=>S.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return i?{stdout:`${i.replace("%n",s).replace("%s",String(h)).replace("%a",m.slice(1)).replace("%A",p).replace("%F",u?"symbolic link":l?"directory":"regular file").replace("%y",y(a.updatedAt)).replace("%z",y(a.updatedAt))}
104
104
  `,exitCode:0}:{stdout:`${[` File: ${s}${u?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${h}${" ".repeat(3)}${u?"symbolic link":l?"directory":"regular file"}`,`Access: (${m}/${p}) Uid: ( 0/ root) Gid: ( 0/ root)`,`Modify: ${y(a.updatedAt)}`,`Change: ${y(a.updatedAt)}`].join(`
105
105
  `)}
106
- `,exitCode:0}}};var Gs="\x1B[0m",Js="\x1B[1;34m",Zs="\x1B[1;36m",Ys="\x1B[1;32m",Qs="",Xs="\x1B[30;42m",ti="\x1B[37;44m",ei="\x1B[34;42m";function Ft(n,t){return t?`${t}${n}${Gs}`:n}function ke(n,t,e){if(e)return Zs;if(t==="directory"){let r=!!(n&512),i=!!(n&2);return r&&i?Xs:r?ti:i?ei:Js}return n&73?Ys:Qs}function Hn(n,t,e){let r;e?r="l":t==="directory"?r="d":r="-";let i=c=>n&c?"r":"-",s=c=>n&c?"w":"-",o=(()=>{let c=!!(n&64);return n&2048?c?"s":"S":c?"x":"-"})(),a=(()=>{let c=!!(n&8);return n&1024?c?"s":"S":c?"x":"-"})(),l=(()=>{let c=!!(n&1);return t==="directory"&&n&512?c?"t":"T":c?"x":"-"})();return`${r}${i(256)}${s(128)}${o}${i(32)}${s(16)}${a}${i(4)}${s(2)}${l}`}var ni=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Pe(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,i=String(n.getDate()).padStart(2," "),s=ni[n.getMonth()]??"";if(r){let o=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return`${i} ${s.padEnd(3)} ${o}:${a}`}return`${i} ${s.padEnd(3)} ${n.getFullYear()}`}function ne(n,t){try{return n.readFile(t)}catch{return"?"}}function ri(n,t,e){let r=t==="/"?"":t;return e.map(i=>{let s=`${r}/${i}`,o=n.isSymlink(s),a;try{a=n.stat(s)}catch{return i}let l=ke(a.mode,a.type,o);return Ft(i,l)}).join(" ")}function si(n,t,e){let r=t==="/"?"":t,i=e.map(d=>{let m=`${r}/${d}`,p=n.isSymlink(m),h;try{h=n.stat(m)}catch{return{perms:"----------",nlink:"1",size:"0",date:Pe(new Date),label:d}}let y=p?41471:h.mode,f=Hn(y,h.type,p),S=h.type==="directory"?String((h.childrenCount??0)+2):"1",F=p?ne(n,m).length:h.type==="file"?h.size??0:(h.childrenCount??0)*4096,A=String(F),x=Pe(h.updatedAt),E=ke(y,h.type,p),N=p?`${Ft(d,E)} -> ${ne(n,m)}`:Ft(d,E);return{perms:f,nlink:S,size:A,date:x,label:N}}),s=Math.max(...i.map(d=>d.nlink.length)),o=Math.max(...i.map(d=>d.size.length)),a="root",l="root",c=e.length*8,u=i.map(d=>`${d.perms} ${d.nlink.padStart(s)} ${a} ${l} ${d.size.padStart(o)} ${d.date} ${d.label}`);return`total ${c}
106
+ `,exitCode:0}}};var Zs="\x1B[0m",Qs="\x1B[1;34m",Xs="\x1B[1;36m",ti="\x1B[1;32m",ei="",ni="\x1B[30;42m",ri="\x1B[37;44m",si="\x1B[34;42m";function Ot(n,t){return t?`${t}${n}${Zs}`:n}function Me(n,t,e){if(e)return Xs;if(t==="directory"){let r=!!(n&512),i=!!(n&2);return r&&i?ni:r?ri:i?si:Qs}return n&73?ti:ei}function Kn(n,t,e){let r;e?r="l":t==="directory"?r="d":r="-";let i=c=>n&c?"r":"-",s=c=>n&c?"w":"-",o=(()=>{let c=!!(n&64);return n&2048?c?"s":"S":c?"x":"-"})(),a=(()=>{let c=!!(n&8);return n&1024?c?"s":"S":c?"x":"-"})(),l=(()=>{let c=!!(n&1);return t==="directory"&&n&512?c?"t":"T":c?"x":"-"})();return`${r}${i(256)}${s(128)}${o}${i(32)}${s(16)}${a}${i(4)}${s(2)}${l}`}var ii=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ee(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,i=String(n.getDate()).padStart(2," "),s=ii[n.getMonth()]??"";if(r){let o=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return`${i} ${s.padEnd(3)} ${o}:${a}`}return`${i} ${s.padEnd(3)} ${n.getFullYear()}`}function re(n,t){try{return n.readFile(t)}catch{return"?"}}function oi(n,t,e){let r=t==="/"?"":t;return e.map(i=>{let s=`${r}/${i}`,o=n.isSymlink(s),a;try{a=n.stat(s)}catch{return i}let l=Me(a.mode,a.type,o);return Ot(i,l)}).join(" ")}function ai(n,t,e){let r=t==="/"?"":t,i=e.map(d=>{let m=`${r}/${d}`,p=n.isSymlink(m),h;try{h=n.stat(m)}catch{return{perms:"----------",nlink:"1",size:"0",date:Ee(new Date),label:d}}let y=p?41471:h.mode,f=Kn(y,h.type,p),S=h.type==="directory"?String((h.childrenCount??0)+2):"1",I=p?re(n,m).length:h.type==="file"?h.size??0:(h.childrenCount??0)*4096,k=String(I),b=Ee(h.updatedAt),M=Me(y,h.type,p),A=p?`${Ot(d,M)} -> ${re(n,m)}`:Ot(d,M);return{perms:f,nlink:S,size:k,date:b,label:A}}),s=Math.max(...i.map(d=>d.nlink.length)),o=Math.max(...i.map(d=>d.size.length)),a="root",l="root",c=e.length*8,u=i.map(d=>`${d.perms} ${d.nlink.padStart(s)} ${a} ${l} ${d.size.padStart(o)} ${d.date} ${d.label}`);return`total ${c}
107
107
  ${u.join(`
108
- `)}`}var qn={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-l","--long","-la","-al"]),s=w(r,["-a","--all","-la","-al"]),o=Ct(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=k(e,o??e);if(L(n,a,"ls"),t.vfs.exists(a)){let u=t.vfs.stat(a),d=t.vfs.isSymlink(a);if(u.type==="file"||d){let m=a.split("/").pop()??a,p=ke(d?41471:u.mode,u.type,d);if(i){let h=d?41471:u.mode,y=d?ne(t.vfs,a).length:u.size??0,f=Hn(h,u.type,d),S=d?`${Ft(m,p)} -> ${ne(t.vfs,a)}`:Ft(m,p);return{stdout:`${f} 1 root root ${y} ${Pe(u.updatedAt)} ${S}
109
- `,exitCode:0}}return{stdout:`${Ft(m,p)}
110
- `,exitCode:0}}}let l=t.vfs.list(a).filter(u=>s||!u.startsWith("."));return{stdout:`${i?si(t.vfs,a,l):ri(t.vfs,a,l)}
111
- `,exitCode:0}}};var Kn={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:n,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",i="1.0";try{let d=t.vfs.readFile("/etc/os-release");for(let m of d.split(`
108
+ `)}`}var Gn={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=w(r,["-l","--long","-la","-al"]),s=w(r,["-a","--all","-la","-al"]),o=Ct(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=N(e,o??e);if(D(n,a,"ls"),t.vfs.exists(a)){let u=t.vfs.stat(a),d=t.vfs.isSymlink(a);if(u.type==="file"||d){let m=a.split("/").pop()??a,p=Me(d?41471:u.mode,u.type,d);if(i){let h=d?41471:u.mode,y=d?re(t.vfs,a).length:u.size??0,f=Kn(h,u.type,d),S=d?`${Ot(m,p)} -> ${re(t.vfs,a)}`:Ot(m,p);return{stdout:`${f} 1 root root ${y} ${Ee(u.updatedAt)} ${S}
109
+ `,exitCode:0}}return{stdout:`${Ot(m,p)}
110
+ `,exitCode:0}}}let l=t.vfs.list(a).filter(u=>s||!u.startsWith("."));return{stdout:`${i?ai(t.vfs,a,l):oi(t.vfs,a,l)}
111
+ `,exitCode:0}}};var Jn={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:n,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",i="1.0";try{let d=t.vfs.readFile("/etc/os-release");for(let m of d.split(`
112
112
  `))m.startsWith("PRETTY_NAME=")&&(e=m.slice(12).replace(/^"|"$/g,"").trim()),m.startsWith("VERSION_CODENAME=")&&(r=m.slice(17).trim()),m.startsWith("VERSION_ID=")&&(i=m.slice(11).replace(/^"|"$/g,"").trim())}catch{}let s=w(n,["-a","--all"]),o=w(n,["-i","--id"]),a=w(n,["-d","--description"]),l=w(n,["-r","--release"]),c=w(n,["-c","--codename"]);if(s||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${i}`,`Codename: ${r}`].join(`
113
113
  `),exitCode:0};let u=[];return o&&u.push("Distributor ID: Fortune"),a&&u.push(`Description: ${e}`),l&&u.push(`Release: ${i}`),c&&u.push(`Codename: ${r}`),{stdout:u.join(`
114
- `),exitCode:0}}};var ii={gunzip:"gzip"},pl=import.meta.dirname,re=new Map,oi=new URL("./manuals/",import.meta.url);async function ai(n){return new Function("moduleName","return import(moduleName)")(n)}async function li(n){let t=n.toLowerCase(),e=ii[t]??t,r=`builtin:${e}`;if(re.has(r))return re.get(r)??null;try{let i=await ai("node:fs/promises"),s=new URL(`${e}.txt`,oi),a=(await i.readFile(s,"utf8")).replace(/\n$/,"");return re.set(r,a),a}catch{return re.set(r,null),null}}var Gn={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:n,shell:t})=>{let e=n[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let i=await li(e);return i?{stdout:i,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Jn={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let i=0;i<r.length;i++){let s=Ct(r,i);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let o=k(e,s);L(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Zn={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r.filter(c=>!c.startsWith("-")),[s,o]=i;if(!s||!o)return{stderr:"mv: missing operand",exitCode:1};let a=k(e,s),l=k(e,o);try{if(L(n,a,"mv"),L(n,l,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let c=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${s.split("/").pop()}`:l;return t.vfs.move(a,c),{exitCode:0}}catch(c){return{stderr:`mv: ${c instanceof Error?c.message:String(c)}`,exitCode:1}}}};import*as Yn from"node:path";var Qn={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r[0];if(!i)return{stderr:"nano: missing file operand",exitCode:1};let s=k(e,i);L(n,s,"nano");let o=t.vfs.exists(s)?t.vfs.readFile(s):"",a=Yn.posix.basename(s)||"buffer",l=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:l,initialContent:o},exitCode:0}}};import{existsSync as ir,readdirSync as ci,readFileSync as Me}from"node:fs";import*as rt from"node:os";import*as or from"node:path";function ui(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60,s=[];return e>0&&s.push(`${e} day${e>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(i>0||s.length===0)&&s.push(`${i} min${i>1?"s":""}`),s.join(", ")}function Xn(n){return`\x1B[${n}m \x1B[0m`}function di(){let n=[40,41,42,43,44,45,46,47].map(Xn).join(""),t=[100,101,102,103,104,105,106,107].map(Xn).join("");return[n,t]}function tr(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s=e<=1?0:t/(e-1),o=Math.round(r.r+(i.r-r.r)*s),a=Math.round(r.g+(i.g-r.g)*s),l=Math.round(r.b+(i.b-r.b)*s);return`\x1B[38;2;${o};${a};${l}m${n}\x1B[0m`}function mi(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?er(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return er(e)+r}function er(n){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=n.replace(t,"");if(e.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),l=Math.round(r.r+(i.r-r.r)*a),c=Math.round(r.g+(i.g-r.g)*a),u=Math.round(r.b+(i.b-r.b)*a);s+=`\x1B[38;2;${l};${c};${u}m${e[o]}\x1B[0m`}return s}function nr(n){return Math.max(0,Math.round(n/(1024*1024)))}function rr(){try{let n=Me("/etc/os-release","utf8");for(let t of n.split(`
115
- `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function sr(n){try{let t=Me(n,"utf8").split(`
116
- `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function pi(n){let t=sr("/sys/devices/virtual/dmi/id/sys_vendor"),e=sr("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function fi(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if(ir(t))try{return Me(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function hi(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if(ir(t))try{return ci(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}}function gi(){let n=fi(),t=hi();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function yi(){let n=rt.cpus();if(n.length===0)return"unknown";let t=n[0];if(!t)return"unknown";let e=(t.speed/1e3).toFixed(2);return`${t.model} (${n.length}) @ ${e}GHz`}function Si(n){return!n||n.trim().length===0?"unknown":or.posix.basename(n.trim())}function wi(n){let t=rt.totalmem(),e=rt.freemem(),r=Math.max(0,t-e),i=n.shellProps,s=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(s)),{user:n.user,host:n.host,osName:i?.os??n.osName??`${rr()??rt.type()} ${rt.arch()}`,kernel:i?.kernel??n.kernel??rt.release(),uptimeSeconds:n.uptimeSeconds??rt.uptime(),packages:n.packages??gi(),shell:Si(n.shell),shellProps:n.shellProps??{kernel:n.kernel??rt.release(),os:n.osName??`${rr()??rt.type()} ${rt.arch()}`,arch:rt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??yi(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??nr(r),memoryTotalMiB:n.memoryTotalMiB??nr(t)}}function ar(n){let t=wi(n),e=ui(t.uptimeSeconds),r=di(),i=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${pi(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${e}`,`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]],o=Math.max(i.length,s.length),a=[];for(let l=0;l<o;l+=1){let c=i[l]??"",u=s[l]??"";if(u.length>0){let d=tr(c.padEnd(31," "),l,i.length),m=mi(u);a.push(`${d} ${m}`);continue}a.push(tr(c,l,i.length))}return a.join(`
117
- `)}var lr={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:i})=>r.packageManager.isInstalled("neofetch")?w(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:w(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:ar({user:t,host:e,shell:i.vars.SHELL,shellProps:r.properties,terminal:i.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
114
+ `),exitCode:0}}};var Zn={adduser:`ADDUSER(8) User Commands ADDUSER(8)
115
+
116
+ NAME
117
+ adduser - add a user to the system
118
+
119
+ SYNOPSIS
120
+ adduser USERNAME
121
+
122
+ DESCRIPTION
123
+ Create a new user account with a home directory.
124
+ In this environment, prompts for a password interactively.`,"apt-cache":`APT-CACHE(8) APT APT-CACHE(8)
125
+
126
+ NAME
127
+ apt-cache - query APT package cache
128
+
129
+ SYNOPSIS
130
+ apt-cache command [args]
131
+
132
+ COMMANDS
133
+ search term search package names/descriptions
134
+ show pkg show package metadata
135
+ policy pkg show package policy and candidate versions`,apt:`APT(8) APT APT(8)
136
+
137
+ NAME
138
+ apt - command-line interface
139
+
140
+ SYNOPSIS
141
+ apt [options] command
142
+
143
+ DESCRIPTION
144
+ apt provides a high-level commandline interface for the package
145
+ management system.
146
+
147
+ COMMANDS
148
+ install pkg... Install packages
149
+ remove pkg... Remove packages
150
+ update Download package information
151
+ upgrade Upgrade installed packages
152
+ search term Search in package descriptions
153
+ show pkg Show package information
154
+ list List packages`,awk:`AWK(1) User Commands AWK(1)
155
+
156
+ NAME
157
+ awk - pattern scanning and processing language
158
+
159
+ SYNOPSIS
160
+ awk [OPTION]... 'PROGRAM' [FILE]...
161
+
162
+ DESCRIPTION
163
+ awk scans each input line, applies PROGRAM rules, and prints results.
164
+
165
+ OPTIONS
166
+ -F fs use fs as input field separator`,cat:`CAT(1) User Commands CAT(1)
167
+
168
+ NAME
169
+ cat - concatenate files and print on the standard output
170
+
171
+ SYNOPSIS
172
+ cat [OPTION]... [FILE]...
173
+
174
+ DESCRIPTION
175
+ Concatenate FILE(s) to standard output.
176
+
177
+ OPTIONS
178
+ -n, --number number all output lines
179
+ -b, --number-nonblank number nonempty output lines`,cd:`CD(1) Shell Builtins CD(1)
180
+
181
+ NAME
182
+ cd - change the shell working directory
183
+
184
+ SYNOPSIS
185
+ cd [DIRECTORY]
186
+
187
+ DESCRIPTION
188
+ Change the current working directory.
189
+ Without DIRECTORY, changes to $HOME.
190
+
191
+ EXAMPLES
192
+ cd /etc
193
+ cd ..
194
+ cd ~`,chmod:`CHMOD(1) User Commands CHMOD(1)
195
+
196
+ NAME
197
+ chmod - change file mode bits
198
+
199
+ SYNOPSIS
200
+ chmod [OPTION]... MODE[,MODE]... FILE...
201
+ chmod [OPTION]... OCTAL-MODE FILE...
202
+
203
+ DESCRIPTION
204
+ Change the file mode bits of each given file according to MODE.
205
+
206
+ EXAMPLES
207
+ chmod 755 script.sh rwxr-xr-x
208
+ chmod 644 file.txt rw-r--r--
209
+ chmod +x script.sh add execute permission`,clear:`CLEAR(1) User Commands CLEAR(1)
210
+
211
+ NAME
212
+ clear - clear the terminal screen
213
+
214
+ SYNOPSIS
215
+ clear
216
+
217
+ DESCRIPTION
218
+ Clear the display and move cursor to top-left.`,cp:`CP(1) User Commands CP(1)
219
+
220
+ NAME
221
+ cp - copy files and directories
222
+
223
+ SYNOPSIS
224
+ cp [OPTION]... SOURCE... DEST
225
+
226
+ OPTIONS
227
+ -r copy directories recursively`,curl:`CURL(1) User Commands CURL(1)
228
+
229
+ NAME
230
+ curl - transfer a URL
231
+
232
+ SYNOPSIS
233
+ curl [options / URLs]
234
+
235
+ DESCRIPTION
236
+ curl is a tool for transferring data with URL syntax.
237
+
238
+ OPTIONS
239
+ -o, --output <file> Write output to <file>
240
+ -X, --request <method> Specify request method
241
+ -d, --data <data> HTTP POST data
242
+ -H, --header <header> Pass custom header
243
+ -s, --silent Silent mode
244
+ -I, --head Show document info only
245
+ -L, --location Follow redirects
246
+ -v, --verbose Make the operation more talkative`,date:`DATE(1) User Commands DATE(1)
247
+
248
+ NAME
249
+ date - print or set the system date and time
250
+
251
+ SYNOPSIS
252
+ date [+FORMAT]
253
+
254
+ DESCRIPTION
255
+ Display current date/time, optionally formatted.
256
+
257
+ EXAMPLES
258
+ date
259
+ date +%Y-%m-%d`,declare:`DECLARE(1) Shell Builtins DECLARE(1)
260
+
261
+ NAME
262
+ declare - set variable values and attributes
263
+
264
+ SYNOPSIS
265
+ declare [OPTION]... [NAME[=VALUE]...]
266
+
267
+ OPTIONS
268
+ -i variable has integer attribute
269
+ -r make NAMEs readonly
270
+ -x export NAMEs to environment`,deluser:`DELUSER(8) User Commands DELUSER(8)
271
+
272
+ NAME
273
+ deluser - remove a user account
274
+
275
+ SYNOPSIS
276
+ deluser [OPTION] USERNAME
277
+
278
+ OPTIONS
279
+ -f, --force remove without interactive confirmation`,df:`DF(1) User Commands DF(1)
280
+
281
+ NAME
282
+ df - report file system disk space usage
283
+
284
+ SYNOPSIS
285
+ df [OPTION]... [FILE]...
286
+
287
+ OPTIONS
288
+ -h print sizes in human readable format`,"dpkg-query":`DPKG-QUERY(1) User Commands DPKG-QUERY(1)
289
+
290
+ NAME
291
+ dpkg-query - tool to query the dpkg database
292
+
293
+ SYNOPSIS
294
+ dpkg-query [OPTION]... [ACTION]
295
+
296
+ OPTIONS
297
+ -W list installed packages (show format)
298
+ -l list packages`,dpkg:`DPKG(1) User Commands DPKG(1)
299
+
300
+ NAME
301
+ dpkg - package manager for Debian-like systems
302
+
303
+ SYNOPSIS
304
+ dpkg [OPTION]... ACTION
305
+
306
+ OPTIONS
307
+ -l list installed packages
308
+ -s show package status
309
+ -L list files in package
310
+ -r remove package
311
+ -P purge package`,du:`DU(1) User Commands DU(1)
312
+
313
+ NAME
314
+ du - estimate file space usage
315
+
316
+ SYNOPSIS
317
+ du [OPTION]... [FILE]...
318
+
319
+ OPTIONS
320
+ -h print sizes in human readable format
321
+ -s display only a total for each argument`,echo:`ECHO(1) User Commands ECHO(1)
322
+
323
+ NAME
324
+ echo - display a line of text
325
+
326
+ SYNOPSIS
327
+ echo [OPTION]... [STRING]...
328
+
329
+ OPTIONS
330
+ -n do not output the trailing newline
331
+ -e enable interpretation of backslash escapes`,false:`FALSE(1) User Commands FALSE(1)
332
+
333
+ NAME
334
+ false - do nothing, unsuccessfully
335
+
336
+ SYNOPSIS
337
+ false
338
+
339
+ DESCRIPTION
340
+ Exit with a status code indicating failure (1).`,find:`FIND(1) User Commands FIND(1)
341
+
342
+ NAME
343
+ find - search for files in a directory hierarchy
344
+
345
+ SYNOPSIS
346
+ find [PATH] [EXPRESSION]
347
+
348
+ OPTIONS
349
+ -name PATTERN base name matches shell PATTERN
350
+ -type TYPE file type, e.g. f for file, d for directory`,free:`FREE(1) User Commands FREE(1)
351
+
352
+ NAME
353
+ free - display amount of free and used memory in the system
354
+
355
+ SYNOPSIS
356
+ free [OPTION]...
357
+
358
+ OPTIONS
359
+ -h show all output fields automatically scaled
360
+ -m show output in mebibytes
361
+ -g show output in gibibytes`,grep:`GREP(1) User Commands GREP(1)
362
+
363
+ NAME
364
+ grep, egrep, fgrep - print lines that match patterns
365
+
366
+ SYNOPSIS
367
+ grep [OPTION]... PATTERNS [FILE]...
368
+
369
+ OPTIONS
370
+ -i, --ignore-case ignore case distinctions in patterns and data
371
+ -v, --invert-match select non-matching lines
372
+ -n, --line-number print line number with output lines
373
+ -r, --recursive read all files under each directory, recursively`,groups:`GROUPS(1) User Commands GROUPS(1)
374
+
375
+ NAME
376
+ groups - print the groups a user is in
377
+
378
+ SYNOPSIS
379
+ groups [USER]
380
+
381
+ DESCRIPTION
382
+ Print group memberships for USER or current user if omitted.`,gzip:`GZIP(1) User Commands GZIP(1)
383
+
384
+ NAME
385
+ gzip, gunzip - compress or expand files
386
+
387
+ SYNOPSIS
388
+ gzip FILE...
389
+ gunzip FILE...
390
+
391
+ DESCRIPTION
392
+ Compress or decompress files in place.`,head:`HEAD(1) User Commands HEAD(1)
393
+
394
+ NAME
395
+ head - output the first part of files
396
+
397
+ SYNOPSIS
398
+ head [OPTION]... [FILE]...
399
+
400
+ OPTIONS
401
+ -n, --lines=[-]NUM print the first NUM lines`,help:`HELP(1) Shell Builtins HELP(1)
402
+
403
+ NAME
404
+ help - display information about builtin commands
405
+
406
+ SYNOPSIS
407
+ help [COMMAND]
408
+
409
+ DESCRIPTION
410
+ With no arguments, list available commands.
411
+ With COMMAND, show usage details for that command.`,history:`HISTORY(1) Shell Builtins HISTORY(1)
412
+
413
+ NAME
414
+ history - command history list
415
+
416
+ SYNOPSIS
417
+ history [N]
418
+
419
+ DESCRIPTION
420
+ Print recent command history entries.
421
+ If N is provided, print only the last N entries.`,hostname:`HOSTNAME(1) User Commands HOSTNAME(1)
422
+
423
+ NAME
424
+ hostname - show or set the system host name
425
+
426
+ SYNOPSIS
427
+ hostname
428
+
429
+ DESCRIPTION
430
+ Print the current host name.`,id:`ID(1) User Commands ID(1)
431
+
432
+ NAME
433
+ id - print real and effective user and group IDs
434
+
435
+ SYNOPSIS
436
+ id [USER]
437
+
438
+ DESCRIPTION
439
+ Print user identity information including uid, gid, and groups.`,kill:`KILL(1) User Commands KILL(1)
440
+
441
+ NAME
442
+ kill - send signals to processes
443
+
444
+ SYNOPSIS
445
+ kill [-SIGNAL] PID...
446
+
447
+ DESCRIPTION
448
+ Send a signal to one or more process IDs.
449
+
450
+ NOTES
451
+ This environment provides a mock process model.`,ls:`LS(1) User Commands LS(1)
452
+
453
+ NAME
454
+ ls - list directory contents
455
+
456
+ SYNOPSIS
457
+ ls [OPTION]... [FILE]...
458
+
459
+ DESCRIPTION
460
+ List information about the FILEs (the current directory by default).
461
+
462
+ OPTIONS
463
+ -l use a long listing format
464
+ -a do not ignore entries starting with .
465
+ -h with -l, print human readable sizes
466
+ -r reverse order while sorting
467
+ -t sort by modification time
468
+
469
+ AUTHOR
470
+ Written by Richard M. Stallman and David MacKenzie.`,lsb_release:`LSB_RELEASE(1) User Commands LSB_RELEASE(1)
471
+
472
+ NAME
473
+ lsb_release - print distribution-specific information
474
+
475
+ SYNOPSIS
476
+ lsb_release [OPTION]...
477
+
478
+ OPTIONS
479
+ -a show all available information
480
+ -i show distributor ID
481
+ -d show description
482
+ -r show release number
483
+ -c show codename`,mkdir:`MKDIR(1) User Commands MKDIR(1)
484
+
485
+ NAME
486
+ mkdir - make directories
487
+
488
+ SYNOPSIS
489
+ mkdir [OPTION]... DIRECTORY...
490
+
491
+ OPTIONS
492
+ -p no error if existing, make parent directories as needed`,mv:`MV(1) User Commands MV(1)
493
+
494
+ NAME
495
+ mv - move (rename) files
496
+
497
+ SYNOPSIS
498
+ mv SOURCE DEST
499
+
500
+ DESCRIPTION
501
+ Rename SOURCE to DEST, or move SOURCE into a destination directory.`,nano:`NANO(1) User Commands NANO(1)
502
+
503
+ NAME
504
+ nano - simple terminal text editor
505
+
506
+ SYNOPSIS
507
+ nano FILE
508
+
509
+ DESCRIPTION
510
+ Open FILE in an interactive editor.
511
+ Save with Ctrl+O, exit with Ctrl+X.`,neofetch:`NEOFETCH(1) User Commands NEOFETCH(1)
512
+
513
+ NAME
514
+ neofetch - display system information
515
+
516
+ SYNOPSIS
517
+ neofetch
518
+
519
+ DESCRIPTION
520
+ Print OS, kernel, uptime, package count, and related system details.`,node:`NODE(1) User Commands NODE(1)
521
+
522
+ NAME
523
+ node - virtual JavaScript runtime entry point
524
+
525
+ SYNOPSIS
526
+ node [--version] [-e SCRIPT] [-p EXPR]
527
+
528
+ DESCRIPTION
529
+ Execute JavaScript snippets in the virtual runtime.
530
+
531
+ NOTES
532
+ Requires package installation: apt install nodejs.`,npm:`NPM(1) User Commands NPM(1)
533
+
534
+ NAME
535
+ npm - virtual Node.js package manager interface
536
+
537
+ SYNOPSIS
538
+ npm [--version] [COMMAND]
539
+
540
+ DESCRIPTION
541
+ Manage packages and run scripts in the virtual environment.
542
+
543
+ NOTES
544
+ Requires package installation: apt install npm.`,npx:`NPX(1) User Commands NPX(1)
545
+
546
+ NAME
547
+ npx - execute package binaries from npm
548
+
549
+ SYNOPSIS
550
+ npx [--version] <command>
551
+
552
+ DESCRIPTION
553
+ Run package executables in the virtual environment.
554
+
555
+ NOTES
556
+ Requires package installation: apt install npm.`,passwd:`PASSWD(1) User Commands PASSWD(1)
557
+
558
+ NAME
559
+ passwd - change user password
560
+
561
+ SYNOPSIS
562
+ passwd [USER]
563
+
564
+ DESCRIPTION
565
+ Update the authentication token (password) for USER.
566
+ Without USER, change the current user's password.`,ping:`PING(8) User Commands PING(8)
567
+
568
+ NAME
569
+ ping - send ICMP ECHO_REQUEST to network hosts
570
+
571
+ SYNOPSIS
572
+ ping [-c COUNT] DESTINATION
573
+
574
+ OPTIONS
575
+ -c COUNT stop after sending COUNT packets`,printf:`PRINTF(1) User Commands PRINTF(1)
576
+
577
+ NAME
578
+ printf - format and print data
579
+
580
+ SYNOPSIS
581
+ printf FORMAT [ARGUMENT]...
582
+
583
+ DESCRIPTION
584
+ Print ARGUMENT(s) according to FORMAT.
585
+ Supports common conversions like %s, %d, %f, %x and escapes like \\n.`,ps:`PS(1) User Commands PS(1)
586
+
587
+ NAME
588
+ ps - report a snapshot of current processes
589
+
590
+ SYNOPSIS
591
+ ps [OPTION]
592
+
593
+ DESCRIPTION
594
+ Show process information for active sessions and commands.`,pwd:`PWD(1) User Commands PWD(1)
595
+
596
+ NAME
597
+ pwd - print name of current working directory
598
+
599
+ SYNOPSIS
600
+ pwd
601
+
602
+ DESCRIPTION
603
+ Print the absolute path of the current directory.`,python3:`PYTHON3(1) User Commands PYTHON3(1)
604
+
605
+ NAME
606
+ python3 - virtual Python 3 interpreter entry point
607
+
608
+ SYNOPSIS
609
+ python3 [--version] [-V] [-c COMMAND]
610
+
611
+ DESCRIPTION
612
+ Execute Python snippets in the virtual runtime.
613
+
614
+ NOTES
615
+ Requires package installation: apt install python3.`,readlink:`READLINK(1) User Commands READLINK(1)
616
+
617
+ NAME
618
+ readlink - print resolved symbolic links or canonical file names
619
+
620
+ SYNOPSIS
621
+ readlink [OPTION]... FILE
622
+
623
+ OPTIONS
624
+ -f canonicalize by following every symlink in every component`,return:`RETURN(1) Shell Builtins RETURN(1)
625
+
626
+ NAME
627
+ return - return from a shell function
628
+
629
+ SYNOPSIS
630
+ return [N]
631
+
632
+ DESCRIPTION
633
+ Cause a function to exit with status N (default: last status).`,rm:`RM(1) User Commands RM(1)
634
+
635
+ NAME
636
+ rm - remove files or directories
637
+
638
+ SYNOPSIS
639
+ rm [OPTION]... FILE...
640
+
641
+ OPTIONS
642
+ -r remove directories and their contents recursively`,sed:`SED(1) User Commands SED(1)
643
+
644
+ NAME
645
+ sed - stream editor for filtering and transforming text
646
+
647
+ SYNOPSIS
648
+ sed [OPTION]... {-e script} [FILE]...
649
+
650
+ OPTIONS
651
+ -e SCRIPT add SCRIPT to commands to be executed
652
+ -i edit files in place`,set:`SET(1) Shell Builtins SET(1)
653
+
654
+ NAME
655
+ set - set or unset shell options and positional parameters
656
+
657
+ SYNOPSIS
658
+ set [OPTION]... [ARG]...
659
+ set [NAME=VALUE]...
660
+
661
+ DESCRIPTION
662
+ Display or modify shell variable state.`,shift:`SHIFT(1) Shell Builtins SHIFT(1)
663
+
664
+ NAME
665
+ shift - shift positional parameters
666
+
667
+ SYNOPSIS
668
+ shift [N]
669
+
670
+ DESCRIPTION
671
+ Rename positional parameters by discarding the first N arguments.`,sleep:`SLEEP(1) User Commands SLEEP(1)
672
+
673
+ NAME
674
+ sleep - delay for a specified amount of time
675
+
676
+ SYNOPSIS
677
+ sleep NUMBER
678
+
679
+ DESCRIPTION
680
+ Pause execution for NUMBER seconds.`,sort:`SORT(1) User Commands SORT(1)
681
+
682
+ NAME
683
+ sort - sort lines of text files
684
+
685
+ SYNOPSIS
686
+ sort [OPTION]... [FILE]...
687
+
688
+ OPTIONS
689
+ -r reverse the result of comparisons
690
+ -n compare according to string numerical value
691
+ -u output only the first of an equal run`,source:`SOURCE(1) Shell Builtins SOURCE(1)
692
+
693
+ NAME
694
+ source - execute commands from a file in the current shell
695
+
696
+ SYNOPSIS
697
+ source FILE
698
+ . FILE
699
+
700
+ DESCRIPTION
701
+ Read and execute commands from FILE in the current shell context.`,ssh:`SSH(1) OpenSSH SSH(1)
702
+
703
+ NAME
704
+ ssh - OpenSSH remote login client
705
+
706
+ SYNOPSIS
707
+ ssh [-p port] [user@]hostname [command]
708
+
709
+ DESCRIPTION
710
+ ssh (SSH client) is a program for logging into a remote machine and
711
+ for executing commands on a remote machine.`,stat:`STAT(1) User Commands STAT(1)
712
+
713
+ NAME
714
+ stat - display file status
715
+
716
+ SYNOPSIS
717
+ stat [OPTION]... FILE...
718
+
719
+ OPTIONS
720
+ -c, --format=FORMAT use the specified output format`,su:`SU(1) User Commands SU(1)
721
+
722
+ NAME
723
+ su - run a command with substitute user and group ID
724
+
725
+ SYNOPSIS
726
+ su [OPTION]... [USER]
727
+
728
+ OPTIONS
729
+ - start a login shell
730
+
731
+ DESCRIPTION
732
+ Switch to another user account in the current session.`,sudo:`SUDO(8) User Commands SUDO(8)
733
+
734
+ NAME
735
+ sudo - execute a command as another user
736
+
737
+ SYNOPSIS
738
+ sudo [OPTION]... COMMAND [ARG]...
739
+
740
+ OPTIONS
741
+ -i run login shell as target user
742
+ -u USER run command as USER`,tail:`TAIL(1) User Commands TAIL(1)
743
+
744
+ NAME
745
+ tail - output the last part of files
746
+
747
+ SYNOPSIS
748
+ tail [OPTION]... [FILE]...
749
+
750
+ OPTIONS
751
+ -n, --lines=[+]NUM output the last NUM lines`,tar:`TAR(1) GNU tar Manual TAR(1)
752
+
753
+ NAME
754
+ tar - an archiving utility
755
+
756
+ SYNOPSIS
757
+ tar [OPTION...] [FILE]...
758
+
759
+ DESCRIPTION
760
+ tar saves many files together into a single tape or disk archive,
761
+ and can restore individual files from the archive.
762
+
763
+ OPTIONS
764
+ -c, --create create a new archive
765
+ -x, --extract extract files from an archive
766
+ -z, --gzip filter the archive through gzip
767
+ -f, --file=ARCHIVE use archive file or device ARCHIVE
768
+ -v, --verbose verbosely list files processed
769
+ -t, --list list the contents of an archive`,tee:`TEE(1) User Commands TEE(1)
770
+
771
+ NAME
772
+ tee - read from standard input and write to standard output and files
773
+
774
+ SYNOPSIS
775
+ tee [OPTION]... [FILE]...
776
+
777
+ OPTIONS
778
+ -a append to the given FILEs, do not overwrite`,test:`TEST(1) Shell Builtins TEST(1)
779
+
780
+ NAME
781
+ test - check file types and compare values
782
+
783
+ SYNOPSIS
784
+ test EXPRESSION
785
+ [ EXPRESSION ]
786
+
787
+ DESCRIPTION
788
+ Evaluate conditional expressions for scripts and shell logic.`,touch:`TOUCH(1) User Commands TOUCH(1)
789
+
790
+ NAME
791
+ touch - change file timestamps / create file
792
+
793
+ SYNOPSIS
794
+ touch FILE...
795
+
796
+ DESCRIPTION
797
+ Update access and modification times.
798
+ If FILE does not exist, create an empty file.`,tr:`TR(1) User Commands TR(1)
799
+
800
+ NAME
801
+ tr - translate or delete characters
802
+
803
+ SYNOPSIS
804
+ tr [OPTION]... SET1 [SET2]
805
+
806
+ OPTIONS
807
+ -d delete characters in SET1 instead of translating`,trap:`TRAP(1) Shell Builtins TRAP(1)
808
+
809
+ NAME
810
+ trap - trap signals and other events
811
+
812
+ SYNOPSIS
813
+ trap [ACTION] [SIGNAL]...
814
+
815
+ DESCRIPTION
816
+ Define or clear handlers for shell signals and EXIT.`,true:`TRUE(1) User Commands TRUE(1)
817
+
818
+ NAME
819
+ true - do nothing, successfully
820
+
821
+ SYNOPSIS
822
+ true
823
+
824
+ DESCRIPTION
825
+ Exit with a status code indicating success (0).`,type:`TYPE(1) Shell Builtins TYPE(1)
826
+
827
+ NAME
828
+ type - display how a command name is interpreted
829
+
830
+ SYNOPSIS
831
+ type NAME...
832
+
833
+ DESCRIPTION
834
+ Indicate whether NAME is a shell builtin, alias, or found in PATH.`,uname:`UNAME(1) User Commands UNAME(1)
835
+
836
+ NAME
837
+ uname - print system information
838
+
839
+ SYNOPSIS
840
+ uname [OPTION]...
841
+
842
+ OPTIONS
843
+ -a print all information
844
+ -r print kernel release
845
+ -m print machine hardware name`,uniq:`UNIQ(1) User Commands UNIQ(1)
846
+
847
+ NAME
848
+ uniq - report or omit repeated lines
849
+
850
+ SYNOPSIS
851
+ uniq [OPTION]... [INPUT [OUTPUT]]
852
+
853
+ OPTIONS
854
+ -c prefix lines by the number of occurrences
855
+ -d only print duplicate lines
856
+ -u only print unique lines`,unset:`UNSET(1) Shell Builtins UNSET(1)
857
+
858
+ NAME
859
+ unset - unset values and attributes of shell variables
860
+
861
+ SYNOPSIS
862
+ unset NAME...
863
+
864
+ DESCRIPTION
865
+ Remove one or more shell variables from the current environment.`,uptime:`UPTIME(1) User Commands UPTIME(1)
866
+
867
+ NAME
868
+ uptime - tell how long the system has been running
869
+
870
+ SYNOPSIS
871
+ uptime [OPTION]
872
+
873
+ OPTIONS
874
+ -p show uptime in a pretty format
875
+ -s show system up since time`,wc:`WC(1) User Commands WC(1)
876
+
877
+ NAME
878
+ wc - print newline, word, and byte counts for each file
879
+
880
+ SYNOPSIS
881
+ wc [OPTION]... [FILE]...
882
+
883
+ OPTIONS
884
+ -l print the newline counts
885
+ -w print the word counts
886
+ -c print the byte counts`,wget:`WGET(1) User Commands WGET(1)
887
+
888
+ NAME
889
+ wget - non-interactive network downloader
890
+
891
+ SYNOPSIS
892
+ wget [OPTION]... [URL]...
893
+
894
+ OPTIONS
895
+ -O FILE write documents to FILE
896
+ -P DIR save files to DIR
897
+ -q quiet mode`,which:`WHICH(1) User Commands WHICH(1)
898
+
899
+ NAME
900
+ which - locate a command
901
+
902
+ SYNOPSIS
903
+ which COMMAND...
904
+
905
+ DESCRIPTION
906
+ Print the path of COMMAND found in $PATH.`,whoami:`WHOAMI(1) User Commands WHOAMI(1)
907
+
908
+ NAME
909
+ whoami - print effective user name
910
+
911
+ SYNOPSIS
912
+ whoami
913
+
914
+ DESCRIPTION
915
+ Print the user name associated with the current effective user ID.`,xargs:`XARGS(1) User Commands XARGS(1)
916
+
917
+ NAME
918
+ xargs - build and execute command lines from standard input
919
+
920
+ SYNOPSIS
921
+ xargs [COMMAND [INITIAL-ARGS]]
922
+
923
+ DESCRIPTION
924
+ Read items from stdin and execute COMMAND with those items as arguments.`};var li={gunzip:"gzip"},Qn={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:n,shell:t})=>{let e=n[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let i=e.toLowerCase(),s=li[i]??i,o=Zn[s]??null;return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Xn={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let i=0;i<r.length;i++){let s=Ct(r,i);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let o=N(e,s);D(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var tr={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r.filter(c=>!c.startsWith("-")),[s,o]=i;if(!s||!o)return{stderr:"mv: missing operand",exitCode:1};let a=N(e,s),l=N(e,o);try{if(D(n,a,"mv"),D(n,l,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let c=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${s.split("/").pop()}`:l;return t.vfs.move(a,c),{exitCode:0}}catch(c){return{stderr:`mv: ${c instanceof Error?c.message:String(c)}`,exitCode:1}}}};import*as er from"node:path";var nr={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r[0];if(!i)return{stderr:"nano: missing file operand",exitCode:1};let s=N(e,i);D(n,s,"nano");let o=t.vfs.exists(s)?t.vfs.readFile(s):"",a=er.posix.basename(s)||"buffer",l=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:l,initialContent:o},exitCode:0}}};import{existsSync as cr,readdirSync as ci,readFileSync as ke}from"node:fs";import*as rt from"node:os";import*as ur from"node:path";function ui(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60,s=[];return e>0&&s.push(`${e} day${e>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(i>0||s.length===0)&&s.push(`${i} min${i>1?"s":""}`),s.join(", ")}function rr(n){return`\x1B[${n}m \x1B[0m`}function di(){let n=[40,41,42,43,44,45,46,47].map(rr).join(""),t=[100,101,102,103,104,105,106,107].map(rr).join("");return[n,t]}function sr(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s=e<=1?0:t/(e-1),o=Math.round(r.r+(i.r-r.r)*s),a=Math.round(r.g+(i.g-r.g)*s),l=Math.round(r.b+(i.b-r.b)*s);return`\x1B[38;2;${o};${a};${l}m${n}\x1B[0m`}function mi(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?ir(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return ir(e)+r}function ir(n){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=n.replace(t,"");if(e.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),l=Math.round(r.r+(i.r-r.r)*a),c=Math.round(r.g+(i.g-r.g)*a),u=Math.round(r.b+(i.b-r.b)*a);s+=`\x1B[38;2;${l};${c};${u}m${e[o]}\x1B[0m`}return s}function or(n){return Math.max(0,Math.round(n/(1024*1024)))}function ar(){try{let n=ke("/etc/os-release","utf8");for(let t of n.split(`
925
+ `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function lr(n){try{let t=ke(n,"utf8").split(`
926
+ `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function pi(n){let t=lr("/sys/devices/virtual/dmi/id/sys_vendor"),e=lr("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function fi(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if(cr(t))try{return ke(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function hi(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if(cr(t))try{return ci(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}}function gi(){let n=fi(),t=hi();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function yi(){let n=rt.cpus();if(n.length===0)return"unknown";let t=n[0];if(!t)return"unknown";let e=(t.speed/1e3).toFixed(2);return`${t.model} (${n.length}) @ ${e}GHz`}function Si(n){return!n||n.trim().length===0?"unknown":ur.posix.basename(n.trim())}function wi(n){let t=rt.totalmem(),e=rt.freemem(),r=Math.max(0,t-e),i=n.shellProps,s=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(s)),{user:n.user,host:n.host,osName:i?.os??n.osName??`${ar()??rt.type()} ${rt.arch()}`,kernel:i?.kernel??n.kernel??rt.release(),uptimeSeconds:n.uptimeSeconds??rt.uptime(),packages:n.packages??gi(),shell:Si(n.shell),shellProps:n.shellProps??{kernel:n.kernel??rt.release(),os:n.osName??`${ar()??rt.type()} ${rt.arch()}`,arch:rt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??yi(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??or(r),memoryTotalMiB:n.memoryTotalMiB??or(t)}}function dr(n){let t=wi(n),e=ui(t.uptimeSeconds),r=di(),i=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${pi(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${e}`,`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]],o=Math.max(i.length,s.length),a=[];for(let l=0;l<o;l+=1){let c=i[l]??"",u=s[l]??"";if(u.length>0){let d=sr(c.padEnd(31," "),l,i.length),m=mi(u);a.push(`${d} ${m}`);continue}a.push(sr(c,l,i.length))}return a.join(`
927
+ `)}var mr={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:i})=>r.packageManager.isInstalled("neofetch")?w(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:w(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:dr({user:t,host:e,shell:i.vars.SHELL,shellProps:r.properties,terminal:i.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
118
928
  Hint: install it with: apt install neofetch
119
- `,exitCode:127}};import cr from"node:vm";var se="v18.19.0",ur={node:se,npm:"9.2.0",v8:"10.2.154.26-node.22"};function xi(n,t){let e={version:se,versions:ur,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:s=>(n.push(s),!0)},stderr:{write:s=>(t.push(s),!0)},exit:(s=0)=>{throw new ie(s)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...s)=>n.push(s.map(St).join(" ")),error:(...s)=>t.push(s.map(St).join(" ")),warn:(...s)=>t.push(s.map(St).join(" ")),info:(...s)=>n.push(s.map(St).join(" ")),dir:s=>n.push(St(s))},i=s=>{switch(s){case"path":return{join:(...o)=>o.join("/").replace(/\/+/g,"/"),resolve:(...o)=>`/${o.join("/").replace(/^\/+/,"")}`,dirname:o=>o.split("/").slice(0,-1).join("/")||"/",basename:o=>o.split("/").pop()??"",extname:o=>{let a=o.split("/").pop()??"",l=a.lastIndexOf(".");return l>0?a.slice(l):""},sep:"/",delimiter:":"};case"os":return{platform:()=>"linux",arch:()=>"x64",type:()=>"Linux",hostname:()=>"fortune-vm",homedir:()=>"/root",tmpdir:()=>"/tmp",EOL:`
120
- `};case"util":return{format:(...o)=>o.map(St).join(" "),inspect:o=>St(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${s}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${s}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${s}'`)}};return i.resolve=s=>{throw new Error(`Cannot resolve '${s}'`)},i.cache={},i.extensions={},cr.createContext({console:r,process:e,require:i,Math,JSON,Object,Array,String,Number,Boolean,Symbol,Date,RegExp,Error,TypeError,RangeError,SyntaxError,Promise,Map,Set,WeakMap,WeakSet,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,setTimeout:()=>{},clearTimeout:()=>{},setInterval:()=>{},clearInterval:()=>{},queueMicrotask:()=>{},globalThis:void 0,undefined:void 0,Infinity:1/0,NaN:NaN})}var ie=class{constructor(t){this.code=t}code};function St(n){if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return n;if(typeof n=="function")return`[Function: ${n.name||"(anonymous)"}]`;if(Array.isArray(n))return`[ ${n.map(St).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${St(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function oe(n){let t=[],e=[],r=xi(t,e),i=0;try{let s=cr.runInContext(n,r,{timeout:5e3});s!==void 0&&t.length===0&&t.push(St(s))}catch(s){s instanceof ie?i=s.code:s instanceof Error?(e.push(`${s.name}: ${s.message}`),i=1):(e.push(String(s)),i=1)}return{stdout:t.length?`${t.join(`
929
+ `,exitCode:127}};import pr from"node:vm";var se="v18.19.0",fr={node:se,npm:"9.2.0",v8:"10.2.154.26-node.22"};function bi(n,t){let e={version:se,versions:fr,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:s=>(n.push(s),!0)},stderr:{write:s=>(t.push(s),!0)},exit:(s=0)=>{throw new ie(s)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...s)=>n.push(s.map(St).join(" ")),error:(...s)=>t.push(s.map(St).join(" ")),warn:(...s)=>t.push(s.map(St).join(" ")),info:(...s)=>n.push(s.map(St).join(" ")),dir:s=>n.push(St(s))},i=s=>{switch(s){case"path":return{join:(...o)=>o.join("/").replace(/\/+/g,"/"),resolve:(...o)=>`/${o.join("/").replace(/^\/+/,"")}`,dirname:o=>o.split("/").slice(0,-1).join("/")||"/",basename:o=>o.split("/").pop()??"",extname:o=>{let a=o.split("/").pop()??"",l=a.lastIndexOf(".");return l>0?a.slice(l):""},sep:"/",delimiter:":"};case"os":return{platform:()=>"linux",arch:()=>"x64",type:()=>"Linux",hostname:()=>"fortune-vm",homedir:()=>"/root",tmpdir:()=>"/tmp",EOL:`
930
+ `};case"util":return{format:(...o)=>o.map(St).join(" "),inspect:o=>St(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${s}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${s}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${s}'`)}};return i.resolve=s=>{throw new Error(`Cannot resolve '${s}'`)},i.cache={},i.extensions={},pr.createContext({console:r,process:e,require:i,Math,JSON,Object,Array,String,Number,Boolean,Symbol,Date,RegExp,Error,TypeError,RangeError,SyntaxError,Promise,Map,Set,WeakMap,WeakSet,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,setTimeout:()=>{},clearTimeout:()=>{},setInterval:()=>{},clearInterval:()=>{},queueMicrotask:()=>{},globalThis:void 0,undefined:void 0,Infinity:1/0,NaN:NaN})}var ie=class{constructor(t){this.code=t}code};function St(n){if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return n;if(typeof n=="function")return`[Function: ${n.name||"(anonymous)"}]`;if(Array.isArray(n))return`[ ${n.map(St).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${St(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function oe(n){let t=[],e=[],r=bi(t,e),i=0;try{let s=pr.runInContext(n,r,{timeout:5e3});s!==void 0&&t.length===0&&t.push(St(s))}catch(s){s instanceof ie?i=s.code:s instanceof Error?(e.push(`${s.name}: ${s.message}`),i=1):(e.push(String(s)),i=1)}return{stdout:t.length?`${t.join(`
121
931
  `)}
122
932
  `:"",stderr:e.length?`${e.join(`
123
933
  `)}
124
- `:"",exitCode:i}}function bi(n){let t=n.trim();return!t.includes(`
125
- `)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")?oe(t):oe(`(async () => { ${n} })()`)}var dr={name:"node",description:"JavaScript runtime (virtual)",category:"system",params:["[--version] [-e <expr>] [-p <expr>] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("nodejs"))return{stderr:`bash: node: command not found
934
+ `:"",exitCode:i}}function vi(n){let t=n.trim();return!t.includes(`
935
+ `)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")?oe(t):oe(`(async () => { ${n} })()`)}var hr={name:"node",description:"JavaScript runtime (virtual)",category:"system",params:["[--version] [-e <expr>] [-p <expr>] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("nodejs"))return{stderr:`bash: node: command not found
126
936
  Hint: install it with: apt install nodejs
127
937
  `,exitCode:127};if(w(n,["--version","-v"]))return{stdout:`${se}
128
- `,exitCode:0};if(w(n,["--versions"]))return{stdout:`${JSON.stringify(ur,null,2)}
938
+ `,exitCode:0};if(w(n,["--versions"]))return{stdout:`${JSON.stringify(fr,null,2)}
129
939
  `,exitCode:0};let r=n.findIndex(o=>o==="-e"||o==="--eval");if(r!==-1){let o=n[r+1];if(!o)return{stderr:`node: -e requires an argument
130
940
  `,exitCode:1};let{stdout:a,stderr:l,exitCode:c}=oe(o);return{stdout:a||void 0,stderr:l||void 0,exitCode:c}}let i=n.findIndex(o=>o==="-p"||o==="--print");if(i!==-1){let o=n[i+1];if(!o)return{stderr:`node: -p requires an argument
131
941
  `,exitCode:1};let{stdout:a,stderr:l,exitCode:c}=oe(o);return{stdout:a||(c===0?`
132
- `:void 0),stderr:l||void 0,exitCode:c}}let s=n.find(o=>!o.startsWith("-"));if(s){let o=k(e,s);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${s}': No such file or directory
133
- `,exitCode:1};let a=t.vfs.readFile(o),{stdout:l,stderr:c,exitCode:u}=bi(a);return{stdout:l||void 0,stderr:c||void 0,exitCode:u}}return{stdout:[`Welcome to Node.js ${se}.`,'Type ".exit" to exit the REPL.',"> "].join(`
134
- `),exitCode:0}}};var ae="9.2.0",vi="18.19.0",mr={name:"npm",description:"Node.js package manager (virtual)",category:"system",params:["<command> [args]"],run:({args:n,shell:t})=>{if(!t.packageManager.isInstalled("npm"))return{stderr:`bash: npm: command not found
942
+ `:void 0),stderr:l||void 0,exitCode:c}}let s=n.find(o=>!o.startsWith("-"));if(s){let o=N(e,s);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${s}': No such file or directory
943
+ `,exitCode:1};let a=t.vfs.readFile(o),{stdout:l,stderr:c,exitCode:u}=vi(a);return{stdout:l||void 0,stderr:c||void 0,exitCode:u}}return{stdout:[`Welcome to Node.js ${se}.`,'Type ".exit" to exit the REPL.',"> "].join(`
944
+ `),exitCode:0}}};var ae="9.2.0",xi="18.19.0",gr={name:"npm",description:"Node.js package manager (virtual)",category:"system",params:["<command> [args]"],run:({args:n,shell:t})=>{if(!t.packageManager.isInstalled("npm"))return{stderr:`bash: npm: command not found
135
945
  Hint: install it with: apt install npm
136
946
  `,exitCode:127};if(w(n,["--version","-v"]))return{stdout:`${ae}
137
- `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${ae}', node: '${vi}', v8: '10.2.154.26' }
947
+ `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${ae}', node: '${xi}', v8: '10.2.154.26' }
138
948
  `,exitCode:0};case"install":case"i":case"add":return{stderr:`npm warn: package installation is not available in the virtual runtime.
139
949
  npm warn: This environment simulates npm CLI behaviour only.
140
950
  `,exitCode:1};case"run":case"exec":case"x":return{stderr:`npm error: script execution is not available in the virtual runtime.
@@ -144,82 +954,84 @@ npm warn: This environment simulates npm CLI behaviour only.
144
954
  `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${ae}`,"","Usage: npm <command>","","Commands:"," install (not available in virtual runtime)"," run (not available in virtual runtime)"," exec (not available in virtual runtime)"," list List installed packages"," version Print versions"," --version Print npm version"].join(`
145
955
  `)}
146
956
  `,exitCode:0};default:return{stderr:`npm error: unknown command: ${e}
147
- `,exitCode:1}}}},pr={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?w(n,["--version"])?{stdout:`${ae}
957
+ `,exitCode:1}}}},yr={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?w(n,["--version"])?{stdout:`${ae}
148
958
  `,exitCode:0}:{stderr:`npx: package execution is not available in the virtual runtime.
149
959
  `,exitCode:1}:{stderr:`bash: npx: command not found
150
960
  Hint: install it with: apt install npm
151
- `,exitCode:127}};var fr={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let i=t[0]??n;if(n!=="root"&&n!==i)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(i))return{stderr:`passwd: user '${i}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let s=r.trim().split(`
961
+ `,exitCode:127}};var Sr={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let i=t[0]??n;if(n!=="root"&&n!==i)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(i))return{stderr:`passwd: user '${i}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let s=r.trim().split(`
152
962
  `)[0];return await e.users.setPassword(i,s),{stdout:`passwd: password updated successfully
153
- `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:i},exitCode:0}}};var hr={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=at(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",i=t.get("-c"),s=i?Math.max(1,parseInt(i,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<s;a++){let l=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${r}: icmp_seq=${a} ttl=64 time=${l} ms`)}return o.push(`--- ${r} ping statistics ---`),o.push(`${s} packets transmitted, ${s} received, 0% packet loss`),{stdout:o.join(`
963
+ `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:i},exitCode:0}}};var wr={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=at(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",i=t.get("-c"),s=i?Math.max(1,parseInt(i,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<s;a++){let l=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${r}: icmp_seq=${a} ttl=64 time=${l} ms`)}return o.push(`--- ${r} ping statistics ---`),o.push(`${s} packets transmitted, ${s} received, 0% packet loss`),{stdout:o.join(`
154
964
  `),exitCode:0}}};function Ci(n,t){let e=0,r="",i=0;for(;i<n.length;){if(n[i]==="\\"&&i+1<n.length)switch(n[i+1]){case"n":r+=`
155
- `,i+=2;continue;case"t":r+=" ",i+=2;continue;case"r":r+="\r",i+=2;continue;case"\\":r+="\\",i+=2;continue;case"a":r+="\x07",i+=2;continue;case"b":r+="\b",i+=2;continue;case"f":r+="\f",i+=2;continue;case"v":r+="\v",i+=2;continue;default:r+=n[i],i++;continue}if(n[i]==="%"&&i+1<n.length){let s=i+1,o=!1;n[s]==="-"&&(o=!0,s++);let a=!1;n[s]==="0"&&(a=!0,s++);let l=0;for(;s<n.length&&/\d/.test(n[s]);)l=l*10+parseInt(n[s],10),s++;let c=-1;if(n[s]===".")for(s++,c=0;s<n.length&&/\d/.test(n[s]);)c=c*10+parseInt(n[s],10),s++;let u=n[s],d=t[e++]??"",m=(p,h=" ")=>{if(l<=0||p.length>=l)return p;let y=h.repeat(l-p.length);return o?p+y:y+p};switch(u){case"s":{let p=String(d);c>=0&&(p=p.slice(0,c)),r+=m(p);break}case"d":case"i":r+=m(String(parseInt(d,10)||0),a?"0":" ");break;case"f":{let p=c>=0?c:6;r+=m((parseFloat(d)||0).toFixed(p));break}case"o":r+=m((parseInt(d,10)||0).toString(8),a?"0":" ");break;case"x":r+=m((parseInt(d,10)||0).toString(16),a?"0":" ");break;case"X":r+=m((parseInt(d,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[i],i++;continue}i=s+1;continue}r+=n[i],i++}return r}var gr={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:Ci(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var yr={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:n,shell:t,args:e})=>{let r=t.users.listActiveSessions(),i=w(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),s=w(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(i){let u=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],d=1e3;for(let m of r){let p=m.username.padEnd(10).slice(0,10),h=(Math.random()*.5).toFixed(1),y=Math.floor(Math.random()*2e4+5e3),f=Math.floor(Math.random()*5e3+1e3);u.push(`${p} ${String(d).padStart(6)} 0.0 ${h.padStart(4)} ${String(y).padStart(6)} ${String(f).padStart(5)} ${m.tty.padEnd(8)} Ss 00:00 0:00 bash`),d++}return u.push(`root ${String(d).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:u.join(`
965
+ `,i+=2;continue;case"t":r+=" ",i+=2;continue;case"r":r+="\r",i+=2;continue;case"\\":r+="\\",i+=2;continue;case"a":r+="\x07",i+=2;continue;case"b":r+="\b",i+=2;continue;case"f":r+="\f",i+=2;continue;case"v":r+="\v",i+=2;continue;default:r+=n[i],i++;continue}if(n[i]==="%"&&i+1<n.length){let s=i+1,o=!1;n[s]==="-"&&(o=!0,s++);let a=!1;n[s]==="0"&&(a=!0,s++);let l=0;for(;s<n.length&&/\d/.test(n[s]);)l=l*10+parseInt(n[s],10),s++;let c=-1;if(n[s]===".")for(s++,c=0;s<n.length&&/\d/.test(n[s]);)c=c*10+parseInt(n[s],10),s++;let u=n[s],d=t[e++]??"",m=(p,h=" ")=>{if(l<=0||p.length>=l)return p;let y=h.repeat(l-p.length);return o?p+y:y+p};switch(u){case"s":{let p=String(d);c>=0&&(p=p.slice(0,c)),r+=m(p);break}case"d":case"i":r+=m(String(parseInt(d,10)||0),a?"0":" ");break;case"f":{let p=c>=0?c:6;r+=m((parseFloat(d)||0).toFixed(p));break}case"o":r+=m((parseInt(d,10)||0).toString(8),a?"0":" ");break;case"x":r+=m((parseInt(d,10)||0).toString(16),a?"0":" ");break;case"X":r+=m((parseInt(d,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[i],i++;continue}i=s+1;continue}r+=n[i],i++}return r}var br={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:Ci(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var vr={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:n,shell:t,args:e})=>{let r=t.users.listActiveSessions(),i=w(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),s=w(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(i){let u=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],d=1e3;for(let m of r){let p=m.username.padEnd(10).slice(0,10),h=(Math.random()*.5).toFixed(1),y=Math.floor(Math.random()*2e4+5e3),f=Math.floor(Math.random()*5e3+1e3);u.push(`${p} ${String(d).padStart(6)} 0.0 ${h.padStart(4)} ${String(y).padStart(6)} ${String(f).padStart(5)} ${m.tty.padEnd(8)} Ss 00:00 0:00 bash`),d++}return u.push(`root ${String(d).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:u.join(`
156
966
  `),exitCode:0}}let a=[" PID TTY TIME CMD"],l=1e3;for(let c of r)!s&&c.username!==n||(a.push(`${String(l).padStart(5)} ${c.tty.padEnd(12)} 00:00:00 ${c.username===n?"bash":`bash (${c.username})`}`),l++);return a.push(`${String(l).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
157
- `),exitCode:0}}};var Sr={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var $i="Python 3.11.2";var le="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",g={__pytype__:"none"};function K(n=[]){return{__pytype__:"dict",data:new Map(n)}}function Ee(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function H(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function _t(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function wt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Ae(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function Tt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function vt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function tt(n){return n===null||vt(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?`'${n.replace(/'/g,"\\'")}'`:Array.isArray(n)?`[${n.map(tt).join(", ")}]`:H(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${tt(e)}`).join(", ")}}`:_t(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:wt(n)?`<function ${n.name} at 0x...>`:Ae(n)?`<class '${n.name}'>`:Tt(n)?`<${n.cls.name} object at 0x...>`:String(n)}function R(n){return n===null||vt(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?n:Array.isArray(n)?`[${n.map(tt).join(", ")}]`:H(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${tt(e)}`).join(", ")}}`:_t(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:tt(n)}function dt(n){return n===null||vt(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:H(n)?n.data.size>0:_t(n)?xr(n)>0:!0}function xr(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function Pi(n){let t=[];for(let e=n.start;(n.step>0?e<n.stop:e>n.stop)&&(t.push(e),!(t.length>1e4));e+=n.step);return t}function X(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(_t(n))return Pi(n);if(H(n))return[...n.data.keys()];throw new q("TypeError",`'${Mt(n)}' object is not iterable`)}function Mt(n){return n===null||vt(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":H(n)?"dict":_t(n)?"range":wt(n)?"function":Ae(n)?"type":Tt(n)?n.cls.name:"object"}var q=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Nt=class{constructor(t){this.value=t}value},Ut=class{},Bt=class{},Ot=class{constructor(t){this.code=t}code};function ki(n){let t=new Map,e=K([["sep","/"],["linesep",`
158
- `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??g:g,path:K([["join",g],["exists",g],["dirname",g],["basename",g]]),listdir:()=>[]},t.set("__builtins__",g),t.set("__name__","__main__"),t.set("__cwd__",n),t}function Mi(n){let t=K([["sep","/"],["curdir","."]]),e=K([["sep","/"],["linesep",`
159
- `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function Ei(){return K([["version",le],["version_info",K([["major",3],["minor",11],["micro",2]].map(([n,t])=>[n,t]))],["platform","linux"],["executable","/usr/bin/python3"],["prefix","/usr"],["path",["/usr/lib/python3.11","/usr/lib/python3.11/lib-dynload"]],["argv",[""]],["maxsize",9007199254740991]])}function Ai(){return K([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",g],["floor",g],["ceil",g],["log",g],["pow",g],["sin",g],["cos",g],["tan",g],["fabs",g],["factorial",g]])}function Fi(){return K([["dumps",g],["loads",g]])}function Ni(){return K([["match",g],["search",g],["findall",g],["sub",g],["split",g],["compile",g]])}var wr={os:Mi,sys:()=>Ei(),math:()=>Ai(),json:()=>Fi(),re:()=>Ni(),random:()=>K([["random",g],["randint",g],["choice",g],["shuffle",g]]),time:()=>K([["time",g],["sleep",g],["ctime",g]]),datetime:()=>K([["datetime",g],["date",g],["timedelta",g]]),collections:()=>K([["Counter",g],["defaultdict",g],["OrderedDict",g]]),itertools:()=>K([["chain",g],["product",g],["combinations",g],["permutations",g]]),functools:()=>K([["reduce",g],["partial",g],["lru_cache",g]]),string:()=>K([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},ce=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
967
+ `),exitCode:0}}};var xr={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var $i="Python 3.11.2";var le="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",g={__pytype__:"none"};function K(n=[]){return{__pytype__:"dict",data:new Map(n)}}function Ie(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function H(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function Rt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function wt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Ae(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function Vt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function xt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function tt(n){return n===null||xt(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?`'${n.replace(/'/g,"\\'")}'`:Array.isArray(n)?`[${n.map(tt).join(", ")}]`:H(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${tt(e)}`).join(", ")}}`:Rt(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:wt(n)?`<function ${n.name} at 0x...>`:Ae(n)?`<class '${n.name}'>`:Vt(n)?`<${n.cls.name} object at 0x...>`:String(n)}function R(n){return n===null||xt(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?n:Array.isArray(n)?`[${n.map(tt).join(", ")}]`:H(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${tt(e)}`).join(", ")}}`:Rt(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:tt(n)}function dt(n){return n===null||xt(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:H(n)?n.data.size>0:Rt(n)?$r(n)>0:!0}function $r(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function Pi(n){let t=[];for(let e=n.start;(n.step>0?e<n.stop:e>n.stop)&&(t.push(e),!(t.length>1e4));e+=n.step);return t}function X(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(Rt(n))return Pi(n);if(H(n))return[...n.data.keys()];throw new Y("TypeError",`'${Et(n)}' object is not iterable`)}function Et(n){return n===null||xt(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":H(n)?"dict":Rt(n)?"range":wt(n)?"function":Ae(n)?"type":Vt(n)?n.cls.name:"object"}var Y=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Ft=class{constructor(t){this.value=t}value},zt=class{},Bt=class{},Wt=class{constructor(t){this.code=t}code};function Ni(n){let t=new Map,e=K([["sep","/"],["linesep",`
968
+ `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??g:g,path:K([["join",g],["exists",g],["dirname",g],["basename",g]]),listdir:()=>[]},t.set("__builtins__",g),t.set("__name__","__main__"),t.set("__cwd__",n),t}function Ei(n){let t=K([["sep","/"],["curdir","."]]),e=K([["sep","/"],["linesep",`
969
+ `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function Mi(){return K([["version",le],["version_info",K([["major",3],["minor",11],["micro",2]].map(([n,t])=>[n,t]))],["platform","linux"],["executable","/usr/bin/python3"],["prefix","/usr"],["path",["/usr/lib/python3.11","/usr/lib/python3.11/lib-dynload"]],["argv",[""]],["maxsize",9007199254740991]])}function ki(){return K([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",g],["floor",g],["ceil",g],["log",g],["pow",g],["sin",g],["cos",g],["tan",g],["fabs",g],["factorial",g]])}function Ii(){return K([["dumps",g],["loads",g]])}function Ai(){return K([["match",g],["search",g],["findall",g],["sub",g],["split",g],["compile",g]])}var Cr={os:Ei,sys:()=>Mi(),math:()=>ki(),json:()=>Ii(),re:()=>Ai(),random:()=>K([["random",g],["randint",g],["choice",g],["shuffle",g]]),time:()=>K([["time",g],["sleep",g],["ctime",g]]),datetime:()=>K([["datetime",g],["date",g],["timedelta",g]]),collections:()=>K([["Counter",g],["defaultdict",g],["OrderedDict",g]]),itertools:()=>K([["chain",g],["product",g],["combinations",g],["permutations",g]]),functools:()=>K([["reduce",g],["partial",g],["lru_cache",g]]),string:()=>K([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},ce=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
160
970
  `)+(this.output.length?`
161
971
  `:"")}getStderr(){return this.stderr.join(`
162
972
  `)+(this.stderr.length?`
163
973
  `:"")}splitArgs(t){let e=[],r=0,i="",s=!1,o="";for(let a=0;a<t.length;a++){let l=t[a];s?(i+=l,l===o&&t[a-1]!=="\\"&&(s=!1)):l==='"'||l==="'"?(s=!0,o=l,i+=l):"([{".includes(l)?(r++,i+=l):")]}".includes(l)?(r--,i+=l):l===","&&r===0?(e.push(i.trim()),i=""):i+=l}return i.trim()&&e.push(i.trim()),e}pyEval(t,e){if(t=t.trim(),!t||t==="None")return g;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return g;if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d*$/.test(t))return parseFloat(t);if(/^0x[0-9a-fA-F]+$/.test(t))return parseInt(t,16);if(/^0o[0-7]+$/.test(t))return parseInt(t.slice(2),8);if(/^('''[\s\S]*'''|"""[\s\S]*""")$/.test(t))return t.slice(3,-3);if(/^(['"])(.*)\1$/s.test(t))return t.slice(1,-1).replace(/\\n/g,`
164
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let c=r[2];return c=c.replace(/\{([^{}]+)\}/g,(u,d)=>{try{return R(this.pyEval(d.trim(),e))}catch{return`{${d}}`}}),c}let i=t.match(/^b(['"])(.*)\1$/s);if(i)return i[2];if(t.startsWith("[")&&t.endsWith("]")){let c=t.slice(1,-1).trim();if(!c)return[];let u=c.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(u){let[,d,m,p,h]=u,y=X(this.pyEval(p.trim(),e)),f=[];for(let S of y){let F=new Map(e);F.set(m,S),!(h&&!dt(this.pyEval(h,F)))&&f.push(this.pyEval(d.trim(),F))}return f}return this.splitArgs(c).map(d=>this.pyEval(d,e))}if(t.startsWith("(")&&t.endsWith(")")){let c=t.slice(1,-1).trim();if(!c)return[];let u=this.splitArgs(c);return u.length===1&&!c.endsWith(",")?this.pyEval(u[0],e):u.map(d=>this.pyEval(d,e))}if(t.startsWith("{")&&t.endsWith("}")){let c=t.slice(1,-1).trim();if(!c)return K();let u=K();for(let d of this.splitArgs(c)){let m=d.indexOf(":");if(m===-1)continue;let p=R(this.pyEval(d.slice(0,m).trim(),e)),h=this.pyEval(d.slice(m+1).trim(),e);u.data.set(p,h)}return u}let s=t.match(/^not\s+(.+)$/);if(s)return!dt(this.pyEval(s[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let c of o){let u=this.tryBinaryOp(t,c,e);if(u!==void 0)return u}if(t.startsWith("-")){let c=this.pyEval(t.slice(1),e);if(typeof c=="number")return-c}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let c=this.findMatchingBracket(t,"[");if(c!==-1){let u=this.pyEval(t.slice(0,c),e),d=t.slice(c+1,-1);return this.subscript(u,d,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,c,u]=a,d=(u?.trim()?this.splitArgs(u):[]).map(m=>this.pyEval(m,e));return this.callBuiltin(c,d,e)}let l=this.findDotAccess(t);if(l){let{objExpr:c,attr:u,callPart:d}=l,m=this.pyEval(c,e);if(d!==void 0){let p=d.slice(1,-1),h=p.trim()?this.splitArgs(p).map(y=>this.pyEval(y,e)):[];return this.callMethod(m,u,h,e)}return this.getAttr(m,u,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new q("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let c=t.split("."),u=e.get(c[0])??(()=>{throw new q("NameError",`name '${c[0]}' is not defined`)})();for(let d of c.slice(1))u=this.getAttr(u,d,e);return u}return g}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",i=0;for(let s=t.length-1;s>=0;s--)if(t[s]===r&&i++,t[s]===e&&(i--,i===0))return s;return-1}findDotAccess(t){let e=0,r=!1,i="";for(let s=t.length-1;s>0;s--){let o=t[s];if(r){o===i&&t[s-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,i=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,s).trim(),c=t.slice(s+1).match(/^(\w+)(\([\s\S]*\))?$/);if(c&&!/^-?\d+$/.test(a))return{objExpr:a,attr:c[1],callPart:c[2]}}return null}tryBinaryOp(t,e,r){let i=0,s=!1,o="";for(let a=t.length-1;a>=0;a--){let l=t[a];if(s){l===o&&t[a-1]!=="\\"&&(s=!1);continue}if(l==='"'||l==="'"){s=!0,o=l;continue}if(")]}".includes(l)){i++;continue}if("([{".includes(l)){i--;continue}if(i===0){for(let c of e)if(t.slice(a,a+c.length)===c){if(c==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let u=t[a-1],d=t[a+c.length];if(/^[a-z]/.test(c)&&(u&&/\w/.test(u)||d&&/\w/.test(d)))continue;let p=t.slice(0,a).trim(),h=t.slice(a+c.length).trim();if(!p||!h)continue;return this.applyBinaryOp(c,p,h,r)}}}}applyBinaryOp(t,e,r,i){if(t==="and"){let a=this.pyEval(e,i);return dt(a)?this.pyEval(r,i):a}if(t==="or"){let a=this.pyEval(e,i);return dt(a)?a:this.pyEval(r,i)}let s=this.pyEval(e,i),o=this.pyEval(r,i);switch(t){case"+":return typeof s=="string"&&typeof o=="string"?s+o:Array.isArray(s)&&Array.isArray(o)?[...s,...o]:s+o;case"-":return s-o;case"*":if(typeof s=="string"&&typeof o=="number")return s.repeat(o);if(Array.isArray(s)&&typeof o=="number"){let a=[];for(let l=0;l<o;l++)a.push(...s);return a}return s*o;case"/":{if(o===0)throw new q("ZeroDivisionError","division by zero");return s/o}case"//":{if(o===0)throw new q("ZeroDivisionError","integer division or modulo by zero");return Math.floor(s/o)}case"%":{if(typeof s=="string")return this.pyStringFormat(s,Array.isArray(o)?o:[o]);if(o===0)throw new q("ZeroDivisionError","integer division or modulo by zero");return s%o}case"**":return s**o;case"==":return tt(s)===tt(o)||s===o;case"!=":return tt(s)!==tt(o)&&s!==o;case"<":return s<o;case"<=":return s<=o;case">":return s>o;case">=":return s>=o;case"in":return this.pyIn(o,s);case"not in":return!this.pyIn(o,s);case"is":return s===o||vt(s)&&vt(o);case"is not":return!(s===o||vt(s)&&vt(o))}return g}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>tt(r)===tt(e)):H(t)?t.data.has(R(e)):!1}subscript(t,e,r){if(e.includes(":")){let s=e.split(":").map(l=>l.trim()),o=s[0]?this.pyEval(s[0],r):void 0,a=s[1]?this.pyEval(s[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):g}let i=this.pyEval(e,r);if(Array.isArray(t)){let s=i;return s<0&&(s=t.length+s),t[s]??g}if(typeof t=="string"){let s=i;return s<0&&(s=t.length+s),t[s]??g}if(H(t))return t.data.get(R(i))??g;throw new q("TypeError",`'${Mt(t)}' is not subscriptable`)}getAttr(t,e,r){return H(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:g:Tt(t)?t.attrs.get(e)??g:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??g:g}callMethod(t,e,r,i){if(typeof t=="string")switch(e){case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();case"strip":return(r[0]?t.replace(new RegExp(`[${r[0]}]+`,"g"),""):t).trim();case"lstrip":return t.trimStart();case"rstrip":return t.trimEnd();case"split":return t.split(typeof r[0]=="string"?r[0]:/\s+/).filter((s,o)=>o>0||s!=="");case"splitlines":return t.split(`
165
- `);case"join":return X(r[0]??[]).map(R).join(t);case"replace":return t.replaceAll(R(r[0]??""),R(r[1]??""));case"startswith":return t.startsWith(R(r[0]??""));case"endswith":return t.endsWith(R(r[0]??""));case"find":return t.indexOf(R(r[0]??""));case"index":{let s=t.indexOf(R(r[0]??""));if(s===-1)throw new q("ValueError","substring not found");return s}case"count":return t.split(R(r[0]??"")).length-1;case"format":return this.pyStringFormat(t,r);case"encode":return t;case"decode":return t;case"isdigit":return/^\d+$/.test(t);case"isalpha":return/^[a-zA-Z]+$/.test(t);case"isalnum":return/^[a-zA-Z0-9]+$/.test(t);case"isspace":return/^\s+$/.test(t);case"isupper":return t===t.toUpperCase()&&t!==t.toLowerCase();case"islower":return t===t.toLowerCase()&&t!==t.toUpperCase();case"center":{let s=r[0]??0,o=R(r[1]??" ");return t.padStart(Math.floor((s+t.length)/2),o).padEnd(s,o)}case"ljust":return t.padEnd(r[0]??0,R(r[1]??" "));case"rjust":return t.padStart(r[0]??0,R(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,s=>s.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(s=>s===s.toUpperCase()?s.toLowerCase():s.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??g),g;case"extend":for(let s of X(r[0]??[]))t.push(s);return g;case"insert":return t.splice(r[0]??0,0,r[1]??g),g;case"pop":{let s=r[0]!==void 0?r[0]:-1,o=s<0?t.length+s:s;return t.splice(o,1)[0]??g}case"remove":{let s=t.findIndex(o=>tt(o)===tt(r[0]??g));return s!==-1&&t.splice(s,1),g}case"index":{let s=t.findIndex(o=>tt(o)===tt(r[0]??g));if(s===-1)throw new q("ValueError","is not in list");return s}case"count":return t.filter(s=>tt(s)===tt(r[0]??g)).length;case"sort":return t.sort((s,o)=>typeof s=="number"&&typeof o=="number"?s-o:R(s).localeCompare(R(o))),g;case"reverse":return t.reverse(),g;case"copy":return[...t];case"clear":return t.splice(0),g}if(H(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([s,o])=>[s,o]);case"get":return t.data.get(R(r[0]??""))??r[1]??g;case"update":{if(H(r[0]??g))for(let[s,o]of r[0].data)t.data.set(s,o);return g}case"pop":{let s=R(r[0]??""),o=t.data.get(s)??r[1]??g;return t.data.delete(s),o}case"clear":return t.data.clear(),g;case"copy":return K([...t.data.entries()]);case"setdefault":{let s=R(r[0]??"");return t.data.has(s)||t.data.set(s,r[1]??g),t.data.get(s)??g}}if(H(t)&&t.data.has("name")&&t.data.get("name")==="posix")switch(e){case"getcwd":return this.cwd;case"getenv":return typeof r[0]=="string"?process.env[r[0]]??r[1]??g:g;case"listdir":return[];case"path":return t}if(H(t))switch(e){case"join":return r.map(R).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return R(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return R(r[0]??"").split("/").pop()??"";case"abspath":return R(r[0]??"");case"splitext":{let s=R(r[0]??""),o=s.lastIndexOf(".");return o>0?[s.slice(0,o),s.slice(o)]:[s,""]}case"isfile":return!1;case"isdir":return!1}if(H(t)&&t.data.has("version")&&t.data.get("version")===le&&e==="exit")throw new Ot(r[0]??0);if(H(t)){let s={sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil,fabs:Math.abs,log:Math.log,log2:Math.log2,log10:Math.log10,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,pow:Math.pow,exp:Math.exp,hypot:Math.hypot};if(e in s){let o=s[e];return o(...r.map(a=>a))}if(e==="factorial"){let o=r[0]??0,a=1;for(;o>1;)a*=o--;return a}if(e==="gcd"){let o=Math.abs(r[0]??0),a=Math.abs(r[1]??0);for(;a;)[o,a]=[a,o%a];return o}}if(H(t)){if(e==="dumps"){let s=H(r[1]??g)?r[1]:void 0,o=s?s.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??g),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(R(r[0]??"")))}if(Tt(t)){let s=t.attrs.get(e)??t.cls.methods.get(e)??g;if(wt(s)){let o=new Map(s.closure);return o.set("self",t),s.params.slice(1).forEach((a,l)=>o.set(a,r[l]??g)),this.execBlock(s.body,o)}}throw new q("AttributeError",`'${Mt(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(i,s)=>{if(s==="%")return"%";let o=e[r++];switch(s){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return R(o??g);case"r":return tt(o??g);default:return String(o)}})}pyToJs(t){return vt(t)?null:H(t)?Object.fromEntries([...t.data.entries()].map(([e,r])=>[e,this.pyToJs(r)])):Array.isArray(t)?t.map(e=>this.pyToJs(e)):t}jsToPy(t){return t==null?g:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?K(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):g}callBuiltin(t,e,r){if(r.has(t)){let i=r.get(t)??g;return wt(i)?this.callFunc(i,e,r):Ae(i)?this.instantiate(i,e,r):i}switch(t){case"print":return this.output.push(e.map(R).join(" ")+`
166
- `.replace(/\\n/g,"")),g;case"input":return this.output.push(R(e[0]??"")),"";case"int":{if(e.length===0)return 0;let i=e[1]??10,s=parseInt(R(e[0]??0),i);return Number.isNaN(s)?(()=>{throw new q("ValueError","invalid literal for int()")})():s}case"float":{if(e.length===0)return 0;let i=parseFloat(R(e[0]??0));return Number.isNaN(i)?(()=>{throw new q("ValueError","could not convert to float")})():i}case"str":return e.length===0?"":R(e[0]??g);case"bool":return e.length===0?!1:dt(e[0]??g);case"list":return e.length===0?[]:X(e[0]??[]);case"tuple":return e.length===0?[]:X(e[0]??[]);case"set":return e.length===0?[]:[...new Set(X(e[0]??[]).map(tt))].map(i=>X(e[0]??[]).find(o=>tt(o)===i)??g);case"dict":return e.length===0?K():H(e[0]??g)?e[0]:K();case"bytes":return typeof e[0]=="string"?e[0]:R(e[0]??"");case"bytearray":return e.length===0?"":R(e[0]??"");case"type":return e.length===1?`<class '${Mt(e[0]??g)}'>`:g;case"isinstance":return Mt(e[0]??g)===R(e[1]??"");case"issubclass":return!1;case"callable":return wt(e[0]??g);case"hasattr":return H(e[0]??g)?e[0].data.has(R(e[1]??"")):!1;case"getattr":return H(e[0]??g)?e[0].data.get(R(e[1]??""))??e[2]??g:e[2]??g;case"setattr":return H(e[0]??g)&&e[0].data.set(R(e[1]??""),e[2]??g),g;case"len":{let i=e[0]??g;if(typeof i=="string"||Array.isArray(i))return i.length;if(H(i))return i.data.size;if(_t(i))return xr(i);throw new q("TypeError",`object of type '${Mt(i)}' has no len()`)}case"range":return e.length===1?Ee(0,e[0]):e.length===2?Ee(e[0],e[1]):Ee(e[0],e[1],e[2]);case"enumerate":{let i=e[1]??0;return X(e[0]??[]).map((s,o)=>[o+i,s])}case"zip":{let i=e.map(X),s=Math.min(...i.map(o=>o.length));return Array.from({length:s},(o,a)=>i.map(l=>l[a]??g))}case"map":{let i=e[0]??g;return X(e[1]??[]).map(s=>wt(i)?this.callFunc(i,[s],r):g)}case"filter":{let i=e[0]??g;return X(e[1]??[]).filter(s=>wt(i)?dt(this.callFunc(i,[s],r)):dt(s))}case"reduce":{let i=e[0]??g,s=X(e[1]??[]);if(s.length===0)return e[2]??g;let o=e[2]!==void 0?e[2]:s[0];for(let a of e[2]!==void 0?s:s.slice(1))o=wt(i)?this.callFunc(i,[o,a],r):g;return o}case"sorted":{let i=[...X(e[0]??[])],s=e[1]??g,o=H(s)?s.data.get("key")??g:s;return i.sort((a,l)=>{let c=wt(o)?this.callFunc(o,[a],r):a,u=wt(o)?this.callFunc(o,[l],r):l;return typeof c=="number"&&typeof u=="number"?c-u:R(c).localeCompare(R(u))}),i}case"reversed":return[...X(e[0]??[])].reverse();case"any":return X(e[0]??[]).some(dt);case"all":return X(e[0]??[]).every(dt);case"sum":return X(e[0]??[]).reduce((i,s)=>i+s,e[1]??0);case"max":return(e.length===1?X(e[0]??[]):e).reduce((s,o)=>s>=o?s:o);case"min":return(e.length===1?X(e[0]??[]):e).reduce((s,o)=>s<=o?s:o);case"abs":return Math.abs(e[0]??0);case"round":return e[1]!==void 0?parseFloat(e[0].toFixed(e[1])):Math.round(e[0]??0);case"divmod":{let i=e[0],s=e[1];return[Math.floor(i/s),i%s]}case"pow":return e[0]**e[1];case"hex":return`0x${e[0].toString(16)}`;case"oct":return`0o${e[0].toString(8)}`;case"bin":return`0b${e[0].toString(2)}`;case"ord":return R(e[0]??"").charCodeAt(0);case"chr":return String.fromCharCode(e[0]??0);case"id":return Math.floor(Math.random()*4294967295);case"hash":return typeof e[0]=="number"?e[0]:R(e[0]??"").split("").reduce((i,s)=>i*31+s.charCodeAt(0)|0,0);case"open":throw new q("PermissionError","open() not available in virtual runtime");case"repr":return tt(e[0]??g);case"iter":return e[0]??g;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new q("StopIteration","")})();case"vars":return K([...r.entries()].map(([i,s])=>[i,s]));case"globals":return K([...r.entries()].map(([i,s])=>[i,s]));case"locals":return K([...r.entries()].map(([i,s])=>[i,s]));case"dir":{if(e.length===0)return[...r.keys()];let i=e[0]??g;return typeof i=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(i)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:H(i)?["keys","values","items","get","update","pop","clear","copy","setdefault"]:[]}case"Exception":case"ValueError":case"TypeError":case"KeyError":case"IndexError":case"AttributeError":case"NameError":case"RuntimeError":case"StopIteration":case"NotImplementedError":case"OSError":case"IOError":throw new q(t,R(e[0]??""));case"exec":return this.execScript(R(e[0]??""),r),g;case"eval":return this.pyEval(R(e[0]??""),r);default:throw new q("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let i=new Map(t.closure);t.params.forEach((s,o)=>{if(s.startsWith("*")){i.set(s.slice(1),e.slice(o));return}i.set(s,e[o]??g)});try{return this.execBlock(t.body,i)}catch(s){if(s instanceof Nt)return s.value;throw s}}instantiate(t,e,r){let i={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(i,"__init__",e,r),i}execScript(t,e){let r=t.split(`
167
- `);this.execLines(r,0,e)}execLines(t,e,r){let i=e;for(;i<t.length;){let s=t[i];if(!s.trim()||s.trim().startsWith("#")){i++;continue}i=this.execStatement(t,i,r)}return i}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof Nt)return r.value;throw r}return g}getIndent(t){let e=0;for(let r of t)if(r===" ")e++;else if(r===" ")e+=4;else break;return e}collectBlock(t,e,r){let i=[];for(let s=e;s<t.length;s++){let o=t[s];if(!o.trim()){i.push("");continue}if(this.getIndent(o)<=r)break;i.push(o.slice(r+4))}return i}execStatement(t,e,r){let i=t[e],s=i.trim(),o=this.getIndent(i);if(s==="pass")return e+1;if(s==="break")throw new Ut;if(s==="continue")throw new Bt;let a=s.match(/^return(?:\s+(.+))?$/);if(a)throw new Nt(a[1]?this.pyEval(a[1],r):g);let l=s.match(/^raise(?:\s+(.+))?$/);if(l){if(l[1]){let b=this.pyEval(l[1],r);throw new q(typeof b=="string"?b:Mt(b),R(b))}throw new q("RuntimeError","")}let c=s.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(c){if(!dt(this.pyEval(c[1],r)))throw new q("AssertionError",c[2]?R(this.pyEval(c[2],r)):"");return e+1}let u=s.match(/^del\s+(.+)$/);if(u)return r.delete(u[1].trim()),e+1;let d=s.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(d){let[,b,M]=d,V=wr[b];if(V){let P=V(this.cwd);this.modules.set(b,P),r.set(M??b,P)}return e+1}let m=s.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(m){let[,b,M]=m,V=wr[b];if(V){let P=V(this.cwd);if(M?.trim()==="*")for(let[$,I]of P.data)r.set($,I);else for(let $ of M.split(",").map(I=>I.trim()))r.set($,P.data.get($)??g)}return e+1}let p=s.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,b,M]=p,V=M.split(",").map(I=>I.trim()).filter(Boolean),P=this.collectBlock(t,e+1,o),$={__pytype__:"func",name:b,params:V,body:P,closure:new Map(r)};return r.set(b,$),e+1+P.length}let h=s.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(h){let[,b,M]=h,V=M?M.split(",").map(Y=>Y.trim()):[],P=this.collectBlock(t,e+1,o),$={__pytype__:"class",name:b,methods:new Map,bases:V},I=0;for(;I<P.length;){let j=P[I].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(j){let[,Q,xt]=j,ht=xt.split(",").map(_=>_.trim()).filter(Boolean),bt=this.collectBlock(P,I+1,0);$.methods.set(Q,{__pytype__:"func",name:Q,params:ht,body:bt,closure:new Map(r)}),I+=1+bt.length}else I++}return r.set(b,$),e+1+P.length}if(s.startsWith("if ")&&s.endsWith(":")){let b=s.slice(3,-1).trim(),M=this.collectBlock(t,e+1,o),V=M.length+1;if(dt(this.pyEval(b,r))){this.execBlock(M,new Map(r).also?.(I=>{for(let[Y,j]of r)I.set(Y,j)})??r),this.runBlockInScope(M,r);let $=e+1+M.length;for(;$<t.length;){let I=t[$].trim();if(this.getIndent(t[$])<o||!I.startsWith("elif")&&!I.startsWith("else"))break;let Y=this.collectBlock(t,$+1,o);$+=1+Y.length}return $}let P=e+1+M.length;for(;P<t.length;){let $=t[P],I=$.trim();if(this.getIndent($)!==o)break;let Y=I.match(/^elif\s+(.+):$/);if(Y){let j=this.collectBlock(t,P+1,o);if(dt(this.pyEval(Y[1],r))){for(this.runBlockInScope(j,r),P+=1+j.length;P<t.length;){let Q=t[P].trim();if(this.getIndent(t[P])!==o||!Q.startsWith("elif")&&!Q.startsWith("else"))break;let xt=this.collectBlock(t,P+1,o);P+=1+xt.length}return P}P+=1+j.length;continue}if(I==="else:"){let j=this.collectBlock(t,P+1,o);return this.runBlockInScope(j,r),P+1+j.length}break}return P}let y=s.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(y){let[,b,M]=y,V=X(this.pyEval(M.trim(),r)),P=this.collectBlock(t,e+1,o),$=[],I=e+1+P.length;I<t.length&&t[I]?.trim()==="else:"&&($=this.collectBlock(t,I+1,o),I+=1+$.length);let Y=!1;for(let j of V){if(b.includes(",")){let Q=b.split(",").map(ht=>ht.trim()),xt=Array.isArray(j)?j:[j];Q.forEach((ht,bt)=>r.set(ht,xt[bt]??g))}else r.set(b.trim(),j);try{this.runBlockInScope(P,r)}catch(Q){if(Q instanceof Ut){Y=!0;break}if(Q instanceof Bt)continue;throw Q}}return!Y&&$.length&&this.runBlockInScope($,r),I}let f=s.match(/^while\s+(.+?)\s*:$/);if(f){let b=f[1],M=this.collectBlock(t,e+1,o),V=0;for(;dt(this.pyEval(b,r))&&V++<1e5;)try{this.runBlockInScope(M,r)}catch(P){if(P instanceof Ut)break;if(P instanceof Bt)continue;throw P}return e+1+M.length}if(s==="try:"){let b=this.collectBlock(t,e+1,o),M=e+1+b.length,V=[],P=[],$=[];for(;M<t.length;){let Y=t[M],j=Y.trim();if(this.getIndent(Y)!==o)break;if(j.startsWith("except")){let Q=j.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),xt=Q?.[1]??null,ht=Q?.[2],bt=this.collectBlock(t,M+1,o);V.push({exc:xt,body:bt}),ht&&r.set(ht,""),M+=1+bt.length}else if(j==="else:")$=this.collectBlock(t,M+1,o),M+=1+$.length;else if(j==="finally:")P=this.collectBlock(t,M+1,o),M+=1+P.length;else break}let I=null;try{this.runBlockInScope(b,r),$.length&&this.runBlockInScope($,r)}catch(Y){if(Y instanceof q){I=Y;let j=!1;for(let Q of V)if(Q.exc===null||Q.exc===Y.type||Q.exc==="Exception"){this.runBlockInScope(Q.body,r),j=!0;break}if(!j)throw Y}else throw Y}finally{P.length&&this.runBlockInScope(P,r)}return M}let S=s.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(S){let b=this.collectBlock(t,e+1,o);return r.set(S[2],g),this.runBlockInScope(b,r),e+1+b.length}let F=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(F){let[,b,M,V]=F,P=r.get(b)??0,$=this.pyEval(V,r),I;switch(M){case"+=":I=typeof P=="string"?P+R($):P+$;break;case"-=":I=P-$;break;case"*=":I=P*$;break;case"/=":I=P/$;break;case"//=":I=Math.floor(P/$);break;case"%=":I=P%$;break;case"**=":I=P**$;break;default:I=$}return r.set(b,I),e+1}let A=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(A){let[,b,M,V]=A,P=r.get(b)??g,$=this.pyEval(V,r)??g,I=this.pyEval(M,r)??g;return Array.isArray(P)?P[I]=$:H(P)&&P.data.set(R(I),$),e+1}let x=s.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(x){let b=x[1].lastIndexOf(".");if(b!==-1){let M=x[1].slice(0,b),V=x[1].slice(b+1),P=this.pyEval(x[2],r),$=this.pyEval(M,r);return H($)?$.data.set(V,P):Tt($)&&$.attrs.set(V,P),e+1}}let E=s.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(E){let b=this.pyEval(E[3],r),M=s.split("=")[0].split(",").map(P=>P.trim()),V=X(b);return M.forEach((P,$)=>r.set(P,V[$]??g)),e+1}let N=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(N){let[,b,M]=N;return r.set(b,this.pyEval(M,r)),e+1}try{this.pyEval(s,r)}catch(b){if(b instanceof q||b instanceof Ot)throw b}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=ki(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Ot?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof q?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Nt?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}:(this.stderr.push(`RuntimeError: ${r}`),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1})}return{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}}},br={name:"python3",aliases:["python"],description:"Python 3 interpreter (virtual)",category:"system",params:["[--version] [-c <code>] [-V] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("python3"))return{stderr:`bash: python3: command not found
974
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let c=r[2];return c=c.replace(/\{([^{}]+)\}/g,(u,d)=>{try{return R(this.pyEval(d.trim(),e))}catch{return`{${d}}`}}),c}let i=t.match(/^b(['"])(.*)\1$/s);if(i)return i[2];if(t.startsWith("[")&&t.endsWith("]")){let c=t.slice(1,-1).trim();if(!c)return[];let u=c.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(u){let[,d,m,p,h]=u,y=X(this.pyEval(p.trim(),e)),f=[];for(let S of y){let I=new Map(e);I.set(m,S),!(h&&!dt(this.pyEval(h,I)))&&f.push(this.pyEval(d.trim(),I))}return f}return this.splitArgs(c).map(d=>this.pyEval(d,e))}if(t.startsWith("(")&&t.endsWith(")")){let c=t.slice(1,-1).trim();if(!c)return[];let u=this.splitArgs(c);return u.length===1&&!c.endsWith(",")?this.pyEval(u[0],e):u.map(d=>this.pyEval(d,e))}if(t.startsWith("{")&&t.endsWith("}")){let c=t.slice(1,-1).trim();if(!c)return K();let u=K();for(let d of this.splitArgs(c)){let m=d.indexOf(":");if(m===-1)continue;let p=R(this.pyEval(d.slice(0,m).trim(),e)),h=this.pyEval(d.slice(m+1).trim(),e);u.data.set(p,h)}return u}let s=t.match(/^not\s+(.+)$/);if(s)return!dt(this.pyEval(s[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let c of o){let u=this.tryBinaryOp(t,c,e);if(u!==void 0)return u}if(t.startsWith("-")){let c=this.pyEval(t.slice(1),e);if(typeof c=="number")return-c}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let c=this.findMatchingBracket(t,"[");if(c!==-1){let u=this.pyEval(t.slice(0,c),e),d=t.slice(c+1,-1);return this.subscript(u,d,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,c,u]=a,d=(u?.trim()?this.splitArgs(u):[]).map(m=>this.pyEval(m,e));return this.callBuiltin(c,d,e)}let l=this.findDotAccess(t);if(l){let{objExpr:c,attr:u,callPart:d}=l,m=this.pyEval(c,e);if(d!==void 0){let p=d.slice(1,-1),h=p.trim()?this.splitArgs(p).map(y=>this.pyEval(y,e)):[];return this.callMethod(m,u,h,e)}return this.getAttr(m,u,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new Y("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let c=t.split("."),u=e.get(c[0])??(()=>{throw new Y("NameError",`name '${c[0]}' is not defined`)})();for(let d of c.slice(1))u=this.getAttr(u,d,e);return u}return g}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",i=0;for(let s=t.length-1;s>=0;s--)if(t[s]===r&&i++,t[s]===e&&(i--,i===0))return s;return-1}findDotAccess(t){let e=0,r=!1,i="";for(let s=t.length-1;s>0;s--){let o=t[s];if(r){o===i&&t[s-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,i=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,s).trim(),c=t.slice(s+1).match(/^(\w+)(\([\s\S]*\))?$/);if(c&&!/^-?\d+$/.test(a))return{objExpr:a,attr:c[1],callPart:c[2]}}return null}tryBinaryOp(t,e,r){let i=0,s=!1,o="";for(let a=t.length-1;a>=0;a--){let l=t[a];if(s){l===o&&t[a-1]!=="\\"&&(s=!1);continue}if(l==='"'||l==="'"){s=!0,o=l;continue}if(")]}".includes(l)){i++;continue}if("([{".includes(l)){i--;continue}if(i===0){for(let c of e)if(t.slice(a,a+c.length)===c){if(c==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let u=t[a-1],d=t[a+c.length];if(/^[a-z]/.test(c)&&(u&&/\w/.test(u)||d&&/\w/.test(d)))continue;let p=t.slice(0,a).trim(),h=t.slice(a+c.length).trim();if(!p||!h)continue;return this.applyBinaryOp(c,p,h,r)}}}}applyBinaryOp(t,e,r,i){if(t==="and"){let a=this.pyEval(e,i);return dt(a)?this.pyEval(r,i):a}if(t==="or"){let a=this.pyEval(e,i);return dt(a)?a:this.pyEval(r,i)}let s=this.pyEval(e,i),o=this.pyEval(r,i);switch(t){case"+":return typeof s=="string"&&typeof o=="string"?s+o:Array.isArray(s)&&Array.isArray(o)?[...s,...o]:s+o;case"-":return s-o;case"*":if(typeof s=="string"&&typeof o=="number")return s.repeat(o);if(Array.isArray(s)&&typeof o=="number"){let a=[];for(let l=0;l<o;l++)a.push(...s);return a}return s*o;case"/":{if(o===0)throw new Y("ZeroDivisionError","division by zero");return s/o}case"//":{if(o===0)throw new Y("ZeroDivisionError","integer division or modulo by zero");return Math.floor(s/o)}case"%":{if(typeof s=="string")return this.pyStringFormat(s,Array.isArray(o)?o:[o]);if(o===0)throw new Y("ZeroDivisionError","integer division or modulo by zero");return s%o}case"**":return s**o;case"==":return tt(s)===tt(o)||s===o;case"!=":return tt(s)!==tt(o)&&s!==o;case"<":return s<o;case"<=":return s<=o;case">":return s>o;case">=":return s>=o;case"in":return this.pyIn(o,s);case"not in":return!this.pyIn(o,s);case"is":return s===o||xt(s)&&xt(o);case"is not":return!(s===o||xt(s)&&xt(o))}return g}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>tt(r)===tt(e)):H(t)?t.data.has(R(e)):!1}subscript(t,e,r){if(e.includes(":")){let s=e.split(":").map(l=>l.trim()),o=s[0]?this.pyEval(s[0],r):void 0,a=s[1]?this.pyEval(s[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):g}let i=this.pyEval(e,r);if(Array.isArray(t)){let s=i;return s<0&&(s=t.length+s),t[s]??g}if(typeof t=="string"){let s=i;return s<0&&(s=t.length+s),t[s]??g}if(H(t))return t.data.get(R(i))??g;throw new Y("TypeError",`'${Et(t)}' is not subscriptable`)}getAttr(t,e,r){return H(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:g:Vt(t)?t.attrs.get(e)??g:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??g:g}callMethod(t,e,r,i){if(typeof t=="string")switch(e){case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();case"strip":return(r[0]?t.replace(new RegExp(`[${r[0]}]+`,"g"),""):t).trim();case"lstrip":return t.trimStart();case"rstrip":return t.trimEnd();case"split":return t.split(typeof r[0]=="string"?r[0]:/\s+/).filter((s,o)=>o>0||s!=="");case"splitlines":return t.split(`
975
+ `);case"join":return X(r[0]??[]).map(R).join(t);case"replace":return t.replaceAll(R(r[0]??""),R(r[1]??""));case"startswith":return t.startsWith(R(r[0]??""));case"endswith":return t.endsWith(R(r[0]??""));case"find":return t.indexOf(R(r[0]??""));case"index":{let s=t.indexOf(R(r[0]??""));if(s===-1)throw new Y("ValueError","substring not found");return s}case"count":return t.split(R(r[0]??"")).length-1;case"format":return this.pyStringFormat(t,r);case"encode":return t;case"decode":return t;case"isdigit":return/^\d+$/.test(t);case"isalpha":return/^[a-zA-Z]+$/.test(t);case"isalnum":return/^[a-zA-Z0-9]+$/.test(t);case"isspace":return/^\s+$/.test(t);case"isupper":return t===t.toUpperCase()&&t!==t.toLowerCase();case"islower":return t===t.toLowerCase()&&t!==t.toUpperCase();case"center":{let s=r[0]??0,o=R(r[1]??" ");return t.padStart(Math.floor((s+t.length)/2),o).padEnd(s,o)}case"ljust":return t.padEnd(r[0]??0,R(r[1]??" "));case"rjust":return t.padStart(r[0]??0,R(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,s=>s.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(s=>s===s.toUpperCase()?s.toLowerCase():s.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??g),g;case"extend":for(let s of X(r[0]??[]))t.push(s);return g;case"insert":return t.splice(r[0]??0,0,r[1]??g),g;case"pop":{let s=r[0]!==void 0?r[0]:-1,o=s<0?t.length+s:s;return t.splice(o,1)[0]??g}case"remove":{let s=t.findIndex(o=>tt(o)===tt(r[0]??g));return s!==-1&&t.splice(s,1),g}case"index":{let s=t.findIndex(o=>tt(o)===tt(r[0]??g));if(s===-1)throw new Y("ValueError","is not in list");return s}case"count":return t.filter(s=>tt(s)===tt(r[0]??g)).length;case"sort":return t.sort((s,o)=>typeof s=="number"&&typeof o=="number"?s-o:R(s).localeCompare(R(o))),g;case"reverse":return t.reverse(),g;case"copy":return[...t];case"clear":return t.splice(0),g}if(H(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([s,o])=>[s,o]);case"get":return t.data.get(R(r[0]??""))??r[1]??g;case"update":{if(H(r[0]??g))for(let[s,o]of r[0].data)t.data.set(s,o);return g}case"pop":{let s=R(r[0]??""),o=t.data.get(s)??r[1]??g;return t.data.delete(s),o}case"clear":return t.data.clear(),g;case"copy":return K([...t.data.entries()]);case"setdefault":{let s=R(r[0]??"");return t.data.has(s)||t.data.set(s,r[1]??g),t.data.get(s)??g}}if(H(t)&&t.data.has("name")&&t.data.get("name")==="posix")switch(e){case"getcwd":return this.cwd;case"getenv":return typeof r[0]=="string"?process.env[r[0]]??r[1]??g:g;case"listdir":return[];case"path":return t}if(H(t))switch(e){case"join":return r.map(R).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return R(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return R(r[0]??"").split("/").pop()??"";case"abspath":return R(r[0]??"");case"splitext":{let s=R(r[0]??""),o=s.lastIndexOf(".");return o>0?[s.slice(0,o),s.slice(o)]:[s,""]}case"isfile":return!1;case"isdir":return!1}if(H(t)&&t.data.has("version")&&t.data.get("version")===le&&e==="exit")throw new Wt(r[0]??0);if(H(t)){let s={sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil,fabs:Math.abs,log:Math.log,log2:Math.log2,log10:Math.log10,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,pow:Math.pow,exp:Math.exp,hypot:Math.hypot};if(e in s){let o=s[e];return o(...r.map(a=>a))}if(e==="factorial"){let o=r[0]??0,a=1;for(;o>1;)a*=o--;return a}if(e==="gcd"){let o=Math.abs(r[0]??0),a=Math.abs(r[1]??0);for(;a;)[o,a]=[a,o%a];return o}}if(H(t)){if(e==="dumps"){let s=H(r[1]??g)?r[1]:void 0,o=s?s.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??g),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(R(r[0]??"")))}if(Vt(t)){let s=t.attrs.get(e)??t.cls.methods.get(e)??g;if(wt(s)){let o=new Map(s.closure);return o.set("self",t),s.params.slice(1).forEach((a,l)=>o.set(a,r[l]??g)),this.execBlock(s.body,o)}}throw new Y("AttributeError",`'${Et(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(i,s)=>{if(s==="%")return"%";let o=e[r++];switch(s){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return R(o??g);case"r":return tt(o??g);default:return String(o)}})}pyToJs(t){return xt(t)?null:H(t)?Object.fromEntries([...t.data.entries()].map(([e,r])=>[e,this.pyToJs(r)])):Array.isArray(t)?t.map(e=>this.pyToJs(e)):t}jsToPy(t){return t==null?g:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?K(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):g}callBuiltin(t,e,r){if(r.has(t)){let i=r.get(t)??g;return wt(i)?this.callFunc(i,e,r):Ae(i)?this.instantiate(i,e,r):i}switch(t){case"print":return this.output.push(e.map(R).join(" ")+`
976
+ `.replace(/\\n/g,"")),g;case"input":return this.output.push(R(e[0]??"")),"";case"int":{if(e.length===0)return 0;let i=e[1]??10,s=parseInt(R(e[0]??0),i);return Number.isNaN(s)?(()=>{throw new Y("ValueError","invalid literal for int()")})():s}case"float":{if(e.length===0)return 0;let i=parseFloat(R(e[0]??0));return Number.isNaN(i)?(()=>{throw new Y("ValueError","could not convert to float")})():i}case"str":return e.length===0?"":R(e[0]??g);case"bool":return e.length===0?!1:dt(e[0]??g);case"list":return e.length===0?[]:X(e[0]??[]);case"tuple":return e.length===0?[]:X(e[0]??[]);case"set":return e.length===0?[]:[...new Set(X(e[0]??[]).map(tt))].map(i=>X(e[0]??[]).find(o=>tt(o)===i)??g);case"dict":return e.length===0?K():H(e[0]??g)?e[0]:K();case"bytes":return typeof e[0]=="string"?e[0]:R(e[0]??"");case"bytearray":return e.length===0?"":R(e[0]??"");case"type":return e.length===1?`<class '${Et(e[0]??g)}'>`:g;case"isinstance":return Et(e[0]??g)===R(e[1]??"");case"issubclass":return!1;case"callable":return wt(e[0]??g);case"hasattr":return H(e[0]??g)?e[0].data.has(R(e[1]??"")):!1;case"getattr":return H(e[0]??g)?e[0].data.get(R(e[1]??""))??e[2]??g:e[2]??g;case"setattr":return H(e[0]??g)&&e[0].data.set(R(e[1]??""),e[2]??g),g;case"len":{let i=e[0]??g;if(typeof i=="string"||Array.isArray(i))return i.length;if(H(i))return i.data.size;if(Rt(i))return $r(i);throw new Y("TypeError",`object of type '${Et(i)}' has no len()`)}case"range":return e.length===1?Ie(0,e[0]):e.length===2?Ie(e[0],e[1]):Ie(e[0],e[1],e[2]);case"enumerate":{let i=e[1]??0;return X(e[0]??[]).map((s,o)=>[o+i,s])}case"zip":{let i=e.map(X),s=Math.min(...i.map(o=>o.length));return Array.from({length:s},(o,a)=>i.map(l=>l[a]??g))}case"map":{let i=e[0]??g;return X(e[1]??[]).map(s=>wt(i)?this.callFunc(i,[s],r):g)}case"filter":{let i=e[0]??g;return X(e[1]??[]).filter(s=>wt(i)?dt(this.callFunc(i,[s],r)):dt(s))}case"reduce":{let i=e[0]??g,s=X(e[1]??[]);if(s.length===0)return e[2]??g;let o=e[2]!==void 0?e[2]:s[0];for(let a of e[2]!==void 0?s:s.slice(1))o=wt(i)?this.callFunc(i,[o,a],r):g;return o}case"sorted":{let i=[...X(e[0]??[])],s=e[1]??g,o=H(s)?s.data.get("key")??g:s;return i.sort((a,l)=>{let c=wt(o)?this.callFunc(o,[a],r):a,u=wt(o)?this.callFunc(o,[l],r):l;return typeof c=="number"&&typeof u=="number"?c-u:R(c).localeCompare(R(u))}),i}case"reversed":return[...X(e[0]??[])].reverse();case"any":return X(e[0]??[]).some(dt);case"all":return X(e[0]??[]).every(dt);case"sum":return X(e[0]??[]).reduce((i,s)=>i+s,e[1]??0);case"max":return(e.length===1?X(e[0]??[]):e).reduce((s,o)=>s>=o?s:o);case"min":return(e.length===1?X(e[0]??[]):e).reduce((s,o)=>s<=o?s:o);case"abs":return Math.abs(e[0]??0);case"round":return e[1]!==void 0?parseFloat(e[0].toFixed(e[1])):Math.round(e[0]??0);case"divmod":{let i=e[0],s=e[1];return[Math.floor(i/s),i%s]}case"pow":return e[0]**e[1];case"hex":return`0x${e[0].toString(16)}`;case"oct":return`0o${e[0].toString(8)}`;case"bin":return`0b${e[0].toString(2)}`;case"ord":return R(e[0]??"").charCodeAt(0);case"chr":return String.fromCharCode(e[0]??0);case"id":return Math.floor(Math.random()*4294967295);case"hash":return typeof e[0]=="number"?e[0]:R(e[0]??"").split("").reduce((i,s)=>i*31+s.charCodeAt(0)|0,0);case"open":throw new Y("PermissionError","open() not available in virtual runtime");case"repr":return tt(e[0]??g);case"iter":return e[0]??g;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new Y("StopIteration","")})();case"vars":return K([...r.entries()].map(([i,s])=>[i,s]));case"globals":return K([...r.entries()].map(([i,s])=>[i,s]));case"locals":return K([...r.entries()].map(([i,s])=>[i,s]));case"dir":{if(e.length===0)return[...r.keys()];let i=e[0]??g;return typeof i=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(i)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:H(i)?["keys","values","items","get","update","pop","clear","copy","setdefault"]:[]}case"Exception":case"ValueError":case"TypeError":case"KeyError":case"IndexError":case"AttributeError":case"NameError":case"RuntimeError":case"StopIteration":case"NotImplementedError":case"OSError":case"IOError":throw new Y(t,R(e[0]??""));case"exec":return this.execScript(R(e[0]??""),r),g;case"eval":return this.pyEval(R(e[0]??""),r);default:throw new Y("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let i=new Map(t.closure);t.params.forEach((s,o)=>{if(s.startsWith("*")){i.set(s.slice(1),e.slice(o));return}i.set(s,e[o]??g)});try{return this.execBlock(t.body,i)}catch(s){if(s instanceof Ft)return s.value;throw s}}instantiate(t,e,r){let i={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(i,"__init__",e,r),i}execScript(t,e){let r=t.split(`
977
+ `);this.execLines(r,0,e)}execLines(t,e,r){let i=e;for(;i<t.length;){let s=t[i];if(!s.trim()||s.trim().startsWith("#")){i++;continue}i=this.execStatement(t,i,r)}return i}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof Ft)return r.value;throw r}return g}getIndent(t){let e=0;for(let r of t)if(r===" ")e++;else if(r===" ")e+=4;else break;return e}collectBlock(t,e,r){let i=[];for(let s=e;s<t.length;s++){let o=t[s];if(!o.trim()){i.push("");continue}if(this.getIndent(o)<=r)break;i.push(o.slice(r+4))}return i}execStatement(t,e,r){let i=t[e],s=i.trim(),o=this.getIndent(i);if(s==="pass")return e+1;if(s==="break")throw new zt;if(s==="continue")throw new Bt;let a=s.match(/^return(?:\s+(.+))?$/);if(a)throw new Ft(a[1]?this.pyEval(a[1],r):g);let l=s.match(/^raise(?:\s+(.+))?$/);if(l){if(l[1]){let v=this.pyEval(l[1],r);throw new Y(typeof v=="string"?v:Et(v),R(v))}throw new Y("RuntimeError","")}let c=s.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(c){if(!dt(this.pyEval(c[1],r)))throw new Y("AssertionError",c[2]?R(this.pyEval(c[2],r)):"");return e+1}let u=s.match(/^del\s+(.+)$/);if(u)return r.delete(u[1].trim()),e+1;let d=s.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(d){let[,v,E]=d,T=Cr[v];if(T){let P=T(this.cwd);this.modules.set(v,P),r.set(E??v,P)}return e+1}let m=s.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(m){let[,v,E]=m,T=Cr[v];if(T){let P=T(this.cwd);if(E?.trim()==="*")for(let[$,F]of P.data)r.set($,F);else for(let $ of E.split(",").map(F=>F.trim()))r.set($,P.data.get($)??g)}return e+1}let p=s.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,v,E]=p,T=E.split(",").map(F=>F.trim()).filter(Boolean),P=this.collectBlock(t,e+1,o),$={__pytype__:"func",name:v,params:T,body:P,closure:new Map(r)};return r.set(v,$),e+1+P.length}let h=s.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(h){let[,v,E]=h,T=E?E.split(",").map(Z=>Z.trim()):[],P=this.collectBlock(t,e+1,o),$={__pytype__:"class",name:v,methods:new Map,bases:T},F=0;for(;F<P.length;){let j=P[F].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(j){let[,Q,bt]=j,ht=bt.split(",").map(O=>O.trim()).filter(Boolean),vt=this.collectBlock(P,F+1,0);$.methods.set(Q,{__pytype__:"func",name:Q,params:ht,body:vt,closure:new Map(r)}),F+=1+vt.length}else F++}return r.set(v,$),e+1+P.length}if(s.startsWith("if ")&&s.endsWith(":")){let v=s.slice(3,-1).trim(),E=this.collectBlock(t,e+1,o),T=E.length+1;if(dt(this.pyEval(v,r))){this.execBlock(E,new Map(r).also?.(F=>{for(let[Z,j]of r)F.set(Z,j)})??r),this.runBlockInScope(E,r);let $=e+1+E.length;for(;$<t.length;){let F=t[$].trim();if(this.getIndent(t[$])<o||!F.startsWith("elif")&&!F.startsWith("else"))break;let Z=this.collectBlock(t,$+1,o);$+=1+Z.length}return $}let P=e+1+E.length;for(;P<t.length;){let $=t[P],F=$.trim();if(this.getIndent($)!==o)break;let Z=F.match(/^elif\s+(.+):$/);if(Z){let j=this.collectBlock(t,P+1,o);if(dt(this.pyEval(Z[1],r))){for(this.runBlockInScope(j,r),P+=1+j.length;P<t.length;){let Q=t[P].trim();if(this.getIndent(t[P])!==o||!Q.startsWith("elif")&&!Q.startsWith("else"))break;let bt=this.collectBlock(t,P+1,o);P+=1+bt.length}return P}P+=1+j.length;continue}if(F==="else:"){let j=this.collectBlock(t,P+1,o);return this.runBlockInScope(j,r),P+1+j.length}break}return P}let y=s.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(y){let[,v,E]=y,T=X(this.pyEval(E.trim(),r)),P=this.collectBlock(t,e+1,o),$=[],F=e+1+P.length;F<t.length&&t[F]?.trim()==="else:"&&($=this.collectBlock(t,F+1,o),F+=1+$.length);let Z=!1;for(let j of T){if(v.includes(",")){let Q=v.split(",").map(ht=>ht.trim()),bt=Array.isArray(j)?j:[j];Q.forEach((ht,vt)=>r.set(ht,bt[vt]??g))}else r.set(v.trim(),j);try{this.runBlockInScope(P,r)}catch(Q){if(Q instanceof zt){Z=!0;break}if(Q instanceof Bt)continue;throw Q}}return!Z&&$.length&&this.runBlockInScope($,r),F}let f=s.match(/^while\s+(.+?)\s*:$/);if(f){let v=f[1],E=this.collectBlock(t,e+1,o),T=0;for(;dt(this.pyEval(v,r))&&T++<1e5;)try{this.runBlockInScope(E,r)}catch(P){if(P instanceof zt)break;if(P instanceof Bt)continue;throw P}return e+1+E.length}if(s==="try:"){let v=this.collectBlock(t,e+1,o),E=e+1+v.length,T=[],P=[],$=[];for(;E<t.length;){let Z=t[E],j=Z.trim();if(this.getIndent(Z)!==o)break;if(j.startsWith("except")){let Q=j.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),bt=Q?.[1]??null,ht=Q?.[2],vt=this.collectBlock(t,E+1,o);T.push({exc:bt,body:vt}),ht&&r.set(ht,""),E+=1+vt.length}else if(j==="else:")$=this.collectBlock(t,E+1,o),E+=1+$.length;else if(j==="finally:")P=this.collectBlock(t,E+1,o),E+=1+P.length;else break}let F=null;try{this.runBlockInScope(v,r),$.length&&this.runBlockInScope($,r)}catch(Z){if(Z instanceof Y){F=Z;let j=!1;for(let Q of T)if(Q.exc===null||Q.exc===Z.type||Q.exc==="Exception"){this.runBlockInScope(Q.body,r),j=!0;break}if(!j)throw Z}else throw Z}finally{P.length&&this.runBlockInScope(P,r)}return E}let S=s.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(S){let v=this.collectBlock(t,e+1,o);return r.set(S[2],g),this.runBlockInScope(v,r),e+1+v.length}let I=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(I){let[,v,E,T]=I,P=r.get(v)??0,$=this.pyEval(T,r),F;switch(E){case"+=":F=typeof P=="string"?P+R($):P+$;break;case"-=":F=P-$;break;case"*=":F=P*$;break;case"/=":F=P/$;break;case"//=":F=Math.floor(P/$);break;case"%=":F=P%$;break;case"**=":F=P**$;break;default:F=$}return r.set(v,F),e+1}let k=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(k){let[,v,E,T]=k,P=r.get(v)??g,$=this.pyEval(T,r)??g,F=this.pyEval(E,r)??g;return Array.isArray(P)?P[F]=$:H(P)&&P.data.set(R(F),$),e+1}let b=s.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(b){let v=b[1].lastIndexOf(".");if(v!==-1){let E=b[1].slice(0,v),T=b[1].slice(v+1),P=this.pyEval(b[2],r),$=this.pyEval(E,r);return H($)?$.data.set(T,P):Vt($)&&$.attrs.set(T,P),e+1}}let M=s.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(M){let v=this.pyEval(M[3],r),E=s.split("=")[0].split(",").map(P=>P.trim()),T=X(v);return E.forEach((P,$)=>r.set(P,T[$]??g)),e+1}let A=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(A){let[,v,E]=A;return r.set(v,this.pyEval(E,r)),e+1}try{this.pyEval(s,r)}catch(v){if(v instanceof Y||v instanceof Wt)throw v}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=Ni(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Wt?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof Y?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Ft?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}:(this.stderr.push(`RuntimeError: ${r}`),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1})}return{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}}},Pr={name:"python3",aliases:["python"],description:"Python 3 interpreter (virtual)",category:"system",params:["[--version] [-c <code>] [-V] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("python3"))return{stderr:`bash: python3: command not found
168
978
  Hint: install it with: apt install python3
169
979
  `,exitCode:127};if(w(n,["--version","-V"]))return{stdout:`${$i}
170
980
  `,exitCode:0};if(w(n,["--version-full"]))return{stdout:`${le}
171
981
  `,exitCode:0};let r=n.indexOf("-c");if(r!==-1){let s=n[r+1];if(!s)return{stderr:`python3: -c requires a code argument
172
982
  `,exitCode:1};let o=s.replace(/\\n/g,`
173
- `).replace(/\\t/g," "),a=new ce(e),{stdout:l,stderr:c,exitCode:u}=a.run(o);return{stdout:l||void 0,stderr:c||void 0,exitCode:u}}let i=n.find(s=>!s.startsWith("-"));if(i){let s=k(e,i);if(!t.vfs.exists(s))return{stderr:`python3: can't open file '${i}': [Errno 2] No such file or directory
983
+ `).replace(/\\t/g," "),a=new ce(e),{stdout:l,stderr:c,exitCode:u}=a.run(o);return{stdout:l||void 0,stderr:c||void 0,exitCode:u}}let i=n.find(s=>!s.startsWith("-"));if(i){let s=N(e,i);if(!t.vfs.exists(s))return{stderr:`python3: can't open file '${i}': [Errno 2] No such file or directory
174
984
  `,exitCode:2};let o=t.vfs.readFile(s),a=new ce(e),{stdout:l,stderr:c,exitCode:u}=a.run(o);return{stdout:l||void 0,stderr:c||void 0,exitCode:u}}return{stdout:`${le}
175
985
  Type "help", "copyright", "credits" or "license" for more information.
176
- >>> `,exitCode:0}}};var vr={name:"read",description:"Read a line from stdin into variables",category:"shell",params:["[-r] [-p prompt] <var...>"],run:({args:n,stdin:t,env:e})=>{let r=n.indexOf("-p"),i=n.filter((a,l)=>a!=="-r"&&a!=="-p"&&n[l-1]!=="-p"),s=(t??"").split(`
986
+ >>> `,exitCode:0}}};var Nr={name:"read",description:"Read a line from stdin into variables",category:"shell",params:["[-r] [-p prompt] <var...>"],run:({args:n,stdin:t,env:e})=>{let r=n.indexOf("-p"),i=n.filter((a,l)=>a!=="-r"&&a!=="-p"&&n[l-1]!=="-p"),s=(t??"").split(`
177
987
  `)[0]??"",o=w(n,["-r"])?s:s.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
178
- `||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(i.length===0)e.vars.REPLY=o;else if(i.length===1)e.vars[i[0]]=o;else{let a=o.split(/\s+/);for(let l=0;l<i.length;l++)e.vars[i[l]]=l<i.length-1?a[l]??"":a.slice(l).join(" ")}return{exitCode:0}}};var Cr={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let i=w(r,["-r","-rf","-fr"]),s=[];for(let o=0;;o+=1){let a=Ct(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;s.push(a)}if(s.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of s){let a=k(e,o);L(n,a,"rm"),t.vfs.remove(a,{recursive:i})}return{exitCode:0}}};var $r={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-i"]),o=ct(r,["-e"])??r.find(f=>!f.startsWith("-")),a=r.filter(f=>!f.startsWith("-")&&f!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let l=i??"";if(a){let f=k(e,a);try{l=t.vfs.readFile(f)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let c=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!c)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,u,d,m]=c,p=(m??"").includes("i")?"gi":(m??"").includes("g")?"g":"",h;try{h=new RegExp(u,p||"")}catch{return{stderr:`sed: invalid regex: ${u}`,exitCode:1}}let y=((m??"").includes("g")||p.includes("g"),l.replace(h,d??""));if(s&&a){let f=k(e,a);return t.writeFileAsUser(n,f,y),{exitCode:0}}return{stdout:y,exitCode:0}}};var Pr={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,i])=>`${r}=${i}`).join(`
179
- `),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("=");t.vars[e.slice(0,r)]=e.slice(r+1)}return{exitCode:0}}};async function kr(n,t,e,r,i,s,o){let a={exitCode:0},l=[],c=i,u=0;for(;u<n.length;){let m=n[u];if(a=await _i(m.pipeline,t,e,r,c,s,o),o.lastExitCode=a.exitCode??0,a.nextCwd&&(a.exitCode??0)===0&&(c=a.nextCwd),a.stdout&&l.push(a.stdout),a.closeSession||a.switchUser)return{...a,stdout:l.join("")||a.stdout};let p=m.op;if(!(!p||p===";")){if(p==="&&"){if((a.exitCode??0)!==0)for(;u<n.length&&n[u]?.op==="&&";)u++}else if(p==="||"&&(a.exitCode??0)===0)for(;u<n.length&&n[u]?.op==="||";)u++}u++}let d=l.join("");return{...a,stdout:d||a.stdout,nextCwd:c!==i?c:void 0}}async function _i(n,t,e,r,i,s,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?Ii(n.commands[0],t,e,r,i,s,a):Ri(n.commands,t,e,r,i,s,a)}async function Ii(n,t,e,r,i,s,o){let a;if(n.inputFile){let c=k(i,n.inputFile);try{a=s.vfs.readFile(c)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let l=await Rt(n.name,n.args,t,e,r,i,s,a,o);if(n.outputFile){let c=k(i,n.outputFile),u=l.stdout||"";try{if(n.appendOutput){let d=(()=>{try{return s.vfs.readFile(c)}catch{return""}})();s.writeFileAsUser(t,c,d+u)}else s.writeFileAsUser(t,c,u);return{...l,stdout:""}}catch{return{...l,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return l}async function Ri(n,t,e,r,i,s,o){let a="",l=0;for(let c=0;c<n.length;c++){let u=n[c];if(c===0&&u.inputFile){let m=k(i,u.inputFile);try{a=s.vfs.readFile(m)}catch{return{stderr:`${u.inputFile}: No such file or directory`,exitCode:1}}}let d=await Rt(u.name,u.args,t,e,r,i,s,a,o);if(l=d.exitCode??0,c===n.length-1&&u.outputFile){let m=k(i,u.outputFile),p=d.stdout||"";try{if(u.appendOutput){let h=(()=>{try{return s.vfs.readFile(m)}catch{return""}})();s.writeFileAsUser(t,m,h+p)}else s.writeFileAsUser(t,m,p);a=""}catch{return{stderr:`Failed to write to ${u.outputFile}`,exitCode:1}}}else a=d.stdout||"";if(d.stderr&&l!==0)return{stderr:d.stderr,exitCode:l};if(d.closeSession||d.switchUser)return d}return{stdout:a,exitCode:l}}function jt(n){let t=[],e="",r=!1,i="",s=0;for(;s<n.length;){let o=n[s],a=n[s+1];if((o==='"'||o==="'")&&!r){r=!0,i=o,s++;continue}if(r&&o===i){r=!1,i="",s++;continue}if(r){e+=o,s++;continue}if(o===" "){e&&(t.push(e),e=""),s++;continue}if(!r&&o==="2"&&a===">"){let l=n.slice(s+1);if(l.startsWith(">>&1")||l.startsWith(">> &1")){e&&(t.push(e),e=""),t.push("2>>&1"),s+=5;continue}if(l.startsWith(">&1")){e&&(t.push(e),e=""),t.push("2>&1"),s+=4;continue}if(l.startsWith(">>")){e&&(t.push(e),e=""),t.push("2>>"),s+=3;continue}if(l.startsWith(">")){e&&(t.push(e),e=""),t.push("2>"),s+=2;continue}}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),s+=2):(t.push(o),s++);continue}e+=o,s++}return e&&t.push(e),t}function Mr(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:Vi(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function Vi(n){let t=Di(n),e=[];for(let r of t){let s={pipeline:{commands:Li(r.text.trim()),isValid:!0}};r.op&&(s.op=r.op),e.push(s)}return e}function Di(n){let t=[],e="",r=0,i=!1,s="",o=0,a=l=>{e.trim()&&t.push({text:e,op:l}),e=""};for(;o<n.length;){let l=n[o],c=n.slice(o,o+2);if((l==='"'||l==="'")&&!i){i=!0,s=l,e+=l,o++;continue}if(i&&l===s){i=!1,e+=l,o++;continue}if(i){e+=l,o++;continue}if(l==="("){r++,e+=l,o++;continue}if(l===")"){r--,e+=l,o++;continue}if(r>0){e+=l,o++;continue}if(c==="&&"){a("&&"),o+=2;continue}if(c==="||"){a("||"),o+=2;continue}if(l===";"){a(";"),o++;continue}e+=l,o++}return a(),t}function Li(n){return zi(n).map(Ti)}function zi(n){let t=[],e="",r=!1,i="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,i=a,e+=a;continue}if(r&&a===i){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let s=e.trim();if(!s&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&t.push(s),t}function Ti(n){let t=jt(n);if(t.length===0)return{name:"",args:[]};let e=[],r,i,s=!1,o=0,a,l=!1,c=!1;for(;o<t.length;){let m=t[o];if(m==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(m===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");i=t[o],s=!0,o++}else if(m===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");i=t[o],s=!1,o++}else if(m==="2>&1")c=!0,o++;else if(m==="2>>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>>");a=t[o],l=!0,o++}else if(m==="2>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>");a=t[o],l=!1,o++}else e.push(m),o++}let u=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(u)?u:u.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:i,appendOutput:s,stderrFile:a,stderrAppend:l,stderrToStdout:c}}function It(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${n}`,USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function Er(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let s=e.vfs.stat(n);return s.type!=="file"||!(s.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let i=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let s of i){if((s==="/sbin"||s==="/usr/sbin")&&r!=="root")continue;let o=`${s}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function Rt(n,t,e,r,i,s,o,a,l){let c=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,u=[n,...t],d=0;for(;d<u.length&&c.test(u[d]);)d+=1;if(d>0){let h=u.slice(0,d).map(S=>S.match(c)),y=u.slice(d),f=[];for(let[,S,F]of h)f.push([S,l.vars[S]]),l.vars[S]=F;if(y.length===0)return{exitCode:0};try{return await Rt(y[0],y.slice(1),e,r,i,s,o,a,l)}finally{for(let[S,F]of f)F===void 0?delete l.vars[S]:l.vars[S]=F}}let m=l.vars[`__alias_${n}`];if(m)return J(`${m} ${t.join(" ")}`,e,r,i,s,o,a,l);let p=ft(n);if(!p){let h=Er(n,l,o,e);if(h){let y=o.vfs.readFile(h),f=y.match(/exec\s+builtin\s+(\S+)/);if(f){let F=ft(f[1]);if(F)return await F.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:l})}let S=ft("sh");if(S)return await S.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(y)}`,mode:i,args:["-c",y,"--",...t],stdin:a,cwd:s,shell:o,env:l})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await p.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:l})}catch(h){return{stderr:h instanceof Error?h.message:"Command failed",exitCode:1}}}async function J(n,t,e,r,i,s,o,a){let l=n.trim();if(l.length===0)return{exitCode:0};let c=a??It(t,e),d=jt(l)[0]?.toLowerCase()??"",m=c.vars[`__alias_${d}`],p=m?l.replace(d,m):l,h=/\bfor\s+\w+\s+in\b/.test(p)||/\bwhile\s+/.test(p)||/\bif\s+/.test(p)||/\w+\s*\(\s*\)\s*\{/.test(p)||/\bfunction\s+\w+/.test(p)||/\(\(\s*.+\s*\)\)/.test(p),y=/(?<![|&])[|](?![|])/.test(p)||p.includes(">")||p.includes("<")||p.includes("&&")||p.includes("||")||p.includes(";");if(h&&d!=="sh"&&d!=="bash"||y){if(h&&d!=="sh"&&d!=="bash"){let b=ft("sh");if(b)return await b.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:p,mode:r,args:["-c",p],stdin:void 0,cwd:i,shell:s,env:c})}let N=Mr(p);if(!N.isValid)return{stderr:N.error||"Syntax error",exitCode:1};try{return await kr(N.statements,t,e,r,i,s,c)}catch(b){return{stderr:b instanceof Error?b.message:"Execution failed",exitCode:1}}}let f=await te(p,c.vars,c.lastExitCode,N=>J(N,t,e,r,i,s,void 0,c).then(b=>b.stdout??"")),S=jt(f.trim());if(S.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(S[0]))return Rt(S[0],S.slice(1),t,e,r,i,s,o,c);let A=S[0]?.toLowerCase()??"",x=S.slice(1).flatMap(Xt),E=ft(A);if(!E){let N=Er(A,c,s,t);if(N){let b=s.vfs.readFile(N),M=b.match(/exec\s+builtin\s+(\S+)/);if(M){let P=M[1],$=ft(P);if($)return await $.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:[A,...x].join(" "),mode:r,args:x,stdin:o,cwd:i,shell:s,env:c})}let V=ft("sh");if(V)return await V.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(b)}`,mode:r,args:["-c",b,"--",...x],stdin:o,cwd:i,shell:s,env:c})}return{stderr:`${A}: command not found`,exitCode:127}}try{return await E.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:f,mode:r,args:x,stdin:o,cwd:i,shell:s,env:c})}catch(N){return{stderr:N instanceof Error?N.message:"Command failed",exitCode:1}}}async function Ie(n,t,e,r){return te(n,t,e,i=>J(i,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(s=>s.stdout??""))}function $t(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}let i=r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{(.+)\}\s*$/),s=i??(r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{?\s*$/)||r.match(/^function\s+(\w+)\s*\{?\s*$/));if(s){let a=s[1],l=[];if(i){l.push(...i[2].split(";").map(c=>c.trim()).filter(Boolean)),t.push({type:"func",name:a,body:l}),e++;continue}for(e++;e<n.length&&n[e]?.trim()!=="}"&&e<n.length+1;){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="{"&&l.push(c),e++}e++,t.push({type:"func",name:a,body:l});continue}let o=r.match(/^\(\(\s*(.+?)\s*\)\)$/);if(o){t.push({type:"arith",expr:o[1]}),e++;continue}if(r.startsWith("if ")||r==="if"){let a=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),l=[],c=[],u=[],d="then",m="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(d="elif",m=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),c.push({cond:m,body:[]})):p==="else"?d="else":p!=="then"&&(d==="then"?l.push(p):d==="elif"&&c.length>0?c[c.length-1].body.push(p):u.push(p)),e++}t.push({type:"if",cond:a,then_:l,elif:c,else_:u})}else if(r.startsWith("for ")){let a=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(a){let l=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="do"&&l.push(c),e++}t.push({type:"for",var:a[1],list:a[2],body:l})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let a=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),l=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="do"&&l.push(c),e++}t.push({type:"while",cond:a,body:l})}else t.push({type:"cmd",line:r});e++}return t}async function _e(n,t){let e=await Ie(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let s=r[1],o=s.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,c,u]=o,d=k(t.cwd,u);if(c==="f")return t.shell.vfs.exists(d)&&t.shell.vfs.stat(d).type==="file";if(c==="d")return t.shell.vfs.exists(d)&&t.shell.vfs.stat(d).type==="directory";if(c==="e")return t.shell.vfs.exists(d);if(c==="z")return(u??"").length===0;if(c==="n")return(u??"").length>0}let a=s.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,c,u,d]=a;if(u==="=="||u==="=")return c===d;if(u==="!=")return c!==d}let l=s.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(l){let[,c,u,d]=l,m=Number(c),p=Number(d);if(u==="-eq")return m===p;if(u==="-ne")return m!==p;if(u==="-lt")return m<p;if(u==="-le")return m<=p;if(u==="-gt")return m>p;if(u==="-ge")return m>=p}}return((await J(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function Pt(n,t){let e={exitCode:0},r="";for(let i of n)if(i.type==="cmd"){let s=await Ie(i.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=s.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(u=>o.test(u))){for(let u of a){let d=u.match(o);t.env.vars[d[1]]=d[2]}t.env.lastExitCode=0;continue}let l=await(async()=>{let c=s.trim().split(/\s+/)[0]??"",u=t.env.vars[`__func_${c}`];if(u){let d=s.trim().split(/\s+/).slice(1),m={...t.env.vars};d.forEach((y,f)=>{t.env.vars[String(f+1)]=y}),t.env.vars[0]=c;let p=u.split(`
988
+ `||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(i.length===0)e.vars.REPLY=o;else if(i.length===1)e.vars[i[0]]=o;else{let a=o.split(/\s+/);for(let l=0;l<i.length;l++)e.vars[i[l]]=l<i.length-1?a[l]??"":a.slice(l).join(" ")}return{exitCode:0}}};var Er={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let i=w(r,["-r","-rf","-fr"]),s=[];for(let o=0;;o+=1){let a=Ct(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;s.push(a)}if(s.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of s){let a=N(e,o);D(n,a,"rm"),t.vfs.remove(a,{recursive:i})}return{exitCode:0}}};var Mr={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-i"]),o=ct(r,["-e"])??r.find(f=>!f.startsWith("-")),a=r.filter(f=>!f.startsWith("-")&&f!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let l=i??"";if(a){let f=N(e,a);try{l=t.vfs.readFile(f)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let c=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!c)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,u,d,m]=c,p=(m??"").includes("i")?"gi":(m??"").includes("g")?"g":"",h;try{h=new RegExp(u,p||"")}catch{return{stderr:`sed: invalid regex: ${u}`,exitCode:1}}let y=((m??"").includes("g")||p.includes("g"),l.replace(h,d??""));if(s&&a){let f=N(e,a);return t.writeFileAsUser(n,f,y),{exitCode:0}}return{stdout:y,exitCode:0}}};var kr={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,i])=>`${r}=${i}`).join(`
989
+ `),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("=");t.vars[e.slice(0,r)]=e.slice(r+1)}return{exitCode:0}}};async function Ir(n,t,e,r,i,s,o){let a={exitCode:0},l=[],c=i,u=0;for(;u<n.length;){let m=n[u];if(a=await Oi(m.pipeline,t,e,r,c,s,o),o.lastExitCode=a.exitCode??0,a.nextCwd&&(a.exitCode??0)===0&&(c=a.nextCwd),a.stdout&&l.push(a.stdout),a.closeSession||a.switchUser)return{...a,stdout:l.join("")||a.stdout};let p=m.op;if(!(!p||p===";")){if(p==="&&"){if((a.exitCode??0)!==0)for(;u<n.length&&n[u]?.op==="&&";)u++}else if(p==="||"&&(a.exitCode??0)===0)for(;u<n.length&&n[u]?.op==="||";)u++}u++}let d=l.join("");return{...a,stdout:d||a.stdout,nextCwd:c!==i?c:void 0}}async function Oi(n,t,e,r,i,s,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?Fi(n.commands[0],t,e,r,i,s,a):Ri(n.commands,t,e,r,i,s,a)}async function Fi(n,t,e,r,i,s,o){let a;if(n.inputFile){let c=N(i,n.inputFile);try{a=s.vfs.readFile(c)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let l=await _t(n.name,n.args,t,e,r,i,s,a,o);if(n.outputFile){let c=N(i,n.outputFile),u=l.stdout||"";try{if(n.appendOutput){let d=(()=>{try{return s.vfs.readFile(c)}catch{return""}})();s.writeFileAsUser(t,c,d+u)}else s.writeFileAsUser(t,c,u);return{...l,stdout:""}}catch{return{...l,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return l}async function Ri(n,t,e,r,i,s,o){let a="",l=0;for(let c=0;c<n.length;c++){let u=n[c];if(c===0&&u.inputFile){let m=N(i,u.inputFile);try{a=s.vfs.readFile(m)}catch{return{stderr:`${u.inputFile}: No such file or directory`,exitCode:1}}}let d=await _t(u.name,u.args,t,e,r,i,s,a,o);if(l=d.exitCode??0,c===n.length-1&&u.outputFile){let m=N(i,u.outputFile),p=d.stdout||"";try{if(u.appendOutput){let h=(()=>{try{return s.vfs.readFile(m)}catch{return""}})();s.writeFileAsUser(t,m,h+p)}else s.writeFileAsUser(t,m,p);a=""}catch{return{stderr:`Failed to write to ${u.outputFile}`,exitCode:1}}}else a=d.stdout||"";if(d.stderr&&l!==0)return{stderr:d.stderr,exitCode:l};if(d.closeSession||d.switchUser)return d}return{stdout:a,exitCode:l}}function Ht(n){let t=[],e="",r=!1,i="",s=0;for(;s<n.length;){let o=n[s],a=n[s+1];if((o==='"'||o==="'")&&!r){r=!0,i=o,s++;continue}if(r&&o===i){r=!1,i="",s++;continue}if(r){e+=o,s++;continue}if(o===" "){e&&(t.push(e),e=""),s++;continue}if(!r&&o==="2"&&a===">"){let l=n.slice(s+1);if(l.startsWith(">>&1")||l.startsWith(">> &1")){e&&(t.push(e),e=""),t.push("2>>&1"),s+=5;continue}if(l.startsWith(">&1")){e&&(t.push(e),e=""),t.push("2>&1"),s+=4;continue}if(l.startsWith(">>")){e&&(t.push(e),e=""),t.push("2>>"),s+=3;continue}if(l.startsWith(">")){e&&(t.push(e),e=""),t.push("2>"),s+=2;continue}}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),s+=2):(t.push(o),s++);continue}e+=o,s++}return e&&t.push(e),t}function Ar(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:Ti(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function Ti(n){let t=_i(n),e=[];for(let r of t){let s={pipeline:{commands:Di(r.text.trim()),isValid:!0}};r.op&&(s.op=r.op),e.push(s)}return e}function _i(n){let t=[],e="",r=0,i=!1,s="",o=0,a=l=>{e.trim()&&t.push({text:e,op:l}),e=""};for(;o<n.length;){let l=n[o],c=n.slice(o,o+2);if((l==='"'||l==="'")&&!i){i=!0,s=l,e+=l,o++;continue}if(i&&l===s){i=!1,e+=l,o++;continue}if(i){e+=l,o++;continue}if(l==="("){r++,e+=l,o++;continue}if(l===")"){r--,e+=l,o++;continue}if(r>0){e+=l,o++;continue}if(c==="&&"){a("&&"),o+=2;continue}if(c==="||"){a("||"),o+=2;continue}if(l===";"){a(";"),o++;continue}e+=l,o++}return a(),t}function Di(n){return Ui(n).map(Li)}function Ui(n){let t=[],e="",r=!1,i="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,i=a,e+=a;continue}if(r&&a===i){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let s=e.trim();if(!s&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&t.push(s),t}function Li(n){let t=Ht(n);if(t.length===0)return{name:"",args:[]};let e=[],r,i,s=!1,o=0,a,l=!1,c=!1;for(;o<t.length;){let m=t[o];if(m==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(m===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");i=t[o],s=!0,o++}else if(m===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");i=t[o],s=!1,o++}else if(m==="2>&1")c=!0,o++;else if(m==="2>>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>>");a=t[o],l=!0,o++}else if(m==="2>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>");a=t[o],l=!1,o++}else e.push(m),o++}let u=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(u)?u:u.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:i,appendOutput:s,stderrFile:a,stderrAppend:l,stderrToStdout:c}}function Tt(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${n}`,USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function Or(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let s=e.vfs.stat(n);return s.type!=="file"||!(s.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let i=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let s of i){if((s==="/sbin"||s==="/usr/sbin")&&r!=="root")continue;let o=`${s}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function _t(n,t,e,r,i,s,o,a,l){let c=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,u=[n,...t],d=0;for(;d<u.length&&c.test(u[d]);)d+=1;if(d>0){let h=u.slice(0,d).map(S=>S.match(c)),y=u.slice(d),f=[];for(let[,S,I]of h)f.push([S,l.vars[S]]),l.vars[S]=I;if(y.length===0)return{exitCode:0};try{return await _t(y[0],y.slice(1),e,r,i,s,o,a,l)}finally{for(let[S,I]of f)I===void 0?delete l.vars[S]:l.vars[S]=I}}let m=l.vars[`__alias_${n}`];if(m)return J(`${m} ${t.join(" ")}`,e,r,i,s,o,a,l);let p=ft(n);if(!p){let h=Or(n,l,o,e);if(h){let y=o.vfs.readFile(h),f=y.match(/exec\s+builtin\s+(\S+)/);if(f){let I=ft(f[1]);if(I)return await I.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:l})}let S=ft("sh");if(S)return await S.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(y)}`,mode:i,args:["-c",y,"--",...t],stdin:a,cwd:s,shell:o,env:l})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await p.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:l})}catch(h){return{stderr:h instanceof Error?h.message:"Command failed",exitCode:1}}}async function J(n,t,e,r,i,s,o,a){let l=n.trim();if(l.length===0)return{exitCode:0};let c=a??Tt(t,e),d=Ht(l)[0]?.toLowerCase()??"",m=c.vars[`__alias_${d}`],p=m?l.replace(d,m):l,h=/\bfor\s+\w+\s+in\b/.test(p)||/\bwhile\s+/.test(p)||/\bif\s+/.test(p)||/\w+\s*\(\s*\)\s*\{/.test(p)||/\bfunction\s+\w+/.test(p)||/\(\(\s*.+\s*\)\)/.test(p),y=/(?<![|&])[|](?![|])/.test(p)||p.includes(">")||p.includes("<")||p.includes("&&")||p.includes("||")||p.includes(";");if(h&&d!=="sh"&&d!=="bash"||y){if(h&&d!=="sh"&&d!=="bash"){let v=ft("sh");if(v)return await v.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:p,mode:r,args:["-c",p],stdin:void 0,cwd:i,shell:s,env:c})}let A=Ar(p);if(!A.isValid)return{stderr:A.error||"Syntax error",exitCode:1};try{return await Ir(A.statements,t,e,r,i,s,c)}catch(v){return{stderr:v instanceof Error?v.message:"Execution failed",exitCode:1}}}let f=await ee(p,c.vars,c.lastExitCode,A=>J(A,t,e,r,i,s,void 0,c).then(v=>v.stdout??"")),S=Ht(f.trim());if(S.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(S[0]))return _t(S[0],S.slice(1),t,e,r,i,s,o,c);let k=S[0]?.toLowerCase()??"",b=S.slice(1).flatMap(te),M=ft(k);if(!M){let A=Or(k,c,s,t);if(A){let v=s.vfs.readFile(A),E=v.match(/exec\s+builtin\s+(\S+)/);if(E){let P=E[1],$=ft(P);if($)return await $.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:[k,...b].join(" "),mode:r,args:b,stdin:o,cwd:i,shell:s,env:c})}let T=ft("sh");if(T)return await T.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(v)}`,mode:r,args:["-c",v,"--",...b],stdin:o,cwd:i,shell:s,env:c})}return{stderr:`${k}: command not found`,exitCode:127}}try{return await M.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:f,mode:r,args:b,stdin:o,cwd:i,shell:s,env:c})}catch(A){return{stderr:A instanceof Error?A.message:"Command failed",exitCode:1}}}async function Te(n,t,e,r){return ee(n,t,e,i=>J(i,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(s=>s.stdout??""))}function $t(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}let i=r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{(.+)\}\s*$/),s=i??(r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{?\s*$/)||r.match(/^function\s+(\w+)\s*\{?\s*$/));if(s){let a=s[1],l=[];if(i){l.push(...i[2].split(";").map(c=>c.trim()).filter(Boolean)),t.push({type:"func",name:a,body:l}),e++;continue}for(e++;e<n.length&&n[e]?.trim()!=="}"&&e<n.length+1;){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="{"&&l.push(c),e++}e++,t.push({type:"func",name:a,body:l});continue}let o=r.match(/^\(\(\s*(.+?)\s*\)\)$/);if(o){t.push({type:"arith",expr:o[1]}),e++;continue}if(r.startsWith("if ")||r==="if"){let a=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),l=[],c=[],u=[],d="then",m="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(d="elif",m=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),c.push({cond:m,body:[]})):p==="else"?d="else":p!=="then"&&(d==="then"?l.push(p):d==="elif"&&c.length>0?c[c.length-1].body.push(p):u.push(p)),e++}t.push({type:"if",cond:a,then_:l,elif:c,else_:u})}else if(r.startsWith("for ")){let a=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(a){let l=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="do"&&l.push(c),e++}t.push({type:"for",var:a[1],list:a[2],body:l})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let a=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),l=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let c=n[e].trim().replace(/^do\s+/,"");c&&c!=="do"&&l.push(c),e++}t.push({type:"while",cond:a,body:l})}else t.push({type:"cmd",line:r});e++}return t}async function Re(n,t){let e=await Te(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let s=r[1],o=s.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,c,u]=o,d=N(t.cwd,u);if(c==="f")return t.shell.vfs.exists(d)&&t.shell.vfs.stat(d).type==="file";if(c==="d")return t.shell.vfs.exists(d)&&t.shell.vfs.stat(d).type==="directory";if(c==="e")return t.shell.vfs.exists(d);if(c==="z")return(u??"").length===0;if(c==="n")return(u??"").length>0}let a=s.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,c,u,d]=a;if(u==="=="||u==="=")return c===d;if(u==="!=")return c!==d}let l=s.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(l){let[,c,u,d]=l,m=Number(c),p=Number(d);if(u==="-eq")return m===p;if(u==="-ne")return m!==p;if(u==="-lt")return m<p;if(u==="-le")return m<=p;if(u==="-gt")return m>p;if(u==="-ge")return m>=p}}return((await J(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function Pt(n,t){let e={exitCode:0},r="";for(let i of n)if(i.type==="cmd"){let s=await Te(i.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=s.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(u=>o.test(u))){for(let u of a){let d=u.match(o);t.env.vars[d[1]]=d[2]}t.env.lastExitCode=0;continue}let l=await(async()=>{let c=s.trim().split(/\s+/)[0]??"",u=t.env.vars[`__func_${c}`];if(u){let d=s.trim().split(/\s+/).slice(1),m={...t.env.vars};d.forEach((y,f)=>{t.env.vars[String(f+1)]=y}),t.env.vars[0]=c;let p=u.split(`
180
990
  `),h=await Pt($t(p),t);for(let y=1;y<=d.length;y++)delete t.env.vars[String(y)];return Object.assign(t.env.vars,{...m,...t.env.vars}),h}return J(s,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)})();if(t.env.lastExitCode=l.exitCode??0,l.stdout&&(r+=`${l.stdout}
181
- `),l.stderr)return{...l,stdout:r.trim()};e=l}else if(i.type==="if"){let s=!1;if(await _e(i.cond,t)){let o=await Pt($t(i.then_),t);o.stdout&&(r+=`${o.stdout}
182
- `),s=!0}else{for(let o of i.elif)if(await _e(o.cond,t)){let a=await Pt($t(o.body),t);a.stdout&&(r+=`${a.stdout}
991
+ `),l.stderr)return{...l,stdout:r.trim()};e=l}else if(i.type==="if"){let s=!1;if(await Re(i.cond,t)){let o=await Pt($t(i.then_),t);o.stdout&&(r+=`${o.stdout}
992
+ `),s=!0}else{for(let o of i.elif)if(await Re(o.cond,t)){let a=await Pt($t(o.body),t);a.stdout&&(r+=`${a.stdout}
183
993
  `),s=!0;break}if(!s&&i.else_.length>0){let o=await Pt($t(i.else_),t);o.stdout&&(r+=`${o.stdout}
184
994
  `)}}}else if(i.type==="func")t.env.vars[`__func_${i.name}`]=i.body.join(`
185
- `);else if(i.type==="arith"){let s=i.expr.trim(),o=s.match(/^(\w+)\s*(\+\+|--)$/);if(o){let a=parseInt(t.env.vars[o[1]]??"0",10);t.env.vars[o[1]]=String(o[2]==="++"?a+1:a-1)}else{let a=s.match(/^(\w+)\s*([+\-*/])=\s*(.+)$/);if(a){let l=parseInt(t.env.vars[a[1]]??"0",10),c=parseInt(a[3],10),u={"+":l+c,"-":l-c,"*":l*c,"/":Math.floor(l/c)};t.env.vars[a[1]]=String(u[a[2]]??l)}else{let l=Ce(s,t.env.vars);Number.isNaN(l)||(t.env.lastExitCode=l===0?1:0)}}}else if(i.type==="for"){let o=(await Ie(i.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(Xt);for(let a of o){t.env.vars[i.var]=a;let l=await Pt($t(i.body),t);if(l.stdout&&(r+=`${l.stdout}
186
- `),l.closeSession)return l}}else if(i.type==="while"){let s=0;for(;s<1e3&&await _e(i.cond,t);){let o=await Pt($t(i.body),t);if(o.stdout&&(r+=`${o.stdout}
187
- `),o.closeSession)return o;s++}}return{...e,stdout:r.trim()||e.stdout}}function Ar(n){let t=[],e="",r=0,i=!1,s=!1,o=0;for(;o<n.length;){let l=n[o];if(!i&&!s){if(l==="'"){i=!0,e+=l,o++;continue}if(l==='"'){s=!0,e+=l,o++;continue}if(l==="{"){r++,e+=l,o++;continue}if(l==="}"){if(r--,e+=l,o++,r===0){let c=e.trim();for(c&&t.push(c),e="";o<n.length&&(n[o]===";"||n[o]===" ");)o++}continue}if(r===0&&(l===";"||l===`
188
- `)){let c=e.trim();c&&!c.startsWith("#")&&t.push(c),e="",o++;continue}}else i&&l==="'"?i=!1:s&&l==='"'&&(s=!1);e+=l,o++}let a=e.trim();return a&&!a.startsWith("#")&&t.push(a),t}var Fr={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,shell:e,cwd:r}=n;if(w(t,"-c")){let s=t[t.indexOf("-c")+1]??"";if(!s)return{stderr:"sh: -c requires a script",exitCode:1};let o=Ar(s),a=$t(o);return Pt(a,n)}let i=t[0];if(i){let s=k(r,i);if(!e.vfs.exists(s))return{stderr:`sh: ${i}: No such file or directory`,exitCode:1};let o=e.vfs.readFile(s),a=Ar(o),l=$t(a);return Pt(l,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var Nr={name:"shift",description:"Shift positional parameters",category:"shell",params:["[n]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=parseInt(n[0]??"1",10)||1,r=t.vars.__argv?.split("\0").filter(Boolean)??[];t.vars.__argv=r.slice(e).join("\0");let i=r.slice(e);for(let s=1;s<=9;s++)t.vars[String(s)]=i[s-1]??"";return{exitCode:0}}},_r={name:"trap",description:"Trap signals and events",category:"shell",params:["[action] [signal...]"],run:({args:n,env:t})=>{if(!t||n.length===0)return{exitCode:0};let e=n[0]??"",r=n.slice(1);for(let i of r)t.vars[`__trap_${i.toUpperCase()}`]=e;return{exitCode:0}}},Ir={name:"return",description:"Return from a shell function",category:"shell",params:["[n]"],run:({args:n,env:t})=>{let e=parseInt(n[0]??"0",10);return t&&(t.lastExitCode=e),{exitCode:e}}};var Rr={name:"sleep",description:"Delay execution",category:"system",params:["<seconds>"],run:async({args:n})=>{let t=parseFloat(n[0]??"1");return Number.isNaN(t)||t<0?{stderr:"sleep: invalid time",exitCode:1}:(await new Promise(e=>setTimeout(e,t*1e3)),{exitCode:0})}};var Vr={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-r"]),o=w(r,["-n"]),a=w(r,["-u"]),l=r.filter(h=>!h.startsWith("-")),d=[...(l.length>0?l.map(h=>{try{return L(n,k(e,h),"sort"),t.vfs.readFile(k(e,h))}catch{return""}}).join(`
995
+ `);else if(i.type==="arith"){let s=i.expr.trim(),o=s.match(/^(\w+)\s*(\+\+|--)$/);if(o){let a=parseInt(t.env.vars[o[1]]??"0",10);t.env.vars[o[1]]=String(o[2]==="++"?a+1:a-1)}else{let a=s.match(/^(\w+)\s*([+\-*/])=\s*(.+)$/);if(a){let l=parseInt(t.env.vars[a[1]]??"0",10),c=parseInt(a[3],10),u={"+":l+c,"-":l-c,"*":l*c,"/":Math.floor(l/c)};t.env.vars[a[1]]=String(u[a[2]]??l)}else{let l=Pe(s,t.env.vars);Number.isNaN(l)||(t.env.lastExitCode=l===0?1:0)}}}else if(i.type==="for"){let o=(await Te(i.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(te);for(let a of o){t.env.vars[i.var]=a;let l=await Pt($t(i.body),t);if(l.stdout&&(r+=`${l.stdout}
996
+ `),l.closeSession)return l}}else if(i.type==="while"){let s=0;for(;s<1e3&&await Re(i.cond,t);){let o=await Pt($t(i.body),t);if(o.stdout&&(r+=`${o.stdout}
997
+ `),o.closeSession)return o;s++}}return{...e,stdout:r.trim()||e.stdout}}function Fr(n){let t=[],e="",r=0,i=!1,s=!1,o=0;for(;o<n.length;){let l=n[o];if(!i&&!s){if(l==="'"){i=!0,e+=l,o++;continue}if(l==='"'){s=!0,e+=l,o++;continue}if(l==="{"){r++,e+=l,o++;continue}if(l==="}"){if(r--,e+=l,o++,r===0){let c=e.trim();for(c&&t.push(c),e="";o<n.length&&(n[o]===";"||n[o]===" ");)o++}continue}if(r===0&&(l===";"||l===`
998
+ `)){let c=e.trim();c&&!c.startsWith("#")&&t.push(c),e="",o++;continue}}else i&&l==="'"?i=!1:s&&l==='"'&&(s=!1);e+=l,o++}let a=e.trim();return a&&!a.startsWith("#")&&t.push(a),t}var Rr={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,shell:e,cwd:r}=n;if(w(t,"-c")){let s=t[t.indexOf("-c")+1]??"";if(!s)return{stderr:"sh: -c requires a script",exitCode:1};let o=Fr(s),a=$t(o);return Pt(a,n)}let i=t[0];if(i){let s=N(r,i);if(!e.vfs.exists(s))return{stderr:`sh: ${i}: No such file or directory`,exitCode:1};let o=e.vfs.readFile(s),a=Fr(o),l=$t(a);return Pt(l,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var Tr={name:"shift",description:"Shift positional parameters",category:"shell",params:["[n]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=parseInt(n[0]??"1",10)||1,r=t.vars.__argv?.split("\0").filter(Boolean)??[];t.vars.__argv=r.slice(e).join("\0");let i=r.slice(e);for(let s=1;s<=9;s++)t.vars[String(s)]=i[s-1]??"";return{exitCode:0}}},_r={name:"trap",description:"Trap signals and events",category:"shell",params:["[action] [signal...]"],run:({args:n,env:t})=>{if(!t||n.length===0)return{exitCode:0};let e=n[0]??"",r=n.slice(1);for(let i of r)t.vars[`__trap_${i.toUpperCase()}`]=e;return{exitCode:0}}},Dr={name:"return",description:"Return from a shell function",category:"shell",params:["[n]"],run:({args:n,env:t})=>{let e=parseInt(n[0]??"0",10);return t&&(t.lastExitCode=e),{exitCode:e}}};var Ur={name:"sleep",description:"Delay execution",category:"system",params:["<seconds>"],run:async({args:n})=>{let t=parseFloat(n[0]??"1");return Number.isNaN(t)||t<0?{stderr:"sleep: invalid time",exitCode:1}:(await new Promise(e=>setTimeout(e,t*1e3)),{exitCode:0})}};var Lr={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-r"]),o=w(r,["-n"]),a=w(r,["-u"]),l=r.filter(h=>!h.startsWith("-")),d=[...(l.length>0?l.map(h=>{try{return D(n,N(e,h),"sort"),t.vfs.readFile(N(e,h))}catch{return""}}).join(`
189
999
  `):i??"").split(`
190
1000
  `).filter(Boolean)].sort((h,y)=>o?Number(h)-Number(y):h.localeCompare(y)),m=s?d.reverse():d;return{stdout:(a?[...new Set(m)]:m).join(`
191
- `),exitCode:0}}};var Dr={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:n,authUser:t,hostname:e,cwd:r,shell:i,env:s})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=k(r,o);if(!i.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let l=i.vfs.readFile(a),c=0;for(let u of l.split(`
192
- `)){let d=u.trim();if(!d||d.startsWith("#"))continue;let m=await J(d,t,e,"shell",r,i,void 0,s);if(c=m.exitCode??0,m.closeSession||m.switchUser)return m}return{exitCode:c}}};var Lr={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:i,cwd:s})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),l=a!==-1?e[a+1]:void 0,u=e.filter((d,m)=>m!==a&&m!==a+1).filter(d=>d!=="-"&&d!=="-l"&&d!=="--login").find(d=>!d.startsWith("-"))??"root";return t.users.listUsers().includes(u)?n==="root"?l?J(l,u,r,i,o?`/home/${u}`:s,t):{switchUser:u,nextCwd:o?`/home/${u}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:u,targetUser:u,commandLine:l??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
1001
+ `),exitCode:0}}};var Vr={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:n,authUser:t,hostname:e,cwd:r,shell:i,env:s})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=N(r,o);if(!i.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let l=i.vfs.readFile(a),c=0;for(let u of l.split(`
1002
+ `)){let d=u.trim();if(!d||d.startsWith("#"))continue;let m=await J(d,t,e,"shell",r,i,void 0,s);if(c=m.exitCode??0,m.closeSession||m.switchUser)return m}return{exitCode:c}}};var zr={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:i,cwd:s})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),l=a!==-1?e[a+1]:void 0,u=e.filter((d,m)=>m!==a&&m!==a+1).filter(d=>d!=="-"&&d!=="-l"&&d!=="--login").find(d=>!d.startsWith("-"))??"root";return t.users.listUsers().includes(u)?n==="root"?l?J(l,u,r,i,o?`/home/${u}`:s,t):{switchUser:u,nextCwd:o?`/home/${u}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:u,targetUser:u,commandLine:l??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
193
1003
  `,exitCode:1}:{stderr:`su: user '${u}' does not exist
194
- `,exitCode:1}}};function Ui(n){let{flags:t,flagsWithValues:e,positionals:r}=at(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),i=t.has("-i"),s=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:s,loginShell:i,commandLine:o}}var zr={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:i,args:s})=>{let{targetUser:o,loginShell:a,commandLine:l}=Ui(s);if(n!=="root"&&!i.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let c=o||"root",u=`[sudo] password for ${n}: `;return n==="root"?!l&&a?{switchUser:c,nextCwd:`/home/${c}`,exitCode:0}:l?J(l,c,t,e,a?`/home/${c}`:r,i):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:c,commandLine:l,loginShell:a,prompt:u},exitCode:0}}};var Tr={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ct(r,["-n"]),o=r.find(d=>/^-\d+$/.test(d)),a=typeof s=="string"?parseInt(s,10):o?parseInt(o.slice(1),10):10,l=r.filter(d=>!d.startsWith("-")&&d!==s&&d!==String(a)),c=d=>{let m=d.split(`
1004
+ `,exitCode:1}}};function Vi(n){let{flags:t,flagsWithValues:e,positionals:r}=at(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),i=t.has("-i"),s=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:s,loginShell:i,commandLine:o}}var Br={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:i,args:s})=>{let{targetUser:o,loginShell:a,commandLine:l}=Vi(s);if(n!=="root"&&!i.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let c=o||"root",u=`[sudo] password for ${n}: `;return n==="root"?!l&&a?{switchUser:c,nextCwd:`/home/${c}`,exitCode:0}:l?J(l,c,t,e,a?`/home/${c}`:r,i):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:c,commandLine:l,loginShell:a,prompt:u},exitCode:0}}};var Wr={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ct(r,["-n"]),o=r.find(d=>/^-\d+$/.test(d)),a=typeof s=="string"?parseInt(s,10):o?parseInt(o.slice(1),10):10,l=r.filter(d=>!d.startsWith("-")&&d!==s&&d!==String(a)),c=d=>{let m=d.split(`
195
1005
  `),p=d.endsWith(`
196
1006
  `),h=p?m.slice(0,-1):m;return h.slice(Math.max(0,h.length-a)).join(`
197
1007
  `)+(p?`
198
- `:"")};if(l.length===0)return{stdout:c(i??""),exitCode:0};let u=[];for(let d of l){let m=k(e,d);try{L(n,m,"tail"),u.push(c(t.vfs.readFile(m)))}catch{return{stderr:`tail: ${d}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
199
- `),exitCode:0}}};var Ur={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=[],s=!1;for(let m of r)if(/^-[a-zA-Z]{2,}$/.test(m))for(let p of m.slice(1))i.push(`-${p}`);else if(!s&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(m)&&!m.includes("/")&&!m.startsWith("-")){s=!0;for(let p of m)i.push(`-${p}`)}else i.push(m);let o=i.includes("-c"),a=i.includes("-x"),l=i.includes("-t"),c=i.indexOf("-f"),u=c!==-1?i[c+1]:i.find(m=>m.endsWith(".tar")||m.endsWith(".tar.gz")||m.endsWith(".tgz"));if(!o&&!a&&!l)return{stderr:`tar: must specify -c, -x, or -t
1008
+ `:"")};if(l.length===0)return{stdout:c(i??""),exitCode:0};let u=[];for(let d of l){let m=N(e,d);try{D(n,m,"tail"),u.push(c(t.vfs.readFile(m)))}catch{return{stderr:`tail: ${d}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
1009
+ `),exitCode:0}}};var jr={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=[],s=!1;for(let m of r)if(/^-[a-zA-Z]{2,}$/.test(m))for(let p of m.slice(1))i.push(`-${p}`);else if(!s&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(m)&&!m.includes("/")&&!m.startsWith("-")){s=!0;for(let p of m)i.push(`-${p}`)}else i.push(m);let o=i.includes("-c"),a=i.includes("-x"),l=i.includes("-t"),c=i.indexOf("-f"),u=c!==-1?i[c+1]:i.find(m=>m.endsWith(".tar")||m.endsWith(".tar.gz")||m.endsWith(".tgz"));if(!o&&!a&&!l)return{stderr:`tar: must specify -c, -x, or -t
200
1010
  `,exitCode:1};if(!u)return{stderr:`tar: no archive specified
201
- `,exitCode:1};let d=k(e,u);if(o){let m=new Set;c!==-1&&m.add(c+1);let p=i.filter((y,f)=>!y.startsWith("-")&&y!==u&&!m.has(f)),h={};for(let y of p){let f=k(e,y);try{if(t.vfs.stat(f).type==="file")h[y]=t.vfs.readFile(f);else{let F=(A,x)=>{for(let E of t.vfs.list(A)){let N=`${A}/${E}`,b=`${x}/${E}`;t.vfs.stat(N).type==="file"?h[b]=t.vfs.readFile(N):F(N,b)}};F(f,y)}}catch{return{stderr:`tar: ${y}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,d,JSON.stringify(h)),{exitCode:0}}if(l||a){let m;try{m=JSON.parse(t.vfs.readFile(d))}catch{return{stderr:`tar: ${u}: cannot open archive`,exitCode:1}}if(l)return{stdout:Object.keys(m).join(`
202
- `),exitCode:0};for(let[p,h]of Object.entries(m))t.writeFileAsUser(n,k(e,p),h);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Br={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-a"]),o=r.filter(l=>!l.startsWith("-")),a=i??"";for(let l of o){let c=k(e,l);if(s){let u=(()=>{try{return t.vfs.readFile(c)}catch{return""}})();t.writeFileAsUser(n,c,u+a)}else t.writeFileAsUser(n,c,a)}return{stdout:a,exitCode:0}}};function Vt(n,t,e){if(n[n.length-1]==="]"&&(n=n.slice(0,-1)),n[0]==="["&&(n=n.slice(1)),n.length===0)return!1;if(n[0]==="!")return!Vt(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return Vt(n.slice(0,r),t,e)&&Vt(n.slice(r+1),t,e);let i=n.indexOf("-o");if(i!==-1)return Vt(n.slice(0,i),t,e)||Vt(n.slice(i+1),t,e);if(n.length===2){let[s,o=""]=n,l=(c=>c.startsWith("/")?c:`${e}/${c}`.replace(/\/+/g,"/"))(o);switch(s){case"-e":return t.vfs.exists(l);case"-f":return t.vfs.exists(l)&&t.vfs.stat(l).type==="file";case"-d":return t.vfs.exists(l)&&t.vfs.stat(l).type==="directory";case"-r":return t.vfs.exists(l);case"-w":return t.vfs.exists(l);case"-x":return t.vfs.exists(l)&&!!(t.vfs.stat(l).mode&73);case"-s":return t.vfs.exists(l)&&t.vfs.stat(l).type==="file"&&t.vfs.stat(l).size>0;case"-z":return o.length===0;case"-n":return o.length>0;case"-L":return t.vfs.isSymlink(l)}}if(n.length===3){let[s="",o,a=""]=n,l=Number(s),c=Number(a);switch(o){case"=":case"==":return s===a;case"!=":return s!==a;case"<":return s<a;case">":return s>a;case"-eq":return l===c;case"-ne":return l!==c;case"-lt":return l<c;case"-le":return l<=c;case"-gt":return l>c;case"-ge":return l>=c}}return n.length===1?(n[0]??"").length>0:!1}var Or={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:Vt([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var Wr={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let i of r){let s=k(e,i);L(n,s,"touch"),t.vfs.exists(s)||t.writeFileAsUser(n,s,"")}return{exitCode:0}}};function Bi(n){return n.replace(/\\n/g,`
203
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function jr(n){let t=[],e=Bi(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let i=e.charCodeAt(r),s=e.charCodeAt(r+2);if(i<=s){for(let o=i;o<=s;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var Hr={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=w(n,["-d"]),r=w(n,["-s"]),i=n.filter(l=>!l.startsWith("-")),s=jr(i[0]??""),o=jr(i[1]??""),a=t??"";if(e){let l=new Set(s);a=[...a].filter(c=>!l.has(c)).join("")}else if(o.length>0){let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],o[c]??o[o.length-1]??"");a=[...a].map(c=>l.get(c)??c).join("")}if(r&&o.length>0){let l=new Set(o);a=a.replace(/(.)\1+/g,(c,u)=>l.has(u)?u:c)}return{stdout:a,exitCode:0}}};var qr={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=k(e,Ct(r,0)??e);return L(n,i,"tree"),{stdout:t.vfs.tree(i),exitCode:0}}};var Kr={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},Gr={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Jr={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"type: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=0;for(let o of n){if(ft(o)){i.push(`${o} is a shell builtin`);continue}let a=!1;for(let l of r){let c=`${l}/${o}`;if(t.vfs.exists(c)){i.push(`${o} is ${c}`),a=!0;break}}a||(i.push(`${o}: not found`),s=1)}return{stdout:i.join(`
204
- `),exitCode:s}}};var Zr={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=w(t,["-a"]),r="Linux",i=n.properties?.kernel??"5.15.0",s=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${i} #1 SMP ${s} GNU/Linux`,exitCode:0}:w(t,["-r"])?{stdout:i,exitCode:0}:w(t,["-m"])?{stdout:s,exitCode:0}:{stdout:r,exitCode:0}}};var Yr={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=w(n,["-c"]),r=w(n,["-d"]),i=w(n,["-u"]),s=(t??"").split(`
1011
+ `,exitCode:1};let d=N(e,u);if(o){let m=new Set;c!==-1&&m.add(c+1);let p=i.filter((y,f)=>!y.startsWith("-")&&y!==u&&!m.has(f)),h={};for(let y of p){let f=N(e,y);try{if(t.vfs.stat(f).type==="file")h[y]=t.vfs.readFile(f);else{let I=(k,b)=>{for(let M of t.vfs.list(k)){let A=`${k}/${M}`,v=`${b}/${M}`;t.vfs.stat(A).type==="file"?h[v]=t.vfs.readFile(A):I(A,v)}};I(f,y)}}catch{return{stderr:`tar: ${y}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,d,JSON.stringify(h)),{exitCode:0}}if(l||a){let m;try{m=JSON.parse(t.vfs.readFile(d))}catch{return{stderr:`tar: ${u}: cannot open archive`,exitCode:1}}if(l)return{stdout:Object.keys(m).join(`
1012
+ `),exitCode:0};for(let[p,h]of Object.entries(m))t.writeFileAsUser(n,N(e,p),h);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Hr={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-a"]),o=r.filter(l=>!l.startsWith("-")),a=i??"";for(let l of o){let c=N(e,l);if(s){let u=(()=>{try{return t.vfs.readFile(c)}catch{return""}})();t.writeFileAsUser(n,c,u+a)}else t.writeFileAsUser(n,c,a)}return{stdout:a,exitCode:0}}};function Dt(n,t,e){if(n[n.length-1]==="]"&&(n=n.slice(0,-1)),n[0]==="["&&(n=n.slice(1)),n.length===0)return!1;if(n[0]==="!")return!Dt(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return Dt(n.slice(0,r),t,e)&&Dt(n.slice(r+1),t,e);let i=n.indexOf("-o");if(i!==-1)return Dt(n.slice(0,i),t,e)||Dt(n.slice(i+1),t,e);if(n.length===2){let[s,o=""]=n,l=(c=>c.startsWith("/")?c:`${e}/${c}`.replace(/\/+/g,"/"))(o);switch(s){case"-e":return t.vfs.exists(l);case"-f":return t.vfs.exists(l)&&t.vfs.stat(l).type==="file";case"-d":return t.vfs.exists(l)&&t.vfs.stat(l).type==="directory";case"-r":return t.vfs.exists(l);case"-w":return t.vfs.exists(l);case"-x":return t.vfs.exists(l)&&!!(t.vfs.stat(l).mode&73);case"-s":return t.vfs.exists(l)&&t.vfs.stat(l).type==="file"&&t.vfs.stat(l).size>0;case"-z":return o.length===0;case"-n":return o.length>0;case"-L":return t.vfs.isSymlink(l)}}if(n.length===3){let[s="",o,a=""]=n,l=Number(s),c=Number(a);switch(o){case"=":case"==":return s===a;case"!=":return s!==a;case"<":return s<a;case">":return s>a;case"-eq":return l===c;case"-ne":return l!==c;case"-lt":return l<c;case"-le":return l<=c;case"-gt":return l>c;case"-ge":return l>=c}}return n.length===1?(n[0]??"").length>0:!1}var qr={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:Dt([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var Yr={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let i of r){let s=N(e,i);D(n,s,"touch"),t.vfs.exists(s)||t.writeFileAsUser(n,s,"")}return{exitCode:0}}};function zi(n){return n.replace(/\\n/g,`
1013
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Kr(n){let t=[],e=zi(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let i=e.charCodeAt(r),s=e.charCodeAt(r+2);if(i<=s){for(let o=i;o<=s;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var Gr={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=w(n,["-d"]),r=w(n,["-s"]),i=n.filter(l=>!l.startsWith("-")),s=Kr(i[0]??""),o=Kr(i[1]??""),a=t??"";if(e){let l=new Set(s);a=[...a].filter(c=>!l.has(c)).join("")}else if(o.length>0){let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],o[c]??o[o.length-1]??"");a=[...a].map(c=>l.get(c)??c).join("")}if(r&&o.length>0){let l=new Set(o);a=a.replace(/(.)\1+/g,(c,u)=>l.has(u)?u:c)}return{stdout:a,exitCode:0}}};var Jr={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=N(e,Ct(r,0)??e);return D(n,i,"tree"),{stdout:t.vfs.tree(i),exitCode:0}}};var Zr={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},Qr={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Xr={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"type: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=0;for(let o of n){if(ft(o)){i.push(`${o} is a shell builtin`);continue}let a=!1;for(let l of r){let c=`${l}/${o}`;if(t.vfs.exists(c)){i.push(`${o} is ${c}`),a=!0;break}}a||(i.push(`${o}: not found`),s=1)}return{stdout:i.join(`
1014
+ `),exitCode:s}}};var ts={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=w(t,["-a"]),r="Linux",i=n.properties?.kernel??"5.15.0",s=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${i} #1 SMP ${s} GNU/Linux`,exitCode:0}:w(t,["-r"])?{stdout:i,exitCode:0}:w(t,["-m"])?{stdout:s,exitCode:0}:{stdout:r,exitCode:0}}};var es={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=w(n,["-c"]),r=w(n,["-d"]),i=w(n,["-u"]),s=(t??"").split(`
205
1015
  `),o=[],a=0;for(;a<s.length;){let l=a;for(;l<s.length&&s[l]===s[a];)l++;let c=l-a,u=s[a];if(r&&c===1){a=l;continue}if(i&&c>1){a=l;continue}o.push(e?`${String(c).padStart(4)} ${u}`:u),a=l}return{stdout:o.join(`
206
- `),exitCode:0}}};var Qr={name:"unset",description:"Remove shell variable",category:"shell",params:["<VAR>"],run:({args:n,env:t})=>{for(let e of n)delete t.vars[e];return{exitCode:0}}};var Xr={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=w(n,["-p"]),r=w(n,["-s"]),i=Math.floor((Date.now()-t.startTime)/1e3),s=Math.floor(i/86400),o=Math.floor(i%86400/3600),a=Math.floor(i%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let m=[];return s>0&&m.push(`${s} day${s>1?"s":""}`),o>0&&m.push(`${o} hour${o>1?"s":""}`),m.push(`${a} minute${a!==1?"s":""}`),{stdout:`up ${m.join(", ")}`,exitCode:0}}let l=new Date().toTimeString().slice(0,8),c=s>0?`${s} day${s>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,u=t.users.listActiveSessions().length,d=(Math.random()*.5).toFixed(2);return{stdout:` ${l} up ${c}, ${u} user${u!==1?"s":""}, load average: ${d}, ${d}, ${d}`,exitCode:0}}};var ts={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-l"]),o=w(r,["-w"]),a=w(r,["-c"]),l=!s&&!o&&!a,c=r.filter(m=>!m.startsWith("-")),u=(m,p)=>{let h=m.length===0?0:m.trim().split(`
207
- `).length,y=m.trim().split(/\s+/).filter(Boolean).length,f=Buffer.byteLength(m,"utf8"),S=[];return(l||s)&&S.push(String(h).padStart(7)),(l||o)&&S.push(String(y).padStart(7)),(l||a)&&S.push(String(f).padStart(7)),p&&S.push(` ${p}`),S.join("")};if(c.length===0)return{stdout:u(i??"",""),exitCode:0};let d=[];for(let m of c){let p=k(e,m);try{L(n,p,"wc");let h=t.vfs.readFile(p);d.push(u(h,m))}catch{return{stderr:`wc: ${m}: No such file or directory`,exitCode:1}}}return{stdout:d.join(`
208
- `),exitCode:0}}};var es={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=at(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(w(e,["-h","--help"]))return{stdout:["Usage: wget [option]... [URL]..."," -O, --output-document=FILE Write to FILE ('-' for stdout)"," -P, --directory-prefix=DIR Save files in DIR"," -q, --quiet Quiet mode"," -v, --verbose Verbose output (default)"," -c, --continue Continue partial download"," --tries=N Retry N times"," --timeout=N Timeout in seconds"].join(`
1016
+ `),exitCode:0}}};var ns={name:"unset",description:"Remove shell variable",category:"shell",params:["<VAR>"],run:({args:n,env:t})=>{for(let e of n)delete t.vars[e];return{exitCode:0}}};var rs={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=w(n,["-p"]),r=w(n,["-s"]),i=Math.floor((Date.now()-t.startTime)/1e3),s=Math.floor(i/86400),o=Math.floor(i%86400/3600),a=Math.floor(i%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let m=[];return s>0&&m.push(`${s} day${s>1?"s":""}`),o>0&&m.push(`${o} hour${o>1?"s":""}`),m.push(`${a} minute${a!==1?"s":""}`),{stdout:`up ${m.join(", ")}`,exitCode:0}}let l=new Date().toTimeString().slice(0,8),c=s>0?`${s} day${s>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,u=t.users.listActiveSessions().length,d=(Math.random()*.5).toFixed(2);return{stdout:` ${l} up ${c}, ${u} user${u!==1?"s":""}, load average: ${d}, ${d}, ${d}`,exitCode:0}}};var ss={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=w(r,["-l"]),o=w(r,["-w"]),a=w(r,["-c"]),l=!s&&!o&&!a,c=r.filter(m=>!m.startsWith("-")),u=(m,p)=>{let h=m.length===0?0:m.trim().split(`
1017
+ `).length,y=m.trim().split(/\s+/).filter(Boolean).length,f=Buffer.byteLength(m,"utf8"),S=[];return(l||s)&&S.push(String(h).padStart(7)),(l||o)&&S.push(String(y).padStart(7)),(l||a)&&S.push(String(f).padStart(7)),p&&S.push(` ${p}`),S.join("")};if(c.length===0)return{stdout:u(i??"",""),exitCode:0};let d=[];for(let m of c){let p=N(e,m);try{D(n,p,"wc");let h=t.vfs.readFile(p);d.push(u(h,m))}catch{return{stderr:`wc: ${m}: No such file or directory`,exitCode:1}}}return{stdout:d.join(`
1018
+ `),exitCode:0}}};var is={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=at(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(w(e,["-h","--help"]))return{stdout:["Usage: wget [option]... [URL]..."," -O, --output-document=FILE Write to FILE ('-' for stdout)"," -P, --directory-prefix=DIR Save files in DIR"," -q, --quiet Quiet mode"," -v, --verbose Verbose output (default)"," -c, --continue Continue partial download"," --tries=N Retry N times"," --timeout=N Timeout in seconds"].join(`
209
1019
  `),exitCode:0};if(w(e,["-V","--version"]))return{stdout:"GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",exitCode:0};let o=s[0];if(!o)return{stderr:`wget: missing URL
210
1020
  Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;if(!a)return{stderr:`wget: missing URL
211
- Usage: wget [OPTION]... [URL]...`,exitCode:1};let l=i.get("-O")??i.get("--output-document")??null,c=i.get("-P")??i.get("--directory-prefix")??null,u=w(e,["-q","--quiet"]),d=l==="-"?null:l??Qe(a),m=d?k(t,c?`${c}/${d}`:d):null;m&&L(n,m,"wget");let p=[];u||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let h;try{h=await fetch(a,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(f){let S=f instanceof Error?f.message:String(f);return p.push(`wget: unable to resolve host: ${S}`),{stderr:p.join(`
1021
+ Usage: wget [OPTION]... [URL]...`,exitCode:1};let l=i.get("-O")??i.get("--output-document")??null,c=i.get("-P")??i.get("--directory-prefix")??null,u=w(e,["-q","--quiet"]),d=l==="-"?null:l??en(a),m=d?N(t,c?`${c}/${d}`:d):null;m&&D(n,m,"wget");let p=[];u||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let h;try{h=await fetch(a,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(f){let S=f instanceof Error?f.message:String(f);return p.push(`wget: unable to resolve host: ${S}`),{stderr:p.join(`
212
1022
  `),exitCode:4}}if(!h.ok)return p.push(`ERROR ${h.status}: ${h.statusText}`),{stderr:p.join(`
213
1023
  `),exitCode:8};let y;try{y=await h.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!u){let f=h.headers.get("content-type")??"application/octet-stream";p.push(`HTTP request sent, awaiting response... ${h.status} ${h.statusText}`),p.push(`Length: ${y.length} [${f}]`)}return l==="-"?{stdout:y,stderr:p.join(`
214
1024
  `)||void 0,exitCode:0}:m?(r.writeFileAsUser(n,m,y),u||p.push(`Saving to: '${m}'
215
1025
  ${m} 100%[==================>] ${y.length} B`),{stderr:p.join(`
216
- `)||void 0,exitCode:0}):{stdout:y,exitCode:0}}};var ns={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"which: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=!1;for(let o of n){let a=!1;for(let l of r){let c=`${l}/${o}`;if(t.vfs.exists(c)&&t.vfs.stat(c).type==="file"){i.push(c),a=!0;break}}a||(s=!0)}return i.length===0?{exitCode:1}:{stdout:i.join(`
217
- `),exitCode:s?1:0}}};function ue(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),i=n.getHours().toString().padStart(2,"0"),s=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${i}:${s}:${o} ${a}`}var rs={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),i=Number.isNaN(r.getTime())?e.startedAt:ue(r);return`${e.username} ${e.tty} ${i} (${e.remoteAddress||"unknown"})`}).join(`
218
- `),exitCode:0})};var ss={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var is={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:n,hostname:t,mode:e,cwd:r,args:i,stdin:s,shell:o,env:a})=>{let l=i[0]??"echo",c=i.slice(1),u=(s??"").trim().split(/\s+/).filter(Boolean);if(u.length===0)return{exitCode:0};let d=[l,...c,...u].join(" ");return J(d,n,t,e,r,o,void 0,a)}};var Oi=[Sr,on,qn,qr,sn,Wr,Cr,Jn,cn,Zn,Bn,On,an,Wn,jn,$n,kn,$r,nn,Vr,Yr,ts,Fn,Tr,dn,Hr,Br,is,gn,Ur,En,An,rn,ss,rs,Ln,Tn,Mn,Zr,yr,Un,hn,wn,mn,Rr,hr,xn,bn,Cn,Pr,Qr,Fr,ln,vn,Qn,zn,un,es,Ge,fr,fn,zr,Lr,lr,tn,en,yn,Sn,ns,Jr,Gn,Ze,Ye,Or,Dr,Dn,gr,vr,pn,Nr,_r,Ir,Kr,Gr,mr,pr,dr,br,Xr,Pn,Kn],os=[],Ht=new Map,de=null,Wi=Vn(()=>Ve().map(n=>n.name));function Re(){Ht.clear();for(let n of Ve()){Ht.set(n.name,n);for(let t of n.aliases??[])Ht.set(t,n)}de=Array.from(Ht.keys()).sort()}function Ve(){return[...Oi,...os,Wi]}function Fe(n){let t={...n,name:n.name.trim().toLowerCase(),aliases:n.aliases?.map(r=>r.trim().toLowerCase())};if([t.name,...t.aliases??[]].some(r=>r.length===0||/\s/.test(r)))throw new Error("Command names must be non-empty and contain no spaces");os.push(t),Re()}function Ne(n,t,e){return{name:n,params:t,run:e}}function Wt(){return de||Re(),de}function $e(){return Ve()}function ft(n){return de||Re(),Ht.get(n.toLowerCase())}import{spawn as Hi}from"node:child_process";import{readFile as ji}from"node:fs/promises";import*as me from"node:path";function De(n){return`'${n.replace(/'/g,"'\\''")}'`}function qt(n){return n.replace(/\r\n/g,`
1026
+ `)||void 0,exitCode:0}):{stdout:y,exitCode:0}}};var os={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"which: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=!1;for(let o of n){let a=!1;for(let l of r){let c=`${l}/${o}`;if(t.vfs.exists(c)&&t.vfs.stat(c).type==="file"){i.push(c),a=!0;break}}a||(s=!0)}return i.length===0?{exitCode:1}:{stdout:i.join(`
1027
+ `),exitCode:s?1:0}}};function ue(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),i=n.getHours().toString().padStart(2,"0"),s=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${i}:${s}:${o} ${a}`}var as={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),i=Number.isNaN(r.getTime())?e.startedAt:ue(r);return`${e.username} ${e.tty} ${i} (${e.remoteAddress||"unknown"})`}).join(`
1028
+ `),exitCode:0})};var ls={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var cs={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:n,hostname:t,mode:e,cwd:r,args:i,stdin:s,shell:o,env:a})=>{let l=i[0]??"echo",c=i.slice(1),u=(s??"").trim().split(/\s+/).filter(Boolean);if(u.length===0)return{exitCode:0};let d=[l,...c,...u].join(" ");return J(d,n,t,e,r,o,void 0,a)}};var Bi=[xr,cn,Gn,Jr,ln,Yr,Er,Xn,mn,tr,jn,Hn,un,qn,Yn,En,kn,Mr,on,Lr,es,ss,Fn,Wr,fn,Gr,Hr,cs,wn,jr,An,On,an,ls,as,Vn,Bn,In,ts,vr,Wn,Sn,xn,hn,Ur,wr,Cn,$n,Nn,kr,ns,Rr,dn,Pn,nr,zn,pn,is,Ze,Sr,yn,Br,zr,mr,rn,sn,bn,vn,os,Xr,Qn,Xe,tn,qr,Vr,Ln,br,Nr,gn,Tr,_r,Dr,Zr,Qr,gr,yr,hr,Pr,rs,Mn,Jn],us=[],qt=new Map,de=null,Wi=Un(()=>De().map(n=>n.name));function _e(){qt.clear();for(let n of De()){qt.set(n.name,n);for(let t of n.aliases??[])qt.set(t,n)}de=Array.from(qt.keys()).sort()}function De(){return[...Bi,...us,Wi]}function Oe(n){let t={...n,name:n.name.trim().toLowerCase(),aliases:n.aliases?.map(r=>r.trim().toLowerCase())};if([t.name,...t.aliases??[]].some(r=>r.length===0||/\s/.test(r)))throw new Error("Command names must be non-empty and contain no spaces");us.push(t),_e()}function Fe(n,t,e){return{name:n,params:t,run:e}}function jt(){return de||_e(),de}function Ne(){return De()}function ft(n){return de||_e(),qt.get(n.toLowerCase())}import{spawn as Hi}from"node:child_process";import{readFile as ji}from"node:fs/promises";import*as me from"node:path";function Ue(n){return`'${n.replace(/'/g,"'\\''")}'`}function Yt(n){return n.replace(/\r\n/g,`
219
1029
  `).replace(/\r/g,`
220
1030
  `).replace(/\n/g,`\r
221
- `)}function as(n,t){let e=Number.isFinite(t.cols)&&t.cols>0?Math.floor(t.cols):80,r=Number.isFinite(t.rows)&&t.rows>0?Math.floor(t.rows):24;return`stty cols ${e} rows ${r} 2>/dev/null; ${n}`}function pe(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?me.posix.normalize(t):me.posix.normalize(me.posix.join(n,t))}async function ls(n){try{let e=(await ji(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(i=>Number.parseInt(i,10)).filter(i=>Number.isInteger(i)&&i>0),r=await Promise.all(e.map(i=>ls(i)));return[...e,...r.flat()]}catch{return[]}}async function cs(n=process.pid){let t=await ls(n),e=Array.from(new Set(t)).sort((r,i)=>r-i);return e.length===0?null:e.join(",")}function us(n,t,e){let r=as(n,t),i=Hi("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return i.stdout.on("data",s=>{e.write(s.toString("utf8"))}),i.stderr.on("data",s=>{e.write(s.toString("utf8"))}),i}function fe(n,t,e){return us(`nano -- ${De(n)}`,t,e)}function ds(n,t,e){return us(`htop -p ${De(n)}`,t,e)}function he(n,t,e){let r=[`Linux ${n} ${t.kernel} ${t.arch}`,"","The programs included with the Fortune GNU/Linux system are free software;","the exact distribution terms for each program are described in the","individual files in /usr/share/doc/*/copyright.","","Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent","permitted by applicable law."];if(e){let i=new Date(e.at),s=Number.isNaN(i.getTime())?e.at:ue(i);r.push(`Last login: ${s} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(i=>`${i}\r
222
- `).join("")}`}function ge(n,t,e){let r=n==="root",i=r?"\x1B[31;1m":"\x1B[35;1m",s="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${s}[${i}${n}${s}@${o}${t}${a} ${e}${s}]${a}${r?"#":"$"} `}import{EventEmitter as bo}from"node:events";import*as Et from"node:os";function v(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function C(n,t,e,r=420){n.exists(t)||n.writeFile(t,e,{mode:r})}function G(n,t,e){n.writeFile(t,e)}function qi(n){let t=2166136261;for(let e=0;e<n.length;e++)t^=n.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function Ki(n,t,e){v(n,"/etc"),C(n,"/etc/os-release",`${['NAME="Fortune GNU/Linux"',`PRETTY_NAME="${e.os}"`,"ID=fortune","ID_LIKE=debian",'HOME_URL="https://github.com/itsrealfortune/typescript-virtual-container"',"VERSION_CODENAME=aurora",'VERSION_ID="1.0"'].join(`
1031
+ `)}function ds(n,t){let e=Number.isFinite(t.cols)&&t.cols>0?Math.floor(t.cols):80,r=Number.isFinite(t.rows)&&t.rows>0?Math.floor(t.rows):24;return`stty cols ${e} rows ${r} 2>/dev/null; ${n}`}function pe(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?me.posix.normalize(t):me.posix.normalize(me.posix.join(n,t))}async function ms(n){try{let e=(await ji(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(i=>Number.parseInt(i,10)).filter(i=>Number.isInteger(i)&&i>0),r=await Promise.all(e.map(i=>ms(i)));return[...e,...r.flat()]}catch{return[]}}async function ps(n=process.pid){let t=await ms(n),e=Array.from(new Set(t)).sort((r,i)=>r-i);return e.length===0?null:e.join(",")}function fs(n,t,e){let r=ds(n,t),i=Hi("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return i.stdout.on("data",s=>{e.write(s.toString("utf8"))}),i.stderr.on("data",s=>{e.write(s.toString("utf8"))}),i}function fe(n,t,e){return fs(`nano -- ${Ue(n)}`,t,e)}function hs(n,t,e){return fs(`htop -p ${Ue(n)}`,t,e)}function he(n,t,e){let r=[`Linux ${n} ${t.kernel} ${t.arch}`,"","The programs included with the Fortune GNU/Linux system are free software;","the exact distribution terms for each program are described in the","individual files in /usr/share/doc/*/copyright.","","Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent","permitted by applicable law."];if(e){let i=new Date(e.at),s=Number.isNaN(i.getTime())?e.at:ue(i);r.push(`Last login: ${s} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(i=>`${i}\r
1032
+ `).join("")}`}function ge(n,t,e){let r=n==="root",i=r?"\x1B[31;1m":"\x1B[35;1m",s="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${s}[${i}${n}${s}@${o}${t}${a} ${e}${s}]${a}${r?"#":"$"} `}import{EventEmitter as $o}from"node:events";import*as It from"node:os";import{EventEmitter as Zi}from"node:events";import*as z from"node:fs";import*as lt from"node:path";import{gunzipSync as He,gzipSync as xs}from"node:zlib";var Be=Buffer.from([86,70,83,33]),qi=1,Le=1,gs=2,Ve=class{chunks=[];write(t){this.chunks.push(t)}writeUint8(t){let e=Buffer.allocUnsafe(1);e.writeUInt8(t,0),this.chunks.push(e)}writeUint16(t){let e=Buffer.allocUnsafe(2);e.writeUInt16LE(t,0),this.chunks.push(e)}writeUint32(t){let e=Buffer.allocUnsafe(4);e.writeUInt32LE(t,0),this.chunks.push(e)}writeFloat64(t){let e=Buffer.allocUnsafe(8);e.writeDoubleBE(t,0),this.chunks.push(e)}writeString(t){let e=Buffer.from(t,"utf8");this.writeUint16(e.length),this.chunks.push(e)}writeBytes(t){this.writeUint32(t.length),this.chunks.push(t)}toBuffer(){return Buffer.concat(this.chunks)}};function ys(n,t){if(t.type==="file"){let e=t;n.writeUint8(Le),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else if(t.type==="stub"){let e=t;n.writeUint8(Le),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(0),n.writeBytes(Buffer.from(e.stubContent,"utf8"))}else{let e=t;n.writeUint8(gs),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt);let r=Object.values(e.children);n.writeUint32(r.length);for(let i of r)ys(n,i)}}function We(n){let t=new Ve;return t.write(Be),t.writeUint8(qi),ys(t,n),t.toBuffer()}var ze=class{constructor(t){this.buf=t}buf;pos=0;readUint8(){return this.buf.readUInt8(this.pos++)}readUint16(){let t=this.buf.readUInt16LE(this.pos);return this.pos+=2,t}readUint32(){let t=this.buf.readUInt32LE(this.pos);return this.pos+=4,t}readFloat64(){let t=this.buf.readDoubleBE(this.pos);return this.pos+=8,t}readString(){let t=this.readUint16(),e=this.buf.toString("utf8",this.pos,this.pos+t);return this.pos+=t,e}readBytes(){let t=this.readUint32(),e=this.buf.slice(this.pos,this.pos+t);return this.pos+=t,e}remaining(){return this.buf.length-this.pos}};function Ss(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),i=n.readFloat64(),s=n.readFloat64();if(t===Le){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:i,updatedAt:s,compressed:o,content:a}}if(t===gs){let o=n.readUint32(),a=Object.create(null);for(let l=0;l<o;l++){let c=Ss(n);a[c.name]=c}return{type:"directory",name:e,mode:r,createdAt:i,updatedAt:s,children:a,_childCount:o}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function Mt(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(Be))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new ze(n);for(let i=0;i<5;i++)e.readUint8();let r=Ss(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function ws(n){return n.length>=4&&n.slice(0,4).equals(Be)}import*as st from"node:fs";var B={WRITE:1,MKDIR:2,REMOVE:3,CHMOD:4,MOVE:5,SYMLINK:6},Kt="utf8";function Yi(n,t,e){let r=Buffer.from(e,Kt);return n.writeUInt16LE(r.length,t),r.copy(n,t+2),2+r.length}function Ki(n){let t=Buffer.from(n.path,Kt),e=0;n.op===B.WRITE?e=4+(n.content?.length??0)+4:n.op===B.MKDIR?e=4:n.op===B.REMOVE?e=0:n.op===B.CHMOD?e=4:(n.op===B.MOVE||n.op===B.SYMLINK)&&(e=2+Buffer.byteLength(n.dest??"",Kt));let r=3+t.length+e,i=Buffer.allocUnsafe(r),s=0;if(i.writeUInt8(n.op,s++),i.writeUInt16LE(t.length,s),s+=2,t.copy(i,s),s+=t.length,n.op===B.WRITE){let o=n.content??Buffer.alloc(0);i.writeUInt32LE(o.length,s),s+=4,o.copy(i,s),s+=o.length,i.writeUInt32LE(n.mode??420,s),s+=4}else n.op===B.MKDIR?(i.writeUInt32LE(n.mode??493,s),s+=4):n.op===B.CHMOD?(i.writeUInt32LE(n.mode??420,s),s+=4):(n.op===B.MOVE||n.op===B.SYMLINK)&&(s+=Yi(i,s,n.dest??""));return i}function Gi(n){let t=[],e=0;try{for(;e<n.length&&!(e+3>n.length);){let r=n.readUInt8(e++),i=n.readUInt16LE(e);if(e+=2,e+i>n.length)break;let s=n.subarray(e,e+i).toString(Kt);if(e+=i,r===B.WRITE){if(e+4>n.length)break;let o=n.readUInt32LE(e);if(e+=4,e+o+4>n.length)break;let a=Buffer.from(n.subarray(e,e+o));e+=o;let l=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,content:a,mode:l})}else if(r===B.MKDIR){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===B.REMOVE)t.push({op:r,path:s});else if(r===B.CHMOD){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===B.MOVE||r===B.SYMLINK){if(e+2>n.length)break;let o=n.readUInt16LE(e);if(e+=2,e+o>n.length)break;let a=n.subarray(e,e+o).toString(Kt);e+=o,t.push({op:r,path:s,dest:a})}else break}}catch{}return t}function bs(n,t){let e=Ki(t),r=st.openSync(n,st.constants.O_WRONLY|st.constants.O_CREAT|st.constants.O_APPEND);try{st.writeSync(r,e)}finally{st.closeSync(r)}}function je(n){if(!st.existsSync(n))return[];let t=st.readFileSync(n);return t.length===0?[]:Gi(t)}function vs(n){st.existsSync(n)&&st.unlinkSync(n)}import*as ye from"node:path";function W(n){if(!n||n.trim()==="")return"/";let t=ye.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function Ji(n){return n.split("/").filter(Boolean)}function it(n,t){let e=W(t);if(e==="/")return n;let r=Ji(e),i=n;for(let s of r){if(i.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=i.children[s];if(!o)throw new Error(`Path '${e}' does not exist.`);i=o}return i}function kt(n,t,e,r){let i=W(t);if(i==="/")throw new Error("Root path has no parent directory.");let s=ye.posix.dirname(i),o=ye.posix.basename(i);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(s);let a=it(n,s);if(a.type!=="directory")throw new Error(`Parent path '${s}' is not a directory.`);return{parent:a,name:o}}var qe=class n extends Zi{root;mode;snapshotFile;journalFile;evictionThreshold;flushAfterNWrites;_writesSinceFlush=0;_flushTimer=null;_dirty=!1;mounts=new Map;static isBrowser=typeof process>"u"||typeof process.versions?.node>"u";constructor(t={}){if(super(),this.mode=t.mode??"memory",this.mode==="fs"){if(!t.snapshotPath)throw new Error('VirtualFileSystem: "snapshotPath" is required when mode is "fs".');this.snapshotFile=lt.resolve(t.snapshotPath,"vfs-snapshot.vfsb"),this.journalFile=lt.resolve(t.snapshotPath,"vfs-journal.bin"),this.evictionThreshold=t.evictionThresholdBytes??64*1024,this.flushAfterNWrites=t.flushAfterNWrites??500;let e=t.flushIntervalMs??3e4;e>0&&(this._flushTimer=setInterval(()=>{this._dirty&&this._autoFlush()},e),typeof this._flushTimer=="object"&&this._flushTimer!==null&&"unref"in this._flushTimer&&this._flushTimer.unref())}else this.snapshotFile=null,this.journalFile=null,this.evictionThreshold=0,this.flushAfterNWrites=0;this.root=this.makeDir("",493)}makeDir(t,e){let r=Date.now();return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:Object.create(null),_childCount:0}}makeFile(t,e,r,i){let s=Date.now();return{type:"file",name:t,content:e,mode:r,compressed:i,createdAt:s,updatedAt:s}}makeStub(t,e,r){let i=Date.now();return{type:"stub",name:t,stubContent:e,mode:r,createdAt:i,updatedAt:i}}writeStub(t,e,r=420){let i=W(t),{parent:s,name:o}=kt(this.root,i,!0,l=>this.mkdirRecursive(l,493)),a=s.children[o];if(a?.type==="directory")throw new Error(`Cannot write stub '${i}': path is a directory.`);a?.type!=="file"&&(a||s._childCount++,s.children[o]=this.makeStub(o,e,r))}mkdirRecursive(t,e){let r=W(t);if(r==="/")return;let i=r.split("/").filter(Boolean),s=this.root,o="";for(let a of i){o+=`/${a}`;let l=s.children[a];if(!l)l=this.makeDir(a,e),s.children[a]=l,s._childCount++,this.emit("dir:create",{path:o,mode:e}),this._journal({op:B.MKDIR,path:o,mode:e});else if(l.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);s=l}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)){if(!z.existsSync(this.snapshotFile)){if(this.journalFile){let t=je(this.journalFile);t.length>0&&this._replayJournal(t)}return}try{let t=z.readFileSync(this.snapshotFile);if(ws(t))this.root=Mt(t);else{let e=JSON.parse(t.toString("utf8"));this.root=this.deserializeDir(e.root,""),console.info("[VirtualFileSystem] Migrating legacy JSON snapshot to binary format.")}if(this.emit("snapshot:restore",{path:this.snapshotFile}),this.journalFile){let e=je(this.journalFile);e.length>0&&this._replayJournal(e)}}catch(t){console.warn(`[VirtualFileSystem] Could not restore snapshot from ${this.snapshotFile}:`,t instanceof Error?t.message:String(t))}}}async flushMirror(){if(this.mode!=="fs"||!this.snapshotFile){this.emit("mirror:flush");return}let t=lt.dirname(this.snapshotFile);z.mkdirSync(t,{recursive:!0});let e=We(this.root);z.writeFileSync(this.snapshotFile,e),this.journalFile&&vs(this.journalFile),this._dirty=!1,this._writesSinceFlush=0,this.emit("mirror:flush",{path:this.snapshotFile}),this.evictLargeFiles()}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}async _autoFlush(){this._dirty&&await this.flushMirror()}_markDirty(){this._dirty=!0,this.flushAfterNWrites>0&&(this._writesSinceFlush++,this._writesSinceFlush>=this.flushAfterNWrites&&(this._writesSinceFlush=0,this._autoFlush()))}async stopAutoFlush(){this._flushTimer!==null&&(clearInterval(this._flushTimer),this._flushTimer=null),this._dirty&&await this.flushMirror()}importRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this.root=t}finally{this._replayMode=e}}encodeBinary(){return We(this.root)}releaseTree(){this.root=this.makeDir("",493)}_replayMode=!1;_journal(t){this.journalFile&&!this._replayMode&&(bs(this.journalFile,t),this._markDirty())}_replayJournal(t){this._replayMode=!0;try{for(let e of t)try{e.op===B.WRITE?this.writeFile(e.path,e.content??Buffer.alloc(0),{mode:e.mode}):e.op===B.MKDIR?this.mkdir(e.path,e.mode):e.op===B.REMOVE?this.exists(e.path)&&this.remove(e.path,{recursive:!0}):e.op===B.CHMOD?this.exists(e.path)&&this.chmod(e.path,e.mode??420):e.op===B.MOVE?this.exists(e.path)&&e.dest&&this.move(e.path,e.dest):e.op===B.SYMLINK&&e.dest&&this.symlink(e.dest,e.path)}catch{}}finally{this._replayMode=!1}}evictLargeFiles(){!this.snapshotFile||this.evictionThreshold===0||z.existsSync(this.snapshotFile)&&this._evictDir(this.root)}_evictDir(t){for(let e of Object.values(t.children))if(e.type==="directory")this._evictDir(e);else if(e.type==="file"&&!e.evicted){let r=e.compressed?e.size??e.content.length*2:e.content.length;r>this.evictionThreshold&&(e.size=r,e.content=Buffer.alloc(0),e.evicted=!0)}}_reloadEvicted(t,e){if(!(!t.evicted||!this.snapshotFile)&&z.existsSync(this.snapshotFile))try{let r=z.readFileSync(this.snapshotFile),i=Mt(r),s=e.split("/").filter(Boolean),o=i;for(let a of s){if(o.type!=="directory")return;let l=o.children[a];if(!l)return;o=l}o.type==="file"&&(t.content=o.content,t.compressed=o.compressed,t.evicted=void 0)}catch{}}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let i=W(t),s=lt.resolve(e);if(!z.existsSync(s))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${s}"`);if(!z.statSync(s).isDirectory())throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${s}"`);this.mkdir(i),this.mounts.set(i,{hostPath:s,readOnly:r}),this.emit("mount",{vPath:i,hostPath:s,readOnly:r})}unmount(t){let e=W(t);this.mounts.delete(e)&&this.emit("unmount",{vPath:e})}getMounts(){return[...this.mounts.entries()].map(([t,e])=>({vPath:t,...e}))}resolveMount(t){let e=W(t),r=[...this.mounts.entries()].sort(([i],[s])=>s.length-i.length);for(let[i,s]of r)if(e===i||e.startsWith(`${i}/`)){let o=e.slice(i.length).replace(/^\//,""),a=o?lt.join(s.hostPath,o):s.hostPath;return{hostPath:s.hostPath,readOnly:s.readOnly,relPath:o,fullHostPath:a}}return null}mkdir(t,e=493){let r=W(t),i=(()=>{try{return it(this.root,r)}catch{return null}})();if(i&&i.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let i=this.resolveMount(t);if(i){if(i.readOnly)throw new Error(`EROFS: read-only file system, open '${i.fullHostPath}'`);let p=lt.dirname(i.fullHostPath);z.existsSync(p)||z.mkdirSync(p,{recursive:!0}),z.writeFileSync(i.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let s=W(t),{parent:o,name:a}=kt(this.root,s,!0,p=>this.mkdirRecursive(p,493)),l=o.children[a];if(l?.type==="directory")throw new Error(`Cannot write file '${s}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),u=r.compress??!1,d=u?xs(c):c,m=r.mode??420;if(l&&l.type==="file"){let p=l;p.content=d,p.compressed=u,p.mode=m,p.updatedAt=Date.now()}else l||o._childCount++,o.children[a]=this.makeFile(a,d,m,u);this.emit("file:write",{path:s,size:d.length}),this._journal({op:B.WRITE,path:s,content:c,mode:m})}readFile(t){let e=this.resolveMount(t);if(e){if(!z.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return z.readFileSync(e.fullHostPath,"utf8")}let r=W(t),i=it(this.root,r);if(i.type==="stub")return this.emit("file:read",{path:r,size:i.stubContent.length}),i.stubContent;if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?He(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o.toString("utf8")}readFileRaw(t){let e=this.resolveMount(t);if(e){if(!z.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return z.readFileSync(e.fullHostPath)}let r=W(t),i=it(this.root,r);if(i.type==="stub"){let a=Buffer.from(i.stubContent,"utf8");return this.emit("file:read",{path:r,size:a.length}),a}if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?He(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o}exists(t){let e=this.resolveMount(t);if(e)return z.existsSync(e.fullHostPath);try{return it(this.root,W(t)),!0}catch{return!1}}chmod(t,e){let r=W(t);it(this.root,r).mode=e,this._journal({op:B.CHMOD,path:r,mode:e})}stat(t){let e=this.resolveMount(t);if(e){if(!z.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=z.statSync(e.fullHostPath),l=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",c=a.mtime;return a.isDirectory()?{type:"directory",name:l,path:W(t),mode:493,createdAt:a.birthtime,updatedAt:c,childrenCount:z.readdirSync(e.fullHostPath).length}:{type:"file",name:l,path:W(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:c,compressed:!1,size:a.size}}let r=W(t),i=it(this.root,r),s=r==="/"?"":lt.posix.basename(r);if(i.type==="stub"){let a=i;return{type:"file",name:s,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:!1,size:a.stubContent.length}}if(i.type==="file"){let a=i;return{type:"file",name:s,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:a.compressed,size:a.evicted?a.size??0:a.content.length}}let o=i;return{type:"directory",name:s,path:r,mode:o.mode,createdAt:new Date(o.createdAt),updatedAt:new Date(o.updatedAt),childrenCount:o._childCount}}list(t="/"){let e=this.resolveMount(t);if(e){if(!z.existsSync(e.fullHostPath))return[];try{return z.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=W(t),i=it(this.root,r);if(i.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Object.keys(i.children).sort()}tree(t="/"){let e=W(t),r=it(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let i=t==="/"?"/":lt.posix.basename(e);return this.renderTreeLines(r,i)}renderTreeLines(t,e){let r=[e],i=Object.keys(t.children).sort();for(let s=0;s<i.length;s++){let o=i[s],a=t.children[o],l=s===i.length-1,c=l?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",u=l?" ":"\u2502 ";if(r.push(`${c}${o}`),a.type==="directory"){let d=this.renderTreeLines(a,"").split(`
1033
+ `).slice(1).map(m=>`${u}${m}`);r.push(...d)}}return r.join(`
1034
+ `)}getUsageBytes(t="/"){return this.computeUsage(it(this.root,W(t)))}computeUsage(t){if(t.type==="file")return t.content.length;if(t.type==="stub")return t.stubContent.length;let e=0;for(let r of Object.values(t.children))e+=this.computeUsage(r);return e}compressFile(t){let e=it(this.root,W(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=xs(r.content),r.compressed=!0,r.updatedAt=Date.now())}decompressFile(t){let e=it(this.root,W(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=He(r.content),r.compressed=!1,r.updatedAt=Date.now())}symlink(t,e){let r=W(e),i=t.startsWith("/")?W(t):t,{parent:s,name:o}=kt(this.root,r,!0,l=>this.mkdirRecursive(l,493)),a={type:"file",name:o,content:Buffer.from(i,"utf8"),mode:41471,compressed:!1,createdAt:Date.now(),updatedAt:Date.now()};s.children[o]=a,s._childCount++,this._journal({op:B.SYMLINK,path:r,dest:i}),this.emit("symlink:create",{link:r,target:i})}isSymlink(t){try{let e=it(this.root,W(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=W(t);for(let i=0;i<e;i++){try{let s=it(this.root,r);if(s.type==="file"&&s.mode===41471){let o=s.content.toString("utf8");r=o.startsWith("/")?o:W(lt.posix.join(lt.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=this.resolveMount(t);if(r){if(r.readOnly)throw new Error(`EROFS: read-only file system, unlink '${r.fullHostPath}'`);if(!z.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);z.statSync(r.fullHostPath).isDirectory()?z.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):z.unlinkSync(r.fullHostPath);return}let i=W(t);if(i==="/")throw new Error("Cannot remove root directory.");let s=it(this.root,i);if(s.type==="directory"){let l=s;if(!e.recursive&&l._childCount>0)throw new Error(`Directory '${i}' is not empty. Use recursive option.`)}let{parent:o,name:a}=kt(this.root,i,!1,()=>{});delete o.children[a],o._childCount--,this.emit("node:remove",{path:i}),this._journal({op:B.REMOVE,path:i})}move(t,e){let r=W(t),i=W(e);if(r==="/"||i==="/")throw new Error("Cannot move root directory.");let s=it(this.root,r);if(this.exists(i))throw new Error(`Destination '${i}' already exists.`);this.mkdirRecursive(lt.posix.dirname(i),493);let{parent:o,name:a}=kt(this.root,i,!1,()=>{}),{parent:l,name:c}=kt(this.root,r,!1,()=>{});delete l.children[c],l._childCount--,s.name=a,o.children[a]=s,o._childCount++,this._journal({op:B.MOVE,path:r,dest:i})}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of Object.values(t.children))r.type==="stub"?e.push({type:"file",name:r.name,mode:r.mode,createdAt:new Date(r.createdAt).toISOString(),updatedAt:new Date(r.updatedAt).toISOString(),compressed:!1,contentBase64:Buffer.from(r.stubContent,"utf8").toString("base64")}):r.type==="file"?e.push(this.serializeFile(r)):e.push(this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString(),compressed:t.compressed,contentBase64:t.content.toString("base64")}}static fromSnapshot(t){let e=new n;return e.root=e.deserializeDir(t.root,""),e}importSnapshot(t){this.root=this.deserializeDir(t.root,""),this.emit("snapshot:import")}deserializeDir(t,e){let r={type:"directory",name:e,mode:t.mode,createdAt:Date.parse(t.createdAt),updatedAt:Date.parse(t.updatedAt),children:Object.create(null),_childCount:0};for(let i of t.children){if(i.type==="file"){let s=i;r.children[s.name]={type:"file",name:s.name,mode:s.mode,createdAt:Date.parse(s.createdAt),updatedAt:Date.parse(s.updatedAt),compressed:s.compressed,content:Buffer.from(s.contentBase64,"base64")}}else{let s=this.deserializeDir(i,i.name);r.children[i.name]=s}r._childCount++}return r}},Se=qe;function x(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function C(n,t,e,r=420){n.writeStub(t,e,r)}function G(n,t,e){n.writeFile(t,e)}function Qi(n){let t=2166136261;for(let e=0;e<n.length;e++)t^=n.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function Xi(n,t,e){x(n,"/etc"),C(n,"/etc/os-release",`${['NAME="Fortune GNU/Linux"',`PRETTY_NAME="${e.os}"`,"ID=fortune","ID_LIKE=debian",'HOME_URL="https://github.com/itsrealfortune/typescript-virtual-container"',"VERSION_CODENAME=aurora",'VERSION_ID="1.0"'].join(`
223
1035
  `)}
224
1036
  `),C(n,"/etc/debian_version",`12.0
225
1037
  `),C(n,"/etc/hostname",`${t}
@@ -230,56 +1042,56 @@ ${m} 100%[==================>] ${y.length} B`),{stderr:p.join(`
230
1042
  `)}
231
1043
  `),C(n,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
232
1044
  `),C(n,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
233
- `)),v(n,"/etc/apt"),v(n,"/etc/apt/sources.list.d"),C(n,"/etc/apt/sources.list",`${["# Fortune GNU/Linux package sources","deb [virtual] fortune://packages.fortune.local aurora main contrib","deb [virtual] fortune://security.fortune.local aurora-security main"].join(`
1045
+ `)),x(n,"/etc/apt"),x(n,"/etc/apt/sources.list.d"),C(n,"/etc/apt/sources.list",`${["# Fortune GNU/Linux package sources","deb [virtual] fortune://packages.fortune.local aurora main contrib","deb [virtual] fortune://security.fortune.local aurora-security main"].join(`
234
1046
  `)}
235
- `),v(n,"/etc/network"),C(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
1047
+ `),x(n,"/etc/network"),C(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
236
1048
  `)}
237
1049
  `),C(n,"/etc/resolv.conf",`nameserver 1.1.1.1
238
1050
  nameserver 8.8.8.8
239
1051
  `),C(n,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
240
1052
  `)}
241
- `),v(n,"/etc/cron.d"),v(n,"/etc/init.d"),v(n,"/etc/systemd"),v(n,"/etc/systemd/system"),C(n,"/etc/fstab",`${["# <file system> <mount point> <type> <options> <dump> <pass>","UUID=00000000-0000-0000-0000-000000000001 / ext4 errors=remount-ro 0 1","UUID=00000000-0000-0000-0000-000000000002 /boot ext4 defaults 0 2","UUID=00000000-0000-0000-0000-000000000003 none swap sw 0 0","tmpfs /tmp tmpfs defaults,noatime 0 0","tmpfs /run tmpfs defaults,noatime 0 0"].join(`
1053
+ `),x(n,"/etc/cron.d"),x(n,"/etc/init.d"),x(n,"/etc/systemd"),x(n,"/etc/systemd/system"),C(n,"/etc/fstab",`${["# <file system> <mount point> <type> <options> <dump> <pass>","UUID=00000000-0000-0000-0000-000000000001 / ext4 errors=remount-ro 0 1","UUID=00000000-0000-0000-0000-000000000002 /boot ext4 defaults 0 2","UUID=00000000-0000-0000-0000-000000000003 none swap sw 0 0","tmpfs /tmp tmpfs defaults,noatime 0 0","tmpfs /run tmpfs defaults,noatime 0 0"].join(`
242
1054
  `)}
243
1055
  `),C(n,"/etc/login.defs",`${["MAIL_DIR /var/mail","PASS_MAX_DAYS 99999","PASS_MIN_DAYS 0","PASS_WARN_AGE 7","UID_MIN 1000","UID_MAX 60000","GID_MIN 1000","GID_MAX 60000","CREATE_HOME yes","UMASK 022","USERGROUPS_ENAB yes","ENCRYPT_METHOD SHA512"].join(`
244
1056
  `)}
245
- `),v(n,"/etc/security"),C(n,"/etc/security/limits.conf",`# /etc/security/limits.conf
1057
+ `),x(n,"/etc/security"),C(n,"/etc/security/limits.conf",`# /etc/security/limits.conf
246
1058
  `),C(n,"/etc/security/access.conf",`# /etc/security/access.conf
247
- `),v(n,"/etc/pam.d"),C(n,"/etc/pam.d/common-auth",`auth required pam_unix.so
1059
+ `),x(n,"/etc/pam.d"),C(n,"/etc/pam.d/common-auth",`auth required pam_unix.so
248
1060
  `),C(n,"/etc/pam.d/common-account",`account required pam_unix.so
249
1061
  `),C(n,"/etc/pam.d/common-password",`password required pam_unix.so obscure sha512
250
1062
  `),C(n,"/etc/pam.d/common-session",`session required pam_unix.so
251
1063
  `),C(n,"/etc/pam.d/sshd",`@include common-auth
252
1064
  @include common-account
253
1065
  @include common-session
254
- `),v(n,"/etc/sudoers.d"),C(n,"/etc/sudoers",`root ALL=(ALL:ALL) ALL
1066
+ `),x(n,"/etc/sudoers.d"),C(n,"/etc/sudoers",`root ALL=(ALL:ALL) ALL
255
1067
  %sudo ALL=(ALL:ALL) ALL
256
1068
  `,288),C(n,"/etc/ld.so.conf",`include /etc/ld.so.conf.d/*.conf
257
- `),v(n,"/etc/ld.so.conf.d"),C(n,"/etc/ld.so.conf.d/x86_64-linux-gnu.conf",`/lib/x86_64-linux-gnu
1069
+ `),x(n,"/etc/ld.so.conf.d"),C(n,"/etc/ld.so.conf.d/x86_64-linux-gnu.conf",`/lib/x86_64-linux-gnu
258
1070
  /usr/lib/x86_64-linux-gnu
259
1071
  `),C(n,"/etc/locale.conf",`LANG=en_US.UTF-8
260
1072
  `),C(n,"/etc/timezone",`UTC
261
1073
  `),C(n,"/etc/localtime",`UTC
262
- `)}function Le(n,t){let e=t.listUsers(),r=["root:x:0:0:root:/root:/bin/bash","daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin"],i=1e3;for(let a of e)a!=="root"&&(r.push(`${a}:x:${i}:${i}::/home/${a}:/bin/bash`),i++);n.writeFile("/etc/passwd",`${r.join(`
1074
+ `)}function Ye(n,t){let e=t.listUsers(),r=["root:x:0:0:root:/root:/bin/bash","daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin"],i=1e3;for(let a of e)a!=="root"&&(r.push(`${a}:x:${i}:${i}::/home/${a}:/bin/bash`),i++);n.writeFile("/etc/passwd",`${r.join(`
263
1075
  `)}
264
1076
  `);let s=["root:x:0:","daemon:x:1:",`sudo:x:27:${e.filter(a=>t.isSudoer(a)).join(",")}`,`users:x:100:${e.filter(a=>a!=="root").join(",")}`,"nogroup:x:65534:"];n.writeFile("/etc/group",`${s.join(`
265
1077
  `)}
266
1078
  `);let o=["root:*:19000:0:99999:7:::","daemon:*:19000:0:99999:7:::"];for(let a of e)a!=="root"&&o.push(`${a}:!:19000:0:99999:7:::`);n.writeFile("/etc/shadow",`${o.join(`
267
1079
  `)}
268
- `,{mode:416})}function ms(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function ps(n,t,e,r,i,s,o){let a=`/proc/${t}`;v(n,a),v(n,`${a}/fd`),v(n,`${a}/fdinfo`);let l=Math.floor((Date.now()-new Date(s).getTime())/1e3),c=i.split(/\s+/)[0]??"bash";G(n,`${a}/cmdline`,`${i.replace(/\s+/g,"\0")}\0`),G(n,`${a}/comm`,c),G(n,`${a}/status`,`${[`Name: ${c}`,"State: S (sleeping)",`Pid: ${t}`,"PPid: 1","Uid: 0 0 0 0","Gid: 0 0 0 0","VmRSS: 4096 kB","VmSize: 16384 kB","Threads: 1"].join(`
1080
+ `,{mode:416})}function Cs(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function $s(n,t,e,r,i,s,o){let a=`/proc/${t}`;x(n,a),x(n,`${a}/fd`),x(n,`${a}/fdinfo`);let l=Math.floor((Date.now()-new Date(s).getTime())/1e3),c=i.split(/\s+/)[0]??"bash";G(n,`${a}/cmdline`,`${i.replace(/\s+/g,"\0")}\0`),G(n,`${a}/comm`,c),G(n,`${a}/status`,`${[`Name: ${c}`,"State: S (sleeping)",`Pid: ${t}`,"PPid: 1","Uid: 0 0 0 0","Gid: 0 0 0 0","VmRSS: 4096 kB","VmSize: 16384 kB","Threads: 1"].join(`
269
1081
  `)}
270
1082
  `),G(n,`${a}/stat`,`${t} (${c}) S 1 ${t} ${t} 0 -1 4194304 0 0 0 0 ${l} 0 0 0 20 0 1 0 0 16384 4096 0
271
- `),G(n,`${a}/environ`,`${Object.entries(o).map(([u,d])=>`${u}=${d}`).join("\0")}\0`),G(n,`${a}/cwd`,`/home/${e}\0`),G(n,`${a}/exe`,"/bin/bash\0");for(let u of["0","1","2"])C(n,`${a}/fd/${u}`,"")}function Gi(n,t){v(n,"/proc/boot"),C(n,"/proc/boot/log",`${["[ 0.000000] Linux virtual kernel booting...","[ 0.000120] init memory subsystem","[ 0.000240] mount /proc /sys /dev","[ 0.000420] start init","[ 0.000680] system ready"].join(`
1083
+ `),G(n,`${a}/environ`,`${Object.entries(o).map(([u,d])=>`${u}=${d}`).join("\0")}\0`),G(n,`${a}/cwd`,`/home/${e}\0`),G(n,`${a}/exe`,"/bin/bash\0");for(let u of["0","1","2"])C(n,`${a}/fd/${u}`,"")}function to(n,t){x(n,"/proc/boot"),C(n,"/proc/boot/log",`${["[ 0.000000] Linux virtual kernel booting...","[ 0.000120] init memory subsystem","[ 0.000240] mount /proc /sys /dev","[ 0.000420] start init","[ 0.000680] system ready"].join(`
272
1084
  `)}
273
1085
  `),C(n,"/proc/boot/version",`Linux ${t.kernel} (virtual)
274
- `)}function ye(n,t,e,r,i=[]){v(n,"/proc");let s=Math.floor((Date.now()-r)/1e3),o=Math.floor(s*.9);G(n,"/proc/uptime",`${s}.00 ${o}.00
275
- `);let a=Math.floor(Et.totalmem()/1024),l=Math.floor(Et.freemem()/1024),c=Math.floor(l*.95);G(n,"/proc/meminfo",`${[`MemTotal: ${String(a).padStart(10)} kB`,`MemFree: ${String(l).padStart(10)} kB`,`MemAvailable: ${String(c).padStart(10)} kB`,`Buffers: ${String(Math.floor(a*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(a*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(a*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(a*.5)).padStart(10)} kB`].join(`
1086
+ `)}function we(n,t,e,r,i=[]){x(n,"/proc");let s=Math.floor((Date.now()-r)/1e3),o=Math.floor(s*.9);G(n,"/proc/uptime",`${s}.00 ${o}.00
1087
+ `);let a=Math.floor(It.totalmem()/1024),l=Math.floor(It.freemem()/1024),c=Math.floor(l*.95);G(n,"/proc/meminfo",`${[`MemTotal: ${String(a).padStart(10)} kB`,`MemFree: ${String(l).padStart(10)} kB`,`MemAvailable: ${String(c).padStart(10)} kB`,`Buffers: ${String(Math.floor(a*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(a*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(a*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(a*.5)).padStart(10)} kB`].join(`
276
1088
  `)}
277
- `);let u=Et.cpus(),d=[];for(let S=0;S<u.length;S++){let F=u[S];F&&d.push(`processor : ${S}`,`model name : ${F.model}`,`cpu MHz : ${F.speed.toFixed(3)}`,"cache size : 8192 KB","")}G(n,"/proc/cpuinfo",`${d.join(`
1089
+ `);let u=It.cpus(),d=[];for(let S=0;S<u.length;S++){let I=u[S];I&&d.push(`processor : ${S}`,`model name : ${I.model}`,`cpu MHz : ${I.speed.toFixed(3)}`,"cache size : 8192 KB","")}G(n,"/proc/cpuinfo",`${d.join(`
278
1090
  `)}
279
1091
  `),G(n,"/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
280
1092
  `),G(n,"/proc/hostname",`${e}
281
1093
  `);let m=(Math.random()*.5).toFixed(2),p=1+i.length;G(n,"/proc/loadavg",`${m} ${m} ${m} ${p}/${p} 1
282
- `),v(n,"/proc/net"),C(n,"/proc/net/dev",`${["Inter-| Receive | Transmit"," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed"," lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"," eth0: 131072 1024 0 0 0 0 0 0 65536 512 0 0 0 0 0 0"].join(`
1094
+ `),x(n,"/proc/net"),C(n,"/proc/net/dev",`${["Inter-| Receive | Transmit"," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed"," lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"," eth0: 131072 1024 0 0 0 0 0 0 65536 512 0 0 0 0 0 0"].join(`
283
1095
  `)}
284
1096
  `),C(n,"/proc/net/if_inet6",""),C(n,"/proc/net/tcp",` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
285
1097
  `),C(n,"/proc/net/tcp6",` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
@@ -288,11 +1100,11 @@ nameserver 8.8.8.8
288
1100
  `)}
289
1101
  `);let h=`${["sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0","proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0","devtmpfs /dev devtmpfs rw,nosuid,size=8192k,nr_inodes=4096,mode=755 0 0","tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=204800k,mode=755 0 0","tmpfs /tmp tmpfs rw,nosuid,nodev,noatime 0 0","/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0","/dev/sda1 /boot ext4 rw,relatime 0 0","tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0","devpts /dev/pts devpts rw,nosuid,noexec,relatime,mode=620,ptmxmode=000 0 0","squashfs /snap/core squashfs ro,nodev,relatime 0 0"].join(`
290
1102
  `)}
291
- `;G(n,"/proc/mounts",h),v(n,"/proc/self"),G(n,"/proc/self/mounts",h),G(n,"/proc/partitions",`${["major minor #blocks name",""," 8 0 41943040 sda"," 8 1 524288 sda1"," 8 2 41417216 sda2"," 7 0 10485760 loop0"].join(`
1103
+ `;G(n,"/proc/mounts",h),x(n,"/proc/self"),G(n,"/proc/self/mounts",h),G(n,"/proc/partitions",`${["major minor #blocks name",""," 8 0 41943040 sda"," 8 1 524288 sda1"," 8 2 41417216 sda2"," 7 0 10485760 loop0"].join(`
292
1104
  `)}
293
1105
  `),G(n,"/proc/swaps",`Filename Type Size Used Priority
294
- /dev/sda3 partition ${Math.floor(Et.totalmem()/2048)} 0 -2
295
- `),v(n,"/proc/sys"),v(n,"/proc/sys/kernel"),v(n,"/proc/sys/net"),v(n,"/proc/sys/vm"),C(n,"/proc/sys/kernel/hostname",`${e}
1106
+ /dev/sda3 partition ${Math.floor(It.totalmem()/2048)} 0 -2
1107
+ `),x(n,"/proc/sys"),x(n,"/proc/sys/kernel"),x(n,"/proc/sys/net"),x(n,"/proc/sys/vm"),C(n,"/proc/sys/kernel/hostname",`${e}
296
1108
  `),C(n,"/proc/sys/kernel/ostype",`Linux
297
1109
  `),C(n,"/proc/sys/kernel/osrelease",`${t.kernel}
298
1110
  `),C(n,"/proc/sys/kernel/pid_max",`32768
@@ -302,29 +1114,27 @@ nameserver 8.8.8.8
302
1114
  `),C(n,"/proc/sys/net/ipv4/ip_forward",`0
303
1115
  `),C(n,"/proc/sys/vm/swappiness",`60
304
1116
  `),C(n,"/proc/sys/vm/overcommit_memory",`0
305
- `),ps(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let S of i){let F=ms(S.tty);ps(n,F,S.username,S.tty,"bash",S.startedAt,{USER:S.username,HOME:`/home/${S.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let y=i.length>0?ms(i[i.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let f=`/proc/${y}`;if(v(n,"/proc/self"),v(n,"/proc/self/fd"),n.exists(f))for(let S of n.list(f)){let F=`${f}/${S}`,A=`/proc/self/${S}`;try{n.stat(F).type==="file"&&G(n,A,n.readFile(F))}catch{}}else G(n,"/proc/self/cmdline","bash\0"),G(n,"/proc/self/comm","bash"),G(n,"/proc/self/status",`Name: bash
1117
+ `),$s(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let S of i){let I=Cs(S.tty);$s(n,I,S.username,S.tty,"bash",S.startedAt,{USER:S.username,HOME:`/home/${S.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let y=i.length>0?Cs(i[i.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let f=`/proc/${y}`;if(x(n,"/proc/self"),x(n,"/proc/self/fd"),n.exists(f))for(let S of n.list(f)){let I=`${f}/${S}`,k=`/proc/self/${S}`;try{n.stat(I).type==="file"&&G(n,k,n.readFile(I))}catch{}}else G(n,"/proc/self/cmdline","bash\0"),G(n,"/proc/self/comm","bash"),G(n,"/proc/self/status",`Name: bash
306
1118
  State: S (sleeping)
307
1119
  Pid: 1
308
1120
  PPid: 0
309
- `),G(n,"/proc/self/environ",""),G(n,"/proc/self/cwd","/root\0"),G(n,"/proc/self/exe","/bin/bash\0")}function Ji(n,t,e){v(n,"/sys"),v(n,"/sys/devices"),v(n,"/sys/devices/virtual"),v(n,"/sys/devices/virtual/dmi"),v(n,"/sys/devices/virtual/dmi/id");let r=qi(t),i=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,s={bios_vendor:"Virtual BIOS",bios_version:"1.0",bios_date:"01/01/2025",sys_vendor:"Fortune Systems",product_name:i,product_family:"VirtualContainer",product_version:"v1",product_uuid:`${r.toString(16).padStart(8,"0")}-0000-0000-0000-000000000000`,product_serial:`SN-${r}`,chassis_type:"3",chassis_vendor:"Virtual",chassis_version:"v1",board_name:"fortune-board",modalias:`dmi:bvnVirtual:bvr1.0:svnFortune:pn${i}`};for(let[o,a]of Object.entries(s))C(n,`/sys/devices/virtual/dmi/id/${o}`,`${a}
310
- `);v(n,"/sys/class"),v(n,"/sys/class/net"),v(n,"/sys/kernel"),C(n,"/sys/kernel/hostname",`${t}
1121
+ `),G(n,"/proc/self/environ",""),G(n,"/proc/self/cwd","/root\0"),G(n,"/proc/self/exe","/bin/bash\0")}function eo(n,t,e){x(n,"/sys"),x(n,"/sys/devices"),x(n,"/sys/devices/virtual"),x(n,"/sys/devices/virtual/dmi"),x(n,"/sys/devices/virtual/dmi/id");let r=Qi(t),i=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,s={bios_vendor:"Virtual BIOS",bios_version:"1.0",bios_date:"01/01/2025",sys_vendor:"Fortune Systems",product_name:i,product_family:"VirtualContainer",product_version:"v1",product_uuid:`${r.toString(16).padStart(8,"0")}-0000-0000-0000-000000000000`,product_serial:`SN-${r}`,chassis_type:"3",chassis_vendor:"Virtual",chassis_version:"v1",board_name:"fortune-board",modalias:`dmi:bvnVirtual:bvr1.0:svnFortune:pn${i}`};for(let[o,a]of Object.entries(s))C(n,`/sys/devices/virtual/dmi/id/${o}`,`${a}
1122
+ `);x(n,"/sys/class"),x(n,"/sys/class/net"),x(n,"/sys/kernel"),C(n,"/sys/kernel/hostname",`${t}
311
1123
  `),C(n,"/sys/kernel/osrelease",`${e.kernel}
312
1124
  `),C(n,"/sys/kernel/ostype",`Linux
313
- `)}function Zi(n){v(n,"/dev"),C(n,"/dev/null","",438),C(n,"/dev/zero","",438),C(n,"/dev/full","",438),C(n,"/dev/random","",292),C(n,"/dev/urandom","",292),C(n,"/dev/mem","",416),C(n,"/dev/console","",384),C(n,"/dev/tty","",438),C(n,"/dev/tty0","",400),C(n,"/dev/tty1","",400),C(n,"/dev/ttyS0","",432);for(let t=0;t<8;t++)C(n,`/dev/loop${t}`,"",432);v(n,"/dev/loop-control"),C(n,"/dev/sda","",432),C(n,"/dev/sda1","",432),C(n,"/dev/sda2","",432),v(n,"/dev/pts"),v(n,"/dev/shm"),C(n,"/dev/stdin","",438),C(n,"/dev/stdout","",438),C(n,"/dev/stderr","",438)}function Yi(n){v(n,"/usr"),v(n,"/usr/bin"),v(n,"/usr/sbin"),v(n,"/usr/local"),v(n,"/usr/local/bin"),v(n,"/usr/local/lib"),v(n,"/usr/local/share"),v(n,"/usr/share"),v(n,"/usr/share/doc"),v(n,"/usr/share/man"),v(n,"/usr/share/man/man1"),v(n,"/usr/lib");let t=["sh","bash","ls","cat","echo","grep","find","sort","head","tail","cut","tr","sed","awk","wc","tee","tar","gzip","gunzip","touch","mkdir","rm","mv","cp","chmod","ln","pwd","env","date","sleep","id","whoami","hostname","uname","ps","kill","df","du","curl","wget","nano","diff","uniq","xargs","base64"];for(let e of t)C(n,`/usr/bin/${e}`,`#!/bin/sh
1125
+ `)}function no(n){x(n,"/dev"),C(n,"/dev/null","",438),C(n,"/dev/zero","",438),C(n,"/dev/full","",438),C(n,"/dev/random","",292),C(n,"/dev/urandom","",292),C(n,"/dev/mem","",416),C(n,"/dev/console","",384),C(n,"/dev/tty","",438),C(n,"/dev/tty0","",400),C(n,"/dev/tty1","",400),C(n,"/dev/ttyS0","",432);for(let t=0;t<8;t++)C(n,`/dev/loop${t}`,"",432);x(n,"/dev/loop-control"),C(n,"/dev/sda","",432),C(n,"/dev/sda1","",432),C(n,"/dev/sda2","",432),x(n,"/dev/pts"),x(n,"/dev/shm"),C(n,"/dev/stdin","",438),C(n,"/dev/stdout","",438),C(n,"/dev/stderr","",438)}function ro(n){x(n,"/usr"),x(n,"/usr/bin"),x(n,"/usr/sbin"),x(n,"/usr/local"),x(n,"/usr/local/bin"),x(n,"/usr/local/lib"),x(n,"/usr/local/share"),x(n,"/usr/share"),x(n,"/usr/share/doc"),x(n,"/usr/share/man"),x(n,"/usr/share/man/man1"),x(n,"/usr/lib");let t=["sh","bash","ls","cat","echo","grep","find","sort","head","tail","cut","tr","sed","awk","wc","tee","tar","gzip","gunzip","touch","mkdir","rm","mv","cp","chmod","ln","pwd","env","date","sleep","id","whoami","hostname","uname","ps","kill","df","du","curl","wget","nano","diff","uniq","xargs","base64"];for(let e of t)C(n,`/usr/bin/${e}`,`#!/bin/sh
314
1126
  exec builtin ${e} "$@"
315
1127
  `,493);C(n,"/usr/bin/lsb_release",`#!/bin/sh
316
1128
  exec lsb_release "$@"
317
- `,493)}function Qi(n){v(n,"/var"),v(n,"/var/log"),v(n,"/var/log/apt"),v(n,"/var/tmp"),v(n,"/var/cache"),v(n,"/var/cache/apt"),v(n,"/var/cache/apt/archives"),v(n,"/var/lib"),v(n,"/var/lib/apt"),v(n,"/var/lib/apt/lists"),v(n,"/var/lib/dpkg"),v(n,"/var/lib/dpkg/info"),v(n,"/var/lib/misc"),v(n,"/var/spool"),v(n,"/var/spool/cron"),v(n,"/var/mail"),C(n,"/var/lib/dpkg/status",""),C(n,"/var/lib/dpkg/available",""),C(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
318
- `),C(n,"/var/log/auth.log",""),C(n,"/var/log/kern.log",""),C(n,"/var/log/dpkg.log",""),C(n,"/var/log/apt/history.log",""),C(n,"/var/log/apt/term.log",""),v(n,"/run"),v(n,"/run/lock"),v(n,"/run/systemd"),v(n,"/run/user"),C(n,"/run/utmp","")}function Xi(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/var/run")||n.symlink("/run","/var/run"),v(n,"/lib"),v(n,"/lib64"),v(n,"/lib/x86_64-linux-gnu"),v(n,"/lib/modules")}function to(n){v(n,"/tmp",1023)}function eo(n){v(n,"/root",448),C(n,"/root/.bashrc",`${["# root .bashrc","export PS1='\\[\\033[0;31m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[0;34m\\]\\w\\[\\033[0m\\]# '","export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","alias ll='ls -la'","alias la='ls -A'"].join(`
1129
+ `,493)}function so(n){x(n,"/var"),x(n,"/var/log"),x(n,"/var/log/apt"),x(n,"/var/tmp"),x(n,"/var/cache"),x(n,"/var/cache/apt"),x(n,"/var/cache/apt/archives"),x(n,"/var/lib"),x(n,"/var/lib/apt"),x(n,"/var/lib/apt/lists"),x(n,"/var/lib/dpkg"),x(n,"/var/lib/dpkg/info"),x(n,"/var/lib/misc"),x(n,"/var/spool"),x(n,"/var/spool/cron"),x(n,"/var/mail"),C(n,"/var/lib/dpkg/status",""),C(n,"/var/lib/dpkg/available",""),C(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
1130
+ `),C(n,"/var/log/auth.log",""),C(n,"/var/log/kern.log",""),C(n,"/var/log/dpkg.log",""),C(n,"/var/log/apt/history.log",""),C(n,"/var/log/apt/term.log",""),x(n,"/run"),x(n,"/run/lock"),x(n,"/run/systemd"),x(n,"/run/user"),C(n,"/run/utmp","")}function io(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/var/run")||n.symlink("/run","/var/run"),x(n,"/lib"),x(n,"/lib64"),x(n,"/lib/x86_64-linux-gnu"),x(n,"/lib/modules")}function oo(n){x(n,"/tmp",1023)}function ao(n){x(n,"/root",448),C(n,"/root/.bashrc",`${["# root .bashrc","export PS1='\\[\\033[0;31m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[0;34m\\]\\w\\[\\033[0m\\]# '","export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","alias ll='ls -la'","alias la='ls -A'"].join(`
319
1131
  `)}
320
1132
  `),C(n,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
321
- `)}function no(n,t){v(n,"/opt"),v(n,"/srv"),v(n,"/mnt"),v(n,"/media"),v(n,"/home"),v(n,"/boot"),v(n,"/boot/grub"),v(n,"/boot/grub/grub.cfg.d"),C(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=5","",'menuentry "Fortune GNU/Linux" {'," linux /vmlinuz root=/dev/sda2 ro quiet splash"," initrd /initrd.img","}"].join(`
1133
+ `)}function lo(n,t){x(n,"/opt"),x(n,"/srv"),x(n,"/mnt"),x(n,"/media"),x(n,"/home"),x(n,"/boot"),x(n,"/boot/grub"),x(n,"/boot/grub/grub.cfg.d"),C(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=5","",'menuentry "Fortune GNU/Linux" {'," linux /vmlinuz root=/dev/sda2 ro quiet splash"," initrd /initrd.img","}"].join(`
322
1134
  `)}
323
1135
  `);let e=t.kernel;C(n,`/boot/vmlinuz-${e}`,"",420),C(n,`/boot/initrd.img-${e}`,"",420),C(n,`/boot/System.map-${e}`,`${e} virtual
324
1136
  `,420),C(n,`/boot/config-${e}`,`# Linux kernel config ${e}
325
- `,420),n.exists("/vmlinuz")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz"),n.exists("/vmlinuz.old")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz.old"),n.exists("/initrd.img")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img"),n.exists("/initrd.img.old")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img.old"),v(n,"/snap"),v(n,"/snap/bin"),v(n,"/lost+found",448)}function fs(n,t,e,r,i,s=[]){Ki(n,e,r),Ji(n,e,r),Zi(n),Yi(n),Qi(n),Xi(n),to(n),eo(n),no(n,r),Gi(n,r),ye(n,r,e,i,s),Le(n,t)}function hs(n){return n==="1"||n==="true"}function gs(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function ro(){return hs(process.env.DEV_MODE)||hs(process.env.RENDER_PERF)}function Se(n){let t=ro();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=gs(),r=s=>{let o=gs()-e;console.log(`[perf][${n}] ${s}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(s="done")=>{r(s)}}}import{EventEmitter as co}from"node:events";import*as B from"node:fs";import*as lt from"node:path";import{gunzipSync as We,gzipSync as Ps}from"node:zlib";var Ue=Buffer.from([86,70,83,33]),so=1,ys=1,Ss=2,ze=class{chunks=[];write(t){this.chunks.push(t)}writeUint8(t){let e=Buffer.allocUnsafe(1);e.writeUInt8(t,0),this.chunks.push(e)}writeUint16(t){let e=Buffer.allocUnsafe(2);e.writeUInt16LE(t,0),this.chunks.push(e)}writeUint32(t){let e=Buffer.allocUnsafe(4);e.writeUInt32LE(t,0),this.chunks.push(e)}writeFloat64(t){let e=Buffer.allocUnsafe(8);e.writeDoubleBE(t,0),this.chunks.push(e)}writeString(t){let e=Buffer.from(t,"utf8");this.writeUint16(e.length),this.chunks.push(e)}writeBytes(t){this.writeUint32(t.length),this.chunks.push(t)}toBuffer(){return Buffer.concat(this.chunks)}};function ws(n,t){if(t.type==="file"){let e=t;n.writeUint8(ys),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime()),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else{let e=t;n.writeUint8(Ss),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime());let r=Array.from(e.children.values());n.writeUint32(r.length);for(let i of r)ws(n,i)}}function xs(n){let t=new ze;return t.write(Ue),t.writeUint8(so),ws(t,n),t.toBuffer()}var Te=class{constructor(t){this.buf=t}buf;pos=0;readUint8(){return this.buf.readUInt8(this.pos++)}readUint16(){let t=this.buf.readUInt16LE(this.pos);return this.pos+=2,t}readUint32(){let t=this.buf.readUInt32LE(this.pos);return this.pos+=4,t}readFloat64(){let t=this.buf.readDoubleBE(this.pos);return this.pos+=8,t}readString(){let t=this.readUint16(),e=this.buf.toString("utf8",this.pos,this.pos+t);return this.pos+=t,e}readBytes(){let t=this.readUint32(),e=this.buf.slice(this.pos,this.pos+t);return this.pos+=t,e}remaining(){return this.buf.length-this.pos}};function bs(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),i=new Date(n.readFloat64()),s=new Date(n.readFloat64());if(t===ys){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:i,updatedAt:s,compressed:o,content:a}}if(t===Ss){let o=n.readUint32(),a=new Map;for(let l=0;l<o;l++){let c=bs(n);a.set(c.name,c)}return{type:"directory",name:e,mode:r,createdAt:i,updatedAt:s,children:a}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function Be(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(Ue))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new Te(n);for(let i=0;i<5;i++)e.readUint8();let r=bs(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function vs(n){return n.length>=4&&n.slice(0,4).equals(Ue)}import*as st from"node:fs";var O={WRITE:1,MKDIR:2,REMOVE:3,CHMOD:4,MOVE:5,SYMLINK:6},Kt="utf8";function io(n,t,e){let r=Buffer.from(e,Kt);return n.writeUInt16LE(r.length,t),r.copy(n,t+2),2+r.length}function oo(n){let t=Buffer.from(n.path,Kt),e=0;n.op===O.WRITE?e=4+(n.content?.length??0)+4:n.op===O.MKDIR?e=4:n.op===O.REMOVE?e=0:n.op===O.CHMOD?e=4:(n.op===O.MOVE||n.op===O.SYMLINK)&&(e=2+Buffer.byteLength(n.dest??"",Kt));let r=3+t.length+e,i=Buffer.allocUnsafe(r),s=0;if(i.writeUInt8(n.op,s++),i.writeUInt16LE(t.length,s),s+=2,t.copy(i,s),s+=t.length,n.op===O.WRITE){let o=n.content??Buffer.alloc(0);i.writeUInt32LE(o.length,s),s+=4,o.copy(i,s),s+=o.length,i.writeUInt32LE(n.mode??420,s),s+=4}else n.op===O.MKDIR?(i.writeUInt32LE(n.mode??493,s),s+=4):n.op===O.CHMOD?(i.writeUInt32LE(n.mode??420,s),s+=4):(n.op===O.MOVE||n.op===O.SYMLINK)&&(s+=io(i,s,n.dest??""));return i}function ao(n){let t=[],e=0;try{for(;e<n.length&&!(e+3>n.length);){let r=n.readUInt8(e++),i=n.readUInt16LE(e);if(e+=2,e+i>n.length)break;let s=n.subarray(e,e+i).toString(Kt);if(e+=i,r===O.WRITE){if(e+4>n.length)break;let o=n.readUInt32LE(e);if(e+=4,e+o+4>n.length)break;let a=Buffer.from(n.subarray(e,e+o));e+=o;let l=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,content:a,mode:l})}else if(r===O.MKDIR){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===O.REMOVE)t.push({op:r,path:s});else if(r===O.CHMOD){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===O.MOVE||r===O.SYMLINK){if(e+2>n.length)break;let o=n.readUInt16LE(e);if(e+=2,e+o>n.length)break;let a=n.subarray(e,e+o).toString(Kt);e+=o,t.push({op:r,path:s,dest:a})}else break}}catch{}return t}function Cs(n,t){let e=oo(t),r=st.openSync(n,st.constants.O_WRONLY|st.constants.O_CREAT|st.constants.O_APPEND);try{st.writeSync(r,e)}finally{st.closeSync(r)}}function Oe(n){if(!st.existsSync(n))return[];let t=st.readFileSync(n);return t.length===0?[]:ao(t)}function $s(n){st.existsSync(n)&&st.unlinkSync(n)}import*as we from"node:path";function W(n){if(!n||n.trim()==="")return"/";let t=we.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function lo(n){return n.split("/").filter(Boolean)}function it(n,t){let e=W(t);if(e==="/")return n;let r=lo(e),i=n;for(let s of r){if(i.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=i.children.get(s);if(!o)throw new Error(`Path '${e}' does not exist.`);i=o}return i}function Dt(n,t,e,r){let i=W(t);if(i==="/")throw new Error("Root path has no parent directory.");let s=we.posix.dirname(i),o=we.posix.basename(i);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(s);let a=it(n,s);if(a.type!=="directory")throw new Error(`Parent path '${s}' is not a directory.`);return{parent:a,name:o}}var je=class n extends co{root;mode;snapshotFile;journalFile;evictionThreshold;flushAfterNWrites;_writesSinceFlush=0;_flushTimer=null;_dirty=!1;mounts=new Map;static isBrowser=typeof process>"u"||typeof process.versions?.node>"u";constructor(t={}){if(super(),this.mode=t.mode??"memory",this.mode==="fs"){if(!t.snapshotPath)throw new Error('VirtualFileSystem: "snapshotPath" is required when mode is "fs".');this.snapshotFile=lt.resolve(t.snapshotPath,"vfs-snapshot.vfsb"),this.journalFile=lt.resolve(t.snapshotPath,"vfs-journal.bin"),this.evictionThreshold=t.evictionThresholdBytes??64*1024,this.flushAfterNWrites=t.flushAfterNWrites??500;let e=t.flushIntervalMs??3e4;e>0&&(this._flushTimer=setInterval(()=>{this._dirty&&this._autoFlush()},e),typeof this._flushTimer=="object"&&this._flushTimer!==null&&"unref"in this._flushTimer&&this._flushTimer.unref())}else this.snapshotFile=null,this.journalFile=null,this.evictionThreshold=0,this.flushAfterNWrites=0;this.root=this.makeDir("",493)}makeDir(t,e){let r=new Date;return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:new Map}}makeFile(t,e,r,i){let s=new Date;return{type:"file",name:t,content:e,mode:r,compressed:i,createdAt:s,updatedAt:s}}mkdirRecursive(t,e){let r=W(t);if(r==="/")return;let i=r.split("/").filter(Boolean),s=this.root,o="";for(let a of i){o+=`/${a}`;let l=s.children.get(a);if(!l)l=this.makeDir(a,e),s.children.set(a,l),this.emit("dir:create",{path:o,mode:e}),this._journal({op:O.MKDIR,path:o,mode:e});else if(l.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);s=l}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)){if(!B.existsSync(this.snapshotFile)){if(this.journalFile){let t=Oe(this.journalFile);t.length>0&&this._replayJournal(t)}return}try{let t=B.readFileSync(this.snapshotFile);if(vs(t))this.root=Be(t);else{let e=JSON.parse(t.toString("utf8"));this.root=this.deserializeDir(e.root,""),console.info("[VirtualFileSystem] Migrating legacy JSON snapshot to binary format.")}if(this.emit("snapshot:restore",{path:this.snapshotFile}),this.journalFile){let e=Oe(this.journalFile);e.length>0&&this._replayJournal(e)}}catch(t){console.warn(`[VirtualFileSystem] Could not restore snapshot from ${this.snapshotFile}:`,t instanceof Error?t.message:String(t))}}}async flushMirror(){if(this.mode!=="fs"||!this.snapshotFile){this.emit("mirror:flush");return}let t=lt.dirname(this.snapshotFile);B.mkdirSync(t,{recursive:!0});let e=xs(this.root);B.writeFileSync(this.snapshotFile,e),this.journalFile&&$s(this.journalFile),this._dirty=!1,this._writesSinceFlush=0,this.emit("mirror:flush",{path:this.snapshotFile}),this.evictLargeFiles()}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}async _autoFlush(){this._dirty&&await this.flushMirror()}_markDirty(){this._dirty=!0,this.flushAfterNWrites>0&&(this._writesSinceFlush++,this._writesSinceFlush>=this.flushAfterNWrites&&(this._writesSinceFlush=0,this._autoFlush()))}async stopAutoFlush(){this._flushTimer!==null&&(clearInterval(this._flushTimer),this._flushTimer=null),this._dirty&&await this.flushMirror()}_replayMode=!1;_journal(t){this.journalFile&&!this._replayMode&&(Cs(this.journalFile,t),this._markDirty())}_replayJournal(t){this._replayMode=!0;try{for(let e of t)try{e.op===O.WRITE?this.writeFile(e.path,e.content??Buffer.alloc(0),{mode:e.mode}):e.op===O.MKDIR?this.mkdir(e.path,e.mode):e.op===O.REMOVE?this.exists(e.path)&&this.remove(e.path,{recursive:!0}):e.op===O.CHMOD?this.exists(e.path)&&this.chmod(e.path,e.mode??420):e.op===O.MOVE?this.exists(e.path)&&e.dest&&this.move(e.path,e.dest):e.op===O.SYMLINK&&e.dest&&this.symlink(e.dest,e.path)}catch{}}finally{this._replayMode=!1}}evictLargeFiles(){!this.snapshotFile||this.evictionThreshold===0||B.existsSync(this.snapshotFile)&&this._evictDir(this.root)}_evictDir(t){for(let e of t.children.values())if(e.type==="directory")this._evictDir(e);else if(!e.evicted){let r=e.compressed?e.size??e.content.length*2:e.content.length;r>this.evictionThreshold&&(e.size=r,e.content=Buffer.alloc(0),e.evicted=!0)}}_reloadEvicted(t,e){if(!(!t.evicted||!this.snapshotFile)&&B.existsSync(this.snapshotFile))try{let r=B.readFileSync(this.snapshotFile),i=Be(r),s=e.split("/").filter(Boolean),o=i;for(let a of s){if(o.type!=="directory")return;let l=o.children.get(a);if(!l)return;o=l}o.type==="file"&&(t.content=o.content,t.compressed=o.compressed,t.evicted=void 0)}catch{}}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let i=W(t),s=lt.resolve(e);if(!B.existsSync(s))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${s}"`);if(!B.statSync(s).isDirectory())throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${s}"`);this.mkdir(i),this.mounts.set(i,{hostPath:s,readOnly:r}),this.emit("mount",{vPath:i,hostPath:s,readOnly:r})}unmount(t){let e=W(t);this.mounts.delete(e)&&this.emit("unmount",{vPath:e})}getMounts(){return[...this.mounts.entries()].map(([t,e])=>({vPath:t,...e}))}resolveMount(t){let e=W(t),r=[...this.mounts.entries()].sort(([i],[s])=>s.length-i.length);for(let[i,s]of r)if(e===i||e.startsWith(`${i}/`)){let o=e.slice(i.length).replace(/^\//,""),a=o?lt.join(s.hostPath,o):s.hostPath;return{hostPath:s.hostPath,readOnly:s.readOnly,relPath:o,fullHostPath:a}}return null}mkdir(t,e=493){let r=W(t),i=(()=>{try{return it(this.root,r)}catch{return null}})();if(i&&i.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let i=this.resolveMount(t);if(i){if(i.readOnly)throw new Error(`EROFS: read-only file system, open '${i.fullHostPath}'`);let p=lt.dirname(i.fullHostPath);B.existsSync(p)||B.mkdirSync(p,{recursive:!0}),B.writeFileSync(i.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let s=W(t),{parent:o,name:a}=Dt(this.root,s,!0,p=>this.mkdirRecursive(p,493)),l=o.children.get(a);if(l?.type==="directory")throw new Error(`Cannot write file '${s}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),u=r.compress??!1,d=u?Ps(c):c,m=r.mode??420;if(l){let p=l;p.content=d,p.compressed=u,p.mode=m,p.updatedAt=new Date}else o.children.set(a,this.makeFile(a,d,m,u));this.emit("file:write",{path:s,size:d.length}),this._journal({op:O.WRITE,path:s,content:c,mode:m})}readFile(t){let e=this.resolveMount(t);if(e){if(!B.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return B.readFileSync(e.fullHostPath,"utf8")}let r=W(t),i=it(this.root,r);if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?We(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o.toString("utf8")}readFileRaw(t){let e=this.resolveMount(t);if(e){if(!B.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return B.readFileSync(e.fullHostPath)}let r=W(t),i=it(this.root,r);if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?We(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o}exists(t){let e=this.resolveMount(t);if(e)return B.existsSync(e.fullHostPath);try{return it(this.root,W(t)),!0}catch{return!1}}chmod(t,e){let r=W(t);it(this.root,r).mode=e,this._journal({op:O.CHMOD,path:r,mode:e})}stat(t){let e=this.resolveMount(t);if(e){if(!B.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=B.statSync(e.fullHostPath),l=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",c=a.mtime;return a.isDirectory()?{type:"directory",name:l,path:W(t),mode:493,createdAt:a.birthtime,updatedAt:c,childrenCount:B.readdirSync(e.fullHostPath).length}:{type:"file",name:l,path:W(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:c,compressed:!1,size:a.size}}let r=W(t),i=it(this.root,r),s=r==="/"?"":lt.posix.basename(r);if(i.type==="file"){let a=i;return{type:"file",name:s,path:r,mode:a.mode,createdAt:a.createdAt,updatedAt:a.updatedAt,compressed:a.compressed,size:a.evicted?a.size??0:a.content.length}}let o=i;return{type:"directory",name:s,path:r,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,childrenCount:o.children.size}}list(t="/"){let e=this.resolveMount(t);if(e){if(!B.existsSync(e.fullHostPath))return[];try{return B.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=W(t),i=it(this.root,r);if(i.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Array.from(i.children.keys()).sort()}tree(t="/"){let e=W(t),r=it(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let i=t==="/"?"/":lt.posix.basename(e);return this.renderTreeLines(r,i)}renderTreeLines(t,e){let r=[e],i=Array.from(t.children.keys()).sort();for(let s=0;s<i.length;s++){let o=i[s],a=t.children.get(o),l=s===i.length-1,c=l?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",u=l?" ":"\u2502 ";if(r.push(`${c}${o}`),a.type==="directory"){let d=this.renderTreeLines(a,"").split(`
326
- `).slice(1).map(m=>`${u}${m}`);r.push(...d)}}return r.join(`
327
- `)}getUsageBytes(t="/"){return this.computeUsage(it(this.root,W(t)))}computeUsage(t){if(t.type==="file")return t.content.length;let e=0;for(let r of t.children.values())e+=this.computeUsage(r);return e}compressFile(t){let e=it(this.root,W(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=Ps(r.content),r.compressed=!0,r.updatedAt=new Date)}decompressFile(t){let e=it(this.root,W(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=We(r.content),r.compressed=!1,r.updatedAt=new Date)}symlink(t,e){let r=W(e),i=t.startsWith("/")?W(t):t,{parent:s,name:o}=Dt(this.root,r,!0,l=>this.mkdirRecursive(l,493)),a={type:"file",name:o,content:Buffer.from(i,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};s.children.set(o,a),this._journal({op:O.SYMLINK,path:r,dest:i}),this.emit("symlink:create",{link:r,target:i})}isSymlink(t){try{let e=it(this.root,W(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=W(t);for(let i=0;i<e;i++){try{let s=it(this.root,r);if(s.type==="file"&&s.mode===41471){let o=s.content.toString("utf8");r=o.startsWith("/")?o:W(lt.posix.join(lt.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=this.resolveMount(t);if(r){if(r.readOnly)throw new Error(`EROFS: read-only file system, unlink '${r.fullHostPath}'`);if(!B.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);B.statSync(r.fullHostPath).isDirectory()?B.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):B.unlinkSync(r.fullHostPath);return}let i=W(t);if(i==="/")throw new Error("Cannot remove root directory.");let s=it(this.root,i);if(s.type==="directory"){let l=s;if(!e.recursive&&l.children.size>0)throw new Error(`Directory '${i}' is not empty. Use recursive option.`)}let{parent:o,name:a}=Dt(this.root,i,!1,()=>{});o.children.delete(a),this.emit("node:remove",{path:i}),this._journal({op:O.REMOVE,path:i})}move(t,e){let r=W(t),i=W(e);if(r==="/"||i==="/")throw new Error("Cannot move root directory.");let s=it(this.root,r);if(this.exists(i))throw new Error(`Destination '${i}' already exists.`);this.mkdirRecursive(lt.posix.dirname(i),493);let{parent:o,name:a}=Dt(this.root,i,!1,()=>{}),{parent:l,name:c}=Dt(this.root,r,!1,()=>{});l.children.delete(c),s.name=a,o.children.set(a,s),this._journal({op:O.MOVE,path:r,dest:i})}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of t.children.values())e.push(r.type==="file"?this.serializeFile(r):this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),compressed:t.compressed,contentBase64:t.content.toString("base64")}}static fromSnapshot(t){let e=new n;return e.root=e.deserializeDir(t.root,""),e}importSnapshot(t){this.root=this.deserializeDir(t.root,""),this.emit("snapshot:import")}deserializeDir(t,e){let r={type:"directory",name:e,mode:t.mode,createdAt:new Date(t.createdAt),updatedAt:new Date(t.updatedAt),children:new Map};for(let i of t.children)if(i.type==="file"){let s=i;r.children.set(s.name,{type:"file",name:s.name,mode:s.mode,createdAt:new Date(s.createdAt),updatedAt:new Date(s.updatedAt),compressed:s.compressed,content:Buffer.from(s.contentBase64,"base64")})}else{let s=this.deserializeDir(i,i.name);r.children.set(i.name,s)}return r}},ks=je;var He=[{name:"vim",version:"2:9.0.1378-2",section:"editors",description:"Vi IMproved - enhanced vi editor",shortDesc:"Vi IMproved",installedSizeKb:3812,files:[{path:"/usr/bin/vim",content:`#!/bin/sh
1137
+ `,420),n.exists("/vmlinuz")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz"),n.exists("/vmlinuz.old")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz.old"),n.exists("/initrd.img")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img"),n.exists("/initrd.img.old")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img.old"),x(n,"/snap"),x(n,"/snap/bin"),x(n,"/lost+found",448)}var Ps=new Map;function co(n,t){return`${n}|${t.kernel}|${t.os}|${t.arch}`}function uo(n,t){let e=co(n,t),r=Ps.get(e);if(r)return r;let i=new Se({mode:"memory"});Xi(i,n,t),eo(i,n,t),no(i),ro(i),so(i),io(i),oo(i),lo(i,t),to(i,t);let s=i.encodeBinary();return Ps.set(e,s),s}function Ns(n,t,e,r,i,s=[]){let o=uo(e,r);n.importRootTree(Mt(o)),ao(n),we(n,r,e,i,s),Ye(n,t)}function Es(n){return n==="1"||n==="true"}function Ms(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function mo(){return Es(process.env.DEV_MODE)||Es(process.env.RENDER_PERF)}function be(n){let t=mo();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Ms(),r=s=>{let o=Ms()-e;console.log(`[perf][${n}] ${s}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(s="done")=>{r(s)}}}var Ke=[{name:"vim",version:"2:9.0.1378-2",section:"editors",description:"Vi IMproved - enhanced vi editor",shortDesc:"Vi IMproved",installedSizeKb:3812,files:[{path:"/usr/bin/vim",content:`#!/bin/sh
328
1138
  echo 'vim: use nano for editing in this environment'
329
1139
  `,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
330
1140
  exec vim "$@"
@@ -413,19 +1223,19 @@ echo 'journalctl: virtual stub'
413
1223
  echo 'gzip: virtual stub'
414
1224
  `,mode:493}]},{name:"neofetch",version:"7.1.0-1",section:"utils",description:"A command-line system information tool written in bash 3.2+",shortDesc:"command-line system information tool",installedSizeKb:256,files:[{path:"/usr/bin/neofetch",content:`#!/bin/sh
415
1225
  echo 'neofetch: virtual stub'
416
- `,mode:493}]}],xe=class{constructor(t,e){this.vfs=t;this.users=e}vfs;users;installed=new Map;registryPath="/var/lib/dpkg/status";logPath="/var/log/dpkg.log";aptLogPath="/var/log/apt/history.log";load(){if(!this.vfs.exists(this.registryPath))return;let t=this.vfs.readFile(this.registryPath);if(!t.trim())return;let e=t.split(/\n\n+/);for(let r of e){if(!r.trim())continue;let i=this.parseFields(r),s=i.Package;s&&this.installed.set(s,{name:s,version:i.Version??"unknown",architecture:i.Architecture??"amd64",maintainer:i.Maintainer??"Fortune Maintainers",description:i.Description??"",section:i.Section??"misc",installedSizeKb:Number(i["Installed-Size"]??0),installedAt:i["X-Installed-At"]??new Date().toISOString(),files:(i["X-Files"]??"").split("|").filter(Boolean)})}}persist(){let t=[];for(let e of this.installed.values())t.push([`Package: ${e.name}`,"Status: install ok installed","Priority: optional",`Section: ${e.section}`,`Installed-Size: ${e.installedSizeKb}`,`Maintainer: ${e.maintainer}`,`Architecture: ${e.architecture}`,`Version: ${e.version}`,`Description: ${e.description}`,`X-Installed-At: ${e.installedAt}`,`X-Files: ${e.files.join("|")}`].join(`
1226
+ `,mode:493}]}],ve=class{constructor(t,e){this.vfs=t;this.users=e}vfs;users;installed=new Map;registryPath="/var/lib/dpkg/status";logPath="/var/log/dpkg.log";aptLogPath="/var/log/apt/history.log";load(){if(!this.vfs.exists(this.registryPath))return;let t=this.vfs.readFile(this.registryPath);if(!t.trim())return;let e=t.split(/\n\n+/);for(let r of e){if(!r.trim())continue;let i=this.parseFields(r),s=i.Package;s&&this.installed.set(s,{name:s,version:i.Version??"unknown",architecture:i.Architecture??"amd64",maintainer:i.Maintainer??"Fortune Maintainers",description:i.Description??"",section:i.Section??"misc",installedSizeKb:Number(i["Installed-Size"]??0),installedAt:i["X-Installed-At"]??new Date().toISOString(),files:(i["X-Files"]??"").split("|").filter(Boolean)})}}persist(){let t=[];for(let e of this.installed.values())t.push([`Package: ${e.name}`,"Status: install ok installed","Priority: optional",`Section: ${e.section}`,`Installed-Size: ${e.installedSizeKb}`,`Maintainer: ${e.maintainer}`,`Architecture: ${e.architecture}`,`Version: ${e.version}`,`Description: ${e.description}`,`X-Installed-At: ${e.installedAt}`,`X-Files: ${e.files.join("|")}`].join(`
417
1227
  `));this.vfs.writeFile(this.registryPath,`${t.join(`
418
1228
 
419
1229
  `)}
420
1230
  `)}parseFields(t){let e={};for(let r of t.split(`
421
1231
  `)){let i=r.indexOf(": ");i!==-1&&(e[r.slice(0,i)]=r.slice(i+2))}return e}log(t){let r=`${new Date().toISOString().replace("T"," ").slice(0,19)} ${t}
422
1232
  `,i=this.vfs.exists(this.logPath)?this.vfs.readFile(this.logPath):"";this.vfs.writeFile(this.logPath,i+r)}aptLog(t,e){let r=new Date().toISOString(),i=this.vfs.exists(this.aptLogPath)?this.vfs.readFile(this.aptLogPath):"",s=[`Start-Date: ${r}`,`Commandline: apt-get ${t} ${e.join(" ")}`,`${t==="install"?"Install":"Remove"}: ${e.join(", ")}`,`End-Date: ${r}`,""].join(`
423
- `);this.vfs.writeFile(this.aptLogPath,i+s)}findInRegistry(t){return He.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...He].sort((t,e)=>t.name.localeCompare(e.name))}listInstalled(){return[...this.installed.values()].sort((t,e)=>t.name.localeCompare(e.name))}isInstalled(t){return this.installed.has(t.toLowerCase())}installedCount(){return this.installed.size}install(t,e={}){let r=[],i=[],s=[],o=(l,c=new Set)=>{if(c.has(l)||(c.add(l),this.isInstalled(l)))return;let u=this.findInRegistry(l);if(!u){s.push(l);return}for(let d of u.depends??[])o(d,c);i.find(d=>d.name===u.name)||i.push(u)};for(let l of t)o(l);if(s.length>0)return{output:`E: Unable to locate package ${s.join(", ")}`,exitCode:100};if(i.length===0)return{output:t.map(l=>`${l} is already the newest version.`).join(`
1233
+ `);this.vfs.writeFile(this.aptLogPath,i+s)}findInRegistry(t){return Ke.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...Ke].sort((t,e)=>t.name.localeCompare(e.name))}listInstalled(){return[...this.installed.values()].sort((t,e)=>t.name.localeCompare(e.name))}isInstalled(t){return this.installed.has(t.toLowerCase())}installedCount(){return this.installed.size}install(t,e={}){let r=[],i=[],s=[],o=(l,c=new Set)=>{if(c.has(l)||(c.add(l),this.isInstalled(l)))return;let u=this.findInRegistry(l);if(!u){s.push(l);return}for(let d of u.depends??[])o(d,c);i.find(d=>d.name===u.name)||i.push(u)};for(let l of t)o(l);if(s.length>0)return{output:`E: Unable to locate package ${s.join(", ")}`,exitCode:100};if(i.length===0)return{output:t.map(l=>`${l} is already the newest version.`).join(`
424
1234
  `),exitCode:0};let a=i.reduce((l,c)=>l+(c.installedSizeKb??0),0);e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","The following NEW packages will be installed:",` ${i.map(l=>l.name).join(" ")}`,`0 upgraded, ${i.length} newly installed, 0 to remove and 0 not upgraded.`,`Need to get 0 B/${a} kB of archives.`,`After this operation, ${a} kB of additional disk space will be used.`,"");for(let l of i){e.quiet||(r.push(`Selecting previously unselected package ${l.name}.`),r.push("(Reading database ... 12345 files and directories currently installed.)"),r.push(`Preparing to unpack .../archives/${l.name}_${l.version}_amd64.deb ...`),r.push(`Unpacking ${l.name} (${l.version}) ...`));for(let u of l.files??[]){let d=u.path.slice(0,u.path.lastIndexOf("/"));d&&!this.vfs.exists(d)&&this.vfs.mkdir(d,493),this.vfs.writeFile(u.path,u.content,{mode:u.mode??420})}l.onInstall?.(this.vfs,this.users),e.quiet||r.push(`Setting up ${l.name} (${l.version}) ...`);let c=new Date().toISOString();this.installed.set(l.name,{name:l.name,version:l.version,architecture:l.architecture??"amd64",maintainer:l.maintainer??"Fortune Maintainers <pkg@fortune.local>",description:l.description,section:l.section??"misc",installedSizeKb:l.installedSizeKb??0,installedAt:c,files:(l.files??[]).map(u=>u.path)}),this.log(`install ${l.name} ${l.version}`)}return this.aptLog("install",i.map(l=>l.name)),this.persist(),e.quiet||r.push("Processing triggers for man-db (2.11.2-2) ..."),{output:r.join(`
425
1235
  `),exitCode:0}}remove(t,e={}){let r=[],i=[];for(let s of t){let o=this.installed.get(s.toLowerCase());o?i.push(o):r.push(`Package '${s}' is not installed, so not removed`)}if(i.length===0)return{output:r.join(`
426
1236
  `)||"Nothing to remove.",exitCode:0};e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","The following packages will be REMOVED:",` ${i.map(s=>s.name).join(" ")}`,`0 upgraded, 0 newly installed, ${i.length} to remove and 0 not upgraded.`);for(let s of i){e.quiet||r.push(`Removing ${s.name} (${s.version}) ...`);for(let a of s.files)if(!(!e.purge&&(a.startsWith("/etc/")||a.endsWith(".conf"))))try{this.vfs.exists(a)&&this.vfs.remove(a)}catch{}this.findInRegistry(s.name)?.onRemove?.(this.vfs),this.installed.delete(s.name),this.log(`remove ${s.name} ${s.version}`)}return this.aptLog("remove",i.map(s=>s.name)),this.persist(),{output:r.join(`
427
- `),exitCode:0}}search(t){let e=t.toLowerCase();return He.filter(r=>r.name.includes(e)||r.description.toLowerCase().includes(e)||(r.shortDesc??"").toLowerCase().includes(e)).sort((r,i)=>r.name.localeCompare(i.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let r=this.installed.get(t);return[`Package: ${e.name}`,`Version: ${e.version}`,`Architecture: ${e.architecture??"amd64"}`,`Maintainer: ${e.maintainer??"Fortune Maintainers <pkg@fortune.local>"}`,`Installed-Size: ${e.installedSizeKb??0}`,`Depends: ${(e.depends??[]).join(", ")||"(none)"}`,`Section: ${e.section??"misc"}`,"Priority: optional",`Description: ${e.description}`,`Status: ${r?"install ok installed":"install ok not-installed"}`].join(`
428
- `)}};import{createHash as Ms,randomBytes as uo,randomUUID as mo,scryptSync as po,timingSafeEqual as fo}from"node:crypto";import{EventEmitter as ho}from"node:events";import*as As from"node:path";function go(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var et=Se("VirtualUserManager"),be=class n extends ho{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;et.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=go();usersPath="/etc/htpasswd";sudoersPath="/etc/sudoers";quotasPath="/etc/quotas";authDirPath="/.virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){et.mark("initialize"),this.loadFromVfs(),this.loadSudoersFromVfs(),this.loadQuotasFromVfs();let e=!1;this.users.has("root")||(this.users.set("root",this.createRecord("root","")),e=!0),this.sudoers.add("root"),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(et.mark("setQuotaBytes"),this.validateUsername(e),!this.users.has(e))throw new Error(`quota: user '${e}' does not exist`);if(!Number.isFinite(r)||r<0)throw new Error("quota: maxBytes must be a non-negative number");this.quotas.set(e,Math.floor(r)),await this.persist()}async clearQuota(e){et.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return et.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){et.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,i){et.mark("assertWriteWithinQuota");let s=this.quotas.get(e);if(s===void 0)return;let o=Es(r),a=Es(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let c=this.getUsageBytes(e),u=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(u=p.size)}let d=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i,"utf8"),m=c-u+d;if(m>s)throw new Error(`quota exceeded for '${e}': ${m}/${s} bytes`)}verifyPassword(e,r){et.mark("verifyPassword");let i=this.users.get(e);if(!i)return this.hashPassword(r,""),!1;let s=this.hashPassword(r,i.salt),o=i.passwordHash;try{let a=Buffer.from(s,"hex"),l=Buffer.from(o,"hex");return a.length!==l.length?!1:fo(a,l)}catch{return s===o}}async addUser(e,r){if(et.mark("addUser"),this.validateUsername(e),this.validatePassword(r),this.users.has(e))return;this.users.set(e,this.createRecord(e,r)),this.autoSudoForNewUsers&&this.sudoers.add(e);let i=`/home/${e}`;this.vfs.exists(i)||(this.vfs.mkdir(i,493),this.vfs.writeFile(`${i}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){et.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(et.mark("setPassword"),this.validateUsername(e),this.validatePassword(r),!this.users.has(e))throw new Error(`passwd: user '${e}' does not exist`);this.users.set(e,this.createRecord(e,r)),await this.persist()}async deleteUser(e){if(et.mark("deleteUser"),this.validateUsername(e),e==="root")throw new Error("deluser: cannot delete root");if(!this.users.delete(e))throw new Error(`deluser: user '${e}' does not exist`);this.sudoers.delete(e),this.emit("user:delete",{username:e}),await this.persist()}isSudoer(e){return et.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(et.mark("addSudoer"),this.validateUsername(e),!this.users.has(e))throw new Error(`sudoers: user '${e}' does not exist`);this.sudoers.add(e),await this.persist()}async removeSudoer(e){if(et.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){et.mark("registerSession");let i={id:mo(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(i.id,i),this.emit("session:register",{sessionId:i.id,username:e,remoteAddress:r}),i}unregisterSession(e){if(et.mark("unregisterSession"),!e)return;let r=this.activeSessions.get(e);this.activeSessions.delete(e),r&&this.emit("session:unregister",{sessionId:e,username:r.username}),this.activeSessions.delete(e)}updateSession(e,r,i){if(et.mark("updateSession"),!e)return;let s=this.activeSessions.get(e);s&&this.activeSessions.set(e,{...s,username:r,remoteAddress:i})}listActiveSessions(){return et.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.startedAt))}listUsers(){return Array.from(this.users.keys()).sort()}loadFromVfs(){if(this.users.clear(),!this.vfs.exists(this.usersPath))return;let e=this.vfs.readFile(this.usersPath);for(let r of e.split(`
1237
+ `),exitCode:0}}search(t){let e=t.toLowerCase();return Ke.filter(r=>r.name.includes(e)||r.description.toLowerCase().includes(e)||(r.shortDesc??"").toLowerCase().includes(e)).sort((r,i)=>r.name.localeCompare(i.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let r=this.installed.get(t);return[`Package: ${e.name}`,`Version: ${e.version}`,`Architecture: ${e.architecture??"amd64"}`,`Maintainer: ${e.maintainer??"Fortune Maintainers <pkg@fortune.local>"}`,`Installed-Size: ${e.installedSizeKb??0}`,`Depends: ${(e.depends??[]).join(", ")||"(none)"}`,`Section: ${e.section??"misc"}`,"Priority: optional",`Description: ${e.description}`,`Status: ${r?"install ok installed":"install ok not-installed"}`].join(`
1238
+ `)}};import{createHash as ks,randomBytes as po,randomUUID as fo,scryptSync as ho,timingSafeEqual as go}from"node:crypto";import{EventEmitter as yo}from"node:events";import*as As from"node:path";function So(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var et=be("VirtualUserManager"),xe=class n extends yo{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;et.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=So();usersPath="/etc/htpasswd";sudoersPath="/etc/sudoers";quotasPath="/etc/quotas";authDirPath="/.virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){et.mark("initialize"),this.loadFromVfs(),this.loadSudoersFromVfs(),this.loadQuotasFromVfs();let e=!1;this.users.has("root")||(this.users.set("root",this.createRecord("root","")),e=!0),this.sudoers.add("root"),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(et.mark("setQuotaBytes"),this.validateUsername(e),!this.users.has(e))throw new Error(`quota: user '${e}' does not exist`);if(!Number.isFinite(r)||r<0)throw new Error("quota: maxBytes must be a non-negative number");this.quotas.set(e,Math.floor(r)),await this.persist()}async clearQuota(e){et.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return et.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){et.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,i){et.mark("assertWriteWithinQuota");let s=this.quotas.get(e);if(s===void 0)return;let o=Is(r),a=Is(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let c=this.getUsageBytes(e),u=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(u=p.size)}let d=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i,"utf8"),m=c-u+d;if(m>s)throw new Error(`quota exceeded for '${e}': ${m}/${s} bytes`)}verifyPassword(e,r){et.mark("verifyPassword");let i=this.users.get(e);if(!i)return this.hashPassword(r,""),!1;let s=this.hashPassword(r,i.salt),o=i.passwordHash;try{let a=Buffer.from(s,"hex"),l=Buffer.from(o,"hex");return a.length!==l.length?!1:go(a,l)}catch{return s===o}}async addUser(e,r){if(et.mark("addUser"),this.validateUsername(e),this.validatePassword(r),this.users.has(e))return;this.users.set(e,this.createRecord(e,r)),this.autoSudoForNewUsers&&this.sudoers.add(e);let i=`/home/${e}`;this.vfs.exists(i)||(this.vfs.mkdir(i,493),this.vfs.writeFile(`${i}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){et.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(et.mark("setPassword"),this.validateUsername(e),this.validatePassword(r),!this.users.has(e))throw new Error(`passwd: user '${e}' does not exist`);this.users.set(e,this.createRecord(e,r)),await this.persist()}async deleteUser(e){if(et.mark("deleteUser"),this.validateUsername(e),e==="root")throw new Error("deluser: cannot delete root");if(!this.users.delete(e))throw new Error(`deluser: user '${e}' does not exist`);this.sudoers.delete(e),this.emit("user:delete",{username:e}),await this.persist()}isSudoer(e){return et.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(et.mark("addSudoer"),this.validateUsername(e),!this.users.has(e))throw new Error(`sudoers: user '${e}' does not exist`);this.sudoers.add(e),await this.persist()}async removeSudoer(e){if(et.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){et.mark("registerSession");let i={id:fo(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(i.id,i),this.emit("session:register",{sessionId:i.id,username:e,remoteAddress:r}),i}unregisterSession(e){if(et.mark("unregisterSession"),!e)return;let r=this.activeSessions.get(e);this.activeSessions.delete(e),r&&this.emit("session:unregister",{sessionId:e,username:r.username}),this.activeSessions.delete(e)}updateSession(e,r,i){if(et.mark("updateSession"),!e)return;let s=this.activeSessions.get(e);s&&this.activeSessions.set(e,{...s,username:r,remoteAddress:i})}listActiveSessions(){return et.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.startedAt))}listUsers(){return Array.from(this.users.keys()).sort()}loadFromVfs(){if(this.users.clear(),!this.vfs.exists(this.usersPath))return;let e=this.vfs.readFile(this.usersPath);for(let r of e.split(`
429
1239
  `)){let i=r.trim();if(i.length===0)continue;let s=i.split(":");if(s.length<3)continue;let[o,a,l]=s;!o||!a||!l||this.users.set(o,{username:o,salt:a,passwordHash:l})}}loadSudoersFromVfs(){if(this.sudoers.clear(),!this.vfs.exists(this.sudoersPath))return;let e=this.vfs.readFile(this.sudoersPath);for(let r of e.split(`
430
1240
  `)){let i=r.trim();i.length>0&&this.sudoers.add(i)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let r of e.split(`
431
1241
  `)){let i=r.trim();if(i.length===0)continue;let[s,o]=i.split(":"),a=Number.parseInt(o??"",10);!s||!Number.isFinite(a)||a<0||this.quotas.set(s,a)}}async persist(){this.vfs.exists(this.authDirPath)||this.vfs.mkdir(this.authDirPath,448);let e=Array.from(this.users.values()).sort((o,a)=>o.username.localeCompare(a.username)).map(o=>[o.username,o.salt,o.passwordHash].join(":")).join(`
@@ -434,55 +1244,57 @@ echo 'neofetch: virtual stub'
434
1244
  `),s=!1;s=this.writeIfChanged(this.usersPath,e.length>0?`${e}
435
1245
  `:"",384)||s,s=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
436
1246
  `:"",384)||s,s=this.writeIfChanged(this.quotasPath,i.length>0?`${i}
437
- `:"",384)||s,s&&await this.vfs.flushMirror()}writeIfChanged(e,r,i){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,i),!1):(this.vfs.writeFile(e,r,{mode:i}),!0)}createRecord(e,r){let i=Ms("sha256").update(e).update(":").update(r).digest("hex"),s=n.recordCache.get(i);if(s)return s;let o=uo(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(i,a),a}hasPassword(e){et.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let i=this.hashPassword("",r.salt);return r.passwordHash===i?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?Ms("sha256").update(r).update(e).digest("hex"):po(e,r||"",32).toString("hex")}validateUsername(e){if(!e||e.trim()==="")throw new Error("invalid username");if(!/^[a-z_][a-z0-9_-]{0,31}$/i.test(e))throw new Error("invalid username")}validatePassword(e){if(!e||e.trim()==="")throw new Error("invalid password")}authorizedKeys=new Map;addAuthorizedKey(e,r,i){et.mark("addAuthorizedKey");let s=this.authorizedKeys.get(e)??[];s.push({algo:r,data:i}),this.authorizedKeys.set(e,s),this.emit("key:add",{username:e,algo:r})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function Es(n){let t=As.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}import{readFile as yo,unlink as So,writeFile as wo}from"node:fs/promises";import*as qe from"node:path";function Fs(n,t,e,r,i,s="unknown",o={cols:80,rows:24},a){let l="",c=0,u=xo(a.vfs,e),d=null,m="",p=`/home/${e}`,h=It(e,r),y=null,f=null,S=()=>{let _=`/home/${e}`,z=p===_?"~":qe.posix.basename(p)||"/";return ge(e,r,z)},F=Array.from(new Set(Wt())).sort();console.log(`[${i}] Shell started for user '${e}' at ${s}`),(async()=>{let _=`/home/${e}/.bashrc`;if(a.vfs.exists(_))try{let z=a.vfs.readFile(_);for(let U of z.split(`
438
- `)){let D=U.trim();!D||D.startsWith("#")||await J(D,e,r,"shell",p,a,void 0,h)}}catch{}})();function A(){let _=S();t.write(`\r${_}${l}\x1B[K`);let z=l.length-c;z>0&&t.write(`\x1B[${z}D`)}function x(){t.write("\r\x1B[K")}function E(_){f={..._,buffer:""},x(),t.write(_.prompt)}async function N(_){if(!f)return;let z=f;if(f=null,!_){t.write(`\r
1247
+ `:"",384)||s,s&&await this.vfs.flushMirror()}writeIfChanged(e,r,i){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,i),!1):(this.vfs.writeFile(e,r,{mode:i}),!0)}createRecord(e,r){let i=ks("sha256").update(e).update(":").update(r).digest("hex"),s=n.recordCache.get(i);if(s)return s;let o=po(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(i,a),a}hasPassword(e){et.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let i=this.hashPassword("",r.salt);return r.passwordHash===i?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?ks("sha256").update(r).update(e).digest("hex"):ho(e,r||"",32).toString("hex")}validateUsername(e){if(!e||e.trim()==="")throw new Error("invalid username");if(!/^[a-z_][a-z0-9_-]{0,31}$/i.test(e))throw new Error("invalid username")}validatePassword(e){if(!e||e.trim()==="")throw new Error("invalid password")}authorizedKeys=new Map;addAuthorizedKey(e,r,i){et.mark("addAuthorizedKey");let s=this.authorizedKeys.get(e)??[];s.push({algo:r,data:i}),this.authorizedKeys.set(e,s),this.emit("key:add",{username:e,algo:r})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function Is(n){let t=As.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}import{EventEmitter as wo}from"node:events";var Ce=class extends wo{vfs;idleThresholdMs;checkIntervalMs;_state="active";_lastActivity=Date.now();_frozenBuffer=null;_checkTimer=null;constructor(t,e={}){super(),this.vfs=t,this.idleThresholdMs=e.idleThresholdMs??6e4,this.checkIntervalMs=e.checkIntervalMs??15e3}start(){this._checkTimer||(this._lastActivity=Date.now(),this._checkTimer=setInterval(()=>this._check(),this.checkIntervalMs),typeof this._checkTimer=="object"&&this._checkTimer!==null&&"unref"in this._checkTimer&&this._checkTimer.unref())}async stop(){this._checkTimer&&(clearInterval(this._checkTimer),this._checkTimer=null),this._state==="frozen"&&await this._thaw()}async ping(){this._lastActivity=Date.now(),this._state==="frozen"&&await this._thaw()}get state(){return this._state}get idleMs(){return Date.now()-this._lastActivity}_check(){this._state!=="frozen"&&Date.now()-this._lastActivity>=this.idleThresholdMs&&this._freeze()}async _freeze(){this._state!=="frozen"&&(await this.vfs.stopAutoFlush(),this._frozenBuffer=this.vfs.encodeBinary(),this.vfs.releaseTree(),this._state="frozen",this.emit("freeze"))}async _thaw(){if(this._state!=="frozen"||!this._frozenBuffer)return;let t=Mt(this._frozenBuffer);this.vfs.importRootTree(t),this._frozenBuffer=null,this._state="active",this.emit("thaw")}};import{readFile as bo,unlink as vo,writeFile as xo}from"node:fs/promises";import*as Ge from"node:path";function Os(n,t,e,r,i,s="unknown",o={cols:80,rows:24},a){let l="",c=0,u=Co(a.vfs,e),d=null,m="",p=`/home/${e}`,h=Tt(e,r),y=null,f=null,S=()=>{let O=`/home/${e}`,U=p===O?"~":Ge.posix.basename(p)||"/";return ge(e,r,U)},I=Array.from(new Set(jt())).sort();console.log(`[${i}] Shell started for user '${e}' at ${s}`),(async()=>{let O=`/home/${e}/.bashrc`;if(a.vfs.exists(O))try{let U=a.vfs.readFile(O);for(let V of U.split(`
1248
+ `)){let _=V.trim();!_||_.startsWith("#")||await J(_,e,r,"shell",p,a,void 0,h)}}catch{}})();function k(){let O=S();t.write(`\r${O}${l}\x1B[K`);let U=l.length-c;U>0&&t.write(`\x1B[${U}D`)}function b(){t.write("\r\x1B[K")}function M(O){f={...O,buffer:""},b(),t.write(O.prompt)}async function A(O){if(!f)return;let U=f;if(f=null,!O){t.write(`\r
439
1249
  Sorry, try again.\r
440
- `),A();return}if(!z.commandLine){e=z.targetUser,z.loginShell&&(p=`/home/${e}`),a.users.updateSession(i,e,s),t.write(`\r
441
- `),A();return}let U=z.loginShell?`/home/${z.targetUser}`:p,D=await Promise.resolve(J(z.commandLine,z.targetUser,r,"shell",U,a));if(t.write(`\r
442
- `),D.openEditor){await M(D.openEditor.targetPath,D.openEditor.initialContent,D.openEditor.tempPath);return}if(D.openHtop){await V();return}D.clearScreen&&t.write("\x1B[2J\x1B[H"),D.stdout&&t.write(`${qt(D.stdout)}\r
443
- `),D.stderr&&t.write(`${qt(D.stderr)}\r
444
- `),D.switchUser?(e=D.switchUser,p=D.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s)):D.nextCwd&&(p=D.nextCwd),A()}async function b(){if(!y)return;let _=y;if(_.kind==="nano"){try{let z=await yo(_.tempPath,"utf8");a.writeFileAsUser(e,_.targetPath,z)}catch{}await So(_.tempPath).catch(()=>{})}y=null,l="",c=0,t.write(`\r
445
- `),A()}async function M(_,z,U){a.vfs.exists(_)&&await wo(U,z,"utf8");let D=fe(U,o,t);D.on("error",nt=>{t.write(`nano: ${nt.message}\r
446
- `),b()}),D.on("close",()=>{b()}),y={kind:"nano",targetPath:_,tempPath:U,process:D}}async function V(){let _=await cs();if(!_){t.write(`htop: no child_process processes to display\r
447
- `);return}let z=ds(_,o,t);z.on("error",U=>{t.write(`htop: ${U.message}\r
448
- `),b()}),z.on("close",()=>{b()}),y={kind:"htop",targetPath:"",tempPath:"",process:z}}function P(_){l=_,c=l.length,A()}function $(_){l=`${l.slice(0,c)}${_}${l.slice(c)}`,c+=_.length,A()}function I(_,z){let U=z;for(;U>0&&!/\s/.test(_[U-1]);)U-=1;let D=z;for(;D<_.length&&!/\s/.test(_[D]);)D+=1;return{start:U,end:D}}function Y(_){let z=_.lastIndexOf("/"),U=z>=0?_.slice(0,z+1):"",D=z>=0?_.slice(z+1):_,nt=pe(p,U||".");try{return a.vfs.list(nt).filter(T=>!T.startsWith(".")).filter(T=>T.startsWith(D)).map(T=>{let gt=qe.posix.join(nt,T),kt=a.vfs.stat(gt).type==="directory"?"/":"";return`${U}${T}${kt}`}).sort()}catch{return[]}}function j(){let{start:_,end:z}=I(l,c),U=l.slice(_,c);if(U.length===0)return;let nt=l.slice(0,_).trim().length===0?F.filter(mt=>mt.startsWith(U)):[],T=Y(U),gt=Array.from(new Set([...nt,...T])).sort();if(gt.length!==0){if(gt.length===1){let mt=gt[0],kt=mt.endsWith("/")?"":" ";l=`${l.slice(0,_)}${mt}${kt}${l.slice(z)}`,c=_+mt.length+kt.length,A();return}t.write(`\r
1250
+ `),k();return}if(!U.commandLine){e=U.targetUser,U.loginShell&&(p=`/home/${e}`),a.users.updateSession(i,e,s),t.write(`\r
1251
+ `),k();return}let V=U.loginShell?`/home/${U.targetUser}`:p,_=await Promise.resolve(J(U.commandLine,U.targetUser,r,"shell",V,a));if(t.write(`\r
1252
+ `),_.openEditor){await E(_.openEditor.targetPath,_.openEditor.initialContent,_.openEditor.tempPath);return}if(_.openHtop){await T();return}_.clearScreen&&t.write("\x1B[2J\x1B[H"),_.stdout&&t.write(`${Yt(_.stdout)}\r
1253
+ `),_.stderr&&t.write(`${Yt(_.stderr)}\r
1254
+ `),_.switchUser?(e=_.switchUser,p=_.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s)):_.nextCwd&&(p=_.nextCwd),k()}async function v(){if(!y)return;let O=y;if(O.kind==="nano"){try{let U=await bo(O.tempPath,"utf8");a.writeFileAsUser(e,O.targetPath,U)}catch{}await vo(O.tempPath).catch(()=>{})}y=null,l="",c=0,t.write(`\r
1255
+ `),k()}async function E(O,U,V){a.vfs.exists(O)&&await xo(V,U,"utf8");let _=fe(V,o,t);_.on("error",nt=>{t.write(`nano: ${nt.message}\r
1256
+ `),v()}),_.on("close",()=>{v()}),y={kind:"nano",targetPath:O,tempPath:V,process:_}}async function T(){let O=await ps();if(!O){t.write(`htop: no child_process processes to display\r
1257
+ `);return}let U=hs(O,o,t);U.on("error",V=>{t.write(`htop: ${V.message}\r
1258
+ `),v()}),U.on("close",()=>{v()}),y={kind:"htop",targetPath:"",tempPath:"",process:U}}function P(O){l=O,c=l.length,k()}function $(O){l=`${l.slice(0,c)}${O}${l.slice(c)}`,c+=O.length,k()}function F(O,U){let V=U;for(;V>0&&!/\s/.test(O[V-1]);)V-=1;let _=U;for(;_<O.length&&!/\s/.test(O[_]);)_+=1;return{start:V,end:_}}function Z(O){let U=O.lastIndexOf("/"),V=U>=0?O.slice(0,U+1):"",_=U>=0?O.slice(U+1):O,nt=pe(p,V||".");try{return a.vfs.list(nt).filter(L=>!L.startsWith(".")).filter(L=>L.startsWith(_)).map(L=>{let gt=Ge.posix.join(nt,L),Nt=a.vfs.stat(gt).type==="directory"?"/":"";return`${V}${L}${Nt}`}).sort()}catch{return[]}}function j(){let{start:O,end:U}=F(l,c),V=l.slice(O,c);if(V.length===0)return;let nt=l.slice(0,O).trim().length===0?I.filter(mt=>mt.startsWith(V)):[],L=Z(V),gt=Array.from(new Set([...nt,...L])).sort();if(gt.length!==0){if(gt.length===1){let mt=gt[0],Nt=mt.endsWith("/")?"":" ";l=`${l.slice(0,O)}${mt}${Nt}${l.slice(U)}`,c=O+mt.length+Nt.length,k();return}t.write(`\r
449
1259
  `),t.write(`${gt.join(" ")}\r
450
- `),A()}}function Q(_){if(_.length===0)return;u.push(_),u.length>500&&(u=u.slice(u.length-500));let z=u.length>0?`${u.join(`
1260
+ `),k()}}function Q(O){if(O.length===0)return;u.push(O),u.length>500&&(u=u.slice(u.length-500));let U=u.length>0?`${u.join(`
451
1261
  `)}
452
- `:"";a.vfs.writeFile(`/home/${e}/.bash_history`,z)}function xt(){let _=`/home/${e}/.lastlog.json`;if(!a.vfs.exists(_))return null;try{return JSON.parse(a.vfs.readFile(_))}catch{return null}}function ht(_){let z=`/home/${e}/.lastlog`;a.vfs.writeFile(z,JSON.stringify({at:_,from:s}))}function bt(){let _=xt(),z=new Date().toISOString();t.write(he(r,n,_)),ht(z)}bt(),A(),t.on("data",async _=>{if(y){y.process.stdin.write(_);return}if(f){let U=_.toString("utf8");for(let D=0;D<U.length;D+=1){let nt=U[D];if(nt===""){f=null,t.write(`^C\r
453
- `),A();return}if(nt==="\x7F"||nt==="\b"){f.buffer=f.buffer.slice(0,-1);continue}if(nt==="\r"||nt===`
454
- `){let T=f.buffer;if(f.buffer="",f.onPassword){let{result:mt,nextPrompt:kt}=await f.onPassword(T,a);t.write(`\r
1262
+ `:"";a.vfs.writeFile(`/home/${e}/.bash_history`,U)}function bt(){let O=`/home/${e}/.lastlog.json`;if(!a.vfs.exists(O))return null;try{return JSON.parse(a.vfs.readFile(O))}catch{return null}}function ht(O){let U=`/home/${e}/.lastlog`;a.vfs.writeFile(U,JSON.stringify({at:O,from:s}))}function vt(){let O=bt(),U=new Date().toISOString();t.write(he(r,n,O)),ht(U)}vt(),k(),t.on("data",async O=>{if(y){y.process.stdin.write(O);return}if(f){let V=O.toString("utf8");for(let _=0;_<V.length;_+=1){let nt=V[_];if(nt===""){f=null,t.write(`^C\r
1263
+ `),k();return}if(nt==="\x7F"||nt==="\b"){f.buffer=f.buffer.slice(0,-1);continue}if(nt==="\r"||nt===`
1264
+ `){let L=f.buffer;if(f.buffer="",f.onPassword){let{result:mt,nextPrompt:Nt}=await f.onPassword(L,a);t.write(`\r
455
1265
  `),mt!==null?(f=null,mt.stdout&&t.write(mt.stdout.replace(/\n/g,`\r
456
1266
  `)),mt.stderr&&t.write(mt.stderr.replace(/\n/g,`\r
457
- `)),A()):(kt&&(f.prompt=kt),t.write(f.prompt));return}let gt=a.users.verifyPassword(f.username,T);await N(gt);return}nt>=" "&&(f.buffer+=nt)}return}let z=_.toString("utf8");for(let U=0;U<z.length;U+=1){let D=z[U];if(D===""){l="",c=0,d=null,m="",t.write(`bye\r
1267
+ `)),k()):(Nt&&(f.prompt=Nt),t.write(f.prompt));return}let gt=a.users.verifyPassword(f.username,L);await A(gt);return}nt>=" "&&(f.buffer+=nt)}return}let U=O.toString("utf8");for(let V=0;V<U.length;V+=1){let _=U[V];if(_===""){l="",c=0,d=null,m="",t.write(`bye\r
458
1268
  `),Q("bye"),t.write(`logout\r
459
- `),t.exit(0),t.end();return}if(D===" "){j();continue}if(D==="\x1B"){let nt=z[U+1],T=z[U+2],gt=z[U+3];if(nt==="["&&T){if(T==="A"){U+=2,u.length>0&&(d===null?(m=l,d=u.length-1):d>0&&(d-=1),P(u[d]??""));continue}if(T==="B"){U+=2,d!==null&&(d<u.length-1?(d+=1,P(u[d]??"")):(d=null,P(m)));continue}if(T==="C"){U+=2,c<l.length&&(c+=1,t.write("\x1B[C"));continue}if(T==="D"){U+=2,c>0&&(c-=1,t.write("\x1B[D"));continue}if(T==="3"&&gt==="~"){U+=3,c<l.length&&(l=`${l.slice(0,c)}${l.slice(c+1)}`,A());continue}}}if(D===""){l="",c=0,d=null,m="",t.write(`^C\r
460
- `),A();continue}if(D==="\r"||D===`
1269
+ `),t.exit(0),t.end();return}if(_===" "){j();continue}if(_==="\x1B"){let nt=U[V+1],L=U[V+2],gt=U[V+3];if(nt==="["&&L){if(L==="A"){V+=2,u.length>0&&(d===null?(m=l,d=u.length-1):d>0&&(d-=1),P(u[d]??""));continue}if(L==="B"){V+=2,d!==null&&(d<u.length-1?(d+=1,P(u[d]??"")):(d=null,P(m)));continue}if(L==="C"){V+=2,c<l.length&&(c+=1,t.write("\x1B[C"));continue}if(L==="D"){V+=2,c>0&&(c-=1,t.write("\x1B[D"));continue}if(L==="3"&&gt==="~"){V+=3,c<l.length&&(l=`${l.slice(0,c)}${l.slice(c+1)}`,k());continue}}}if(_===""){l="",c=0,d=null,m="",t.write(`^C\r
1270
+ `),k();continue}if(_==="\r"||_===`
461
1271
  `){let nt=l.trim();if(l="",c=0,d=null,m="",t.write(`\r
462
- `),nt.length>0){let T=await Promise.resolve(J(nt,e,r,"shell",p,a,void 0,h));if(Q(nt),T.openEditor){await M(T.openEditor.targetPath,T.openEditor.initialContent,T.openEditor.tempPath);return}if(T.openHtop){await V();return}if(T.sudoChallenge){E(T.sudoChallenge);return}if(T.clearScreen&&t.write("\x1B[2J\x1B[H"),T.stdout&&t.write(`${qt(T.stdout)}\r
463
- `),T.stderr&&t.write(`${qt(T.stderr)}\r
464
- `),T.closeSession){t.write(`logout\r
465
- `),t.exit(T.exitCode??0),t.end();return}T.nextCwd&&(p=T.nextCwd),T.switchUser&&(e=T.switchUser,p=T.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s),l="",c=0)}A();continue}if(D==="\x7F"||D==="\b"){c>0&&(l=`${l.slice(0,c-1)}${l.slice(c)}`,c-=1,A());continue}$(D)}}),t.on("close",()=>{y&&(y.process.kill("SIGTERM"),y=null)})}function xo(n,t){let e=`/home/${t}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
466
- `).map(i=>i.trim()).filter(i=>i.length>0):(n.writeFile(e,""),[])}function vo(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&Ns(n.vfsInstance)}function Ns(n){if(typeof n!="object"||n===null)return!1;let t=n;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 Co={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Gt=Se("VirtualShell");function $o(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var ve=class extends bo{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,e,r){super(),Gt.mark("constructor"),this.hostname=t,this.properties=e||Co,this.startTime=Date.now(),Ns(r)?this.vfs=r:vo(r)?this.vfs=r.vfsInstance:this.vfs=new ks(r??{}),this.users=new be(this.vfs,$o()),this.packageManager=new xe(this.vfs,this.users);let i=this.vfs,s=this.users,o=this.packageManager,a=this.properties,l=this.hostname,c=this.startTime;this.initialized=(async()=>{await i.restoreMirror(),await s.initialize(),fs(i,s,l,a,c),o.load(),this.emit("initialized")})()}async ensureInitialized(){Gt.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let i=t.trim().toLowerCase();if(i.length===0||/\s/.test(i))throw new Error("Command name must be non-empty and contain no spaces");Fe(Ne(i,e,r))}executeCommand(t,e,r){Gt.mark("executeCommand"),J(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,i,s){Gt.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:r,remoteAddress:i}),Fs(this.properties,t,e,this.hostname,r,i,s,this),this.refreshProcSessions()}refreshProcFs(){ye(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,e,r={}){this.vfs.mount(t,e,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){ye(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Le(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){Gt.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}};var Lt=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Ke=process.argv.slice(2);console.clear();function Fo(){for(let n=0;n<Ke.length;n+=1){let t=Ke[n];if(t==="--user"){let e=Ke[n+1];if(!e||e.startsWith("--"))throw new Error("self-standalone: --user requires a value");return e}if(t?.startsWith("--user="))return t.slice(7)||"root"}return"root"}var No=Fo(),Z=new ve(Lt,void 0,{mode:"fs",snapshotPath:".vfs"});function _o(n){let t=`/home/${n}/.lastlog`;if(!Z.vfs.exists(t))return null;try{return JSON.parse(Z.vfs.readFile(t))}catch{return null}}function Io(n,t){Z.vfs.writeFile(`/home/${n}/.lastlog`,JSON.stringify({at:new Date().toISOString(),from:t}))}async function Jt(){await Z.vfs.stopAutoFlush()}function Ro(n){let t=`/home/${n}/.bash_history`;return Z.vfs.exists(t)?Z.vfs.readFile(t).split(`
467
- `).map(e=>e.trim()).filter(e=>e.length>0):(Z.vfs.writeFile(t,""),[])}function Vo(n,t){let e=n.length>0?`${n.join(`
1272
+ `),nt.length>0){let L=await Promise.resolve(J(nt,e,r,"shell",p,a,void 0,h));if(Q(nt),L.openEditor){await E(L.openEditor.targetPath,L.openEditor.initialContent,L.openEditor.tempPath);return}if(L.openHtop){await T();return}if(L.sudoChallenge){M(L.sudoChallenge);return}if(L.clearScreen&&t.write("\x1B[2J\x1B[H"),L.stdout&&t.write(`${Yt(L.stdout)}\r
1273
+ `),L.stderr&&t.write(`${Yt(L.stderr)}\r
1274
+ `),L.closeSession){t.write(`logout\r
1275
+ `),t.exit(L.exitCode??0),t.end();return}L.nextCwd&&(p=L.nextCwd),L.switchUser&&(e=L.switchUser,p=L.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s),l="",c=0)}k();continue}if(_==="\x7F"||_==="\b"){c>0&&(l=`${l.slice(0,c-1)}${l.slice(c)}`,c-=1,k());continue}$(_)}}),t.on("close",()=>{y&&(y.process.kill("SIGTERM"),y=null)})}function Co(n,t){let e=`/home/${t}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
1276
+ `).map(i=>i.trim()).filter(i=>i.length>0):(n.writeFile(e,""),[])}function Po(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&Fs(n.vfsInstance)}function Fs(n){if(typeof n!="object"||n===null)return!1;let t=n;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 No={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Gt=be("VirtualShell");function Eo(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var $e=class extends $o{vfs;users;packageManager;hostname;properties;startTime;_idle=null;initialized;constructor(t,e,r){super(),Gt.mark("constructor"),this.hostname=t,this.properties=e||No,this.startTime=Date.now(),Fs(r)?this.vfs=r:Po(r)?this.vfs=r.vfsInstance:this.vfs=new Se(r??{}),this.users=new xe(this.vfs,Eo()),this.packageManager=new ve(this.vfs,this.users);let i=this.vfs,s=this.users,o=this.packageManager,a=this.properties,l=this.hostname,c=this.startTime;this.initialized=(async()=>{await i.restoreMirror(),await s.initialize(),Ns(i,s,l,a,c),o.load(),this.emit("initialized")})()}async ensureInitialized(){Gt.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let i=t.trim().toLowerCase();if(i.length===0||/\s/.test(i))throw new Error("Command name must be non-empty and contain no spaces");Oe(Fe(i,e,r))}executeCommand(t,e,r){Gt.mark("executeCommand"),this._idle&&this._idle.ping(),J(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,i,s){Gt.mark("startInteractiveSession"),this._idle&&this._idle.ping(),this.emit("session:start",{user:e,sessionId:r,remoteAddress:i}),Os(this.properties,t,e,this.hostname,r,i,s,this),this.refreshProcSessions()}refreshProcFs(){we(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,e,r={}){this.vfs.mount(t,e,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){we(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Ye(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){Gt.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}enableIdleManagement(t){this._idle||(this._idle=new Ce(this.vfs,t),this._idle.on("freeze",()=>this.emit("shell:freeze")),this._idle.on("thaw",()=>this.emit("shell:thaw")),this._idle.start())}async disableIdleManagement(){this._idle&&(await this._idle.stop(),this._idle=null)}get idleState(){return this._idle?.state??"active"}get idleMs(){return this._idle?.idleMs??0}};var Ut=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Je=process.argv.slice(2);console.clear();function Fo(){for(let n=0;n<Je.length;n+=1){let t=Je[n];if(t==="--user"){let e=Je[n+1];if(!e||e.startsWith("--"))throw new Error("self-standalone: --user requires a value");return e}if(t?.startsWith("--user="))return t.slice(7)||"root"}return"root"}var Ro=Fo(),q=new $e(Ut,void 0,{mode:"fs",snapshotPath:".vfs"});function To(n){let t=`/home/${n}/.lastlog`;if(!q.vfs.exists(t))return null;try{return JSON.parse(q.vfs.readFile(t))}catch{return null}}function _o(n,t){q.vfs.writeFile(`/home/${n}/.lastlog`,JSON.stringify({at:new Date().toISOString(),from:t}))}async function Jt(){await q.vfs.stopAutoFlush()}function Do(n){let t=`/home/${n}/.bash_history`;return q.vfs.exists(t)?q.vfs.readFile(t).split(`
1277
+ `).map(e=>e.trim()).filter(e=>e.length>0):(q.vfs.writeFile(t,""),[])}function Uo(n,t){let e=n.length>0?`${n.join(`
468
1278
  `)}
469
- `:"";Z.vfs.writeFile(`/home/${t}/.bash_history`,e)}function Do(n,t,e){let r=e.lastIndexOf("/"),i=r>=0?e.slice(0,r+1):"",s=r>=0?e.slice(r+1):e,o=pe(t,i||".");try{return n.list(o).filter(a=>!a.startsWith(".")&&a.startsWith(s)).map(a=>{let l=_s.posix.join(o,a),c=n.stat(l);return`${i}${a}${c.type==="directory"?"/":""}`}).sort()}catch{return[]}}function Lo(n){let t=Array.from(new Set(Wt())).sort();return(e,r)=>{let{cwd:i}=n(),s=e.split(/\s+/).at(-1)??"",a=e.trimStart()===s?t.filter(u=>u.startsWith(s)):[],l=Do(Z.vfs,i,s),c=Array.from(new Set([...a,...l])).sort();r(null,[c,s])}}function Zt(n,t){return new Promise(e=>{if(!ut.isTTY||!ot.isTTY){n.question(t,e);return}let r=!!ut.isRaw,i="",s=()=>{ut.off("data",a),r||ut.setRawMode(!1)},o=l=>{s(),ot.write(`
1279
+ `:"";q.vfs.writeFile(`/home/${t}/.bash_history`,e)}function Lo(n,t,e){let r=e.lastIndexOf("/"),i=r>=0?e.slice(0,r+1):"",s=r>=0?e.slice(r+1):e,o=pe(t,i||".");try{return n.list(o).filter(a=>!a.startsWith(".")&&a.startsWith(s)).map(a=>{let l=Ts.posix.join(o,a),c=n.stat(l);return`${i}${a}${c.type==="directory"?"/":""}`}).sort()}catch{return[]}}function Vo(n){let t=Array.from(new Set(jt())).sort();return(e,r)=>{let{cwd:i}=n(),s=e.split(/\s+/).at(-1)??"",a=e.trimStart()===s?t.filter(u=>u.startsWith(s)):[],l=Lo(q.vfs,i,s),c=Array.from(new Set([...a,...l])).sort();r(null,[c,s])}}function Zt(n,t){return new Promise(e=>{if(!ut.isTTY||!ot.isTTY){n.question(t,e);return}let r=!!ut.isRaw,i="",s=()=>{ut.off("data",a),r||ut.setRawMode(!1)},o=l=>{s(),ot.write(`
470
1280
  `),e(l)},a=l=>{let c=l.toString("utf8");for(let u=0;u<c.length;u+=1){let d=c[u];if(d==="\r"||d===`
471
- `){o(i);return}if(d==="\x7F"||d==="\b"){i=i.slice(0,-1);continue}d>=" "&&(i+=d)}};n.pause(),ot.write(t),r||ut.setRawMode(!0),ut.resume(),ut.on("data",a)})}function zo(n,t,e,r){let i=n,s=t;return e.switchUser?(i=e.switchUser,s=e.nextCwd??`/home/${i}`,r.vars.USER=i,r.vars.LOGNAME=i,r.vars.HOME=`/home/${i}`,r.vars.PWD=s):e.nextCwd&&(s=e.nextCwd,r.vars.PWD=s),{authUser:i,cwd:s}}Z.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));async function To(){await Z.ensureInitialized();let n=No.trim()||"root";Z.users.getPasswordHash(n)===null&&(process.stderr.write(`self-standalone: user '${n}' does not exist
472
- `),process.exit(1));let t=It(n,Lt),e=n,r=`/home/${e}`;t.vars.PWD=r;let i="localhost",s={cols:ot.columns??80,rows:ot.rows??24},o=Ro(e),a=Ao({input:ut,output:ot,terminal:!0,completer:Lo(()=>({cwd:r}))}),l=a;l.history=[...o].reverse();async function c(f,S,F){Z.vfs.exists(f)&&await Mo(F,S,"utf8"),a.pause();let A=fe(F,s,{write:ot.write.bind(ot),exit:()=>{},end:()=>{}}),x=!!ut.isRaw,E=N=>{A.stdin.write(N)};ut.resume(),x||ut.setRawMode(!0),ut.on("data",E),await new Promise(N=>{let b=()=>{ut.off("data",E),x||ut.setRawMode(!1),a.resume()};A.on("error",M=>{b(),ot.write(`nano: ${M.message}\r
473
- `),N()}),A.on("close",async()=>{b(),a.write("",{ctrl:!0,name:"u"});try{let M=await Po(F,"utf8");Z.writeFileAsUser(e,f,M),await Jt()}catch{}await ko(F).catch(()=>{}),ot.write(`\r
474
- `),N()})})}async function u(f){if(f.onPassword){let x=f.prompt;for(;;){let E=await Zt(a,x),N=await f.onPassword(E,Z);if(N.result===null){x=N.nextPrompt??x;continue}await m(N.result);return}}let S=await Zt(a,f.prompt);if(!Z.users.verifyPassword(f.username,S)){process.stderr.write(`Sorry, try again.
475
- `);return}if(!f.commandLine){e=f.targetUser,r=`/home/${e}`,t.vars.USER=e,t.vars.LOGNAME=e,t.vars.HOME=`/home/${e}`,t.vars.PWD=r;return}let F=f.loginShell?`/home/${f.targetUser}`:r,A=await J(f.commandLine,f.targetUser,Lt,"shell",F,Z,void 0,t);await m(A)}async function d(f){let S=await Zt(a,f.prompt);if(f.confirmPrompt&&await Zt(a,f.confirmPrompt)!==S){process.stderr.write(`passwords do not match
476
- `);return}switch(f.action){case"passwd":await Z.users.setPassword(f.targetUsername,S),ot.write(`passwd: password updated successfully
1281
+ `){o(i);return}if(d==="\x7F"||d==="\b"){i=i.slice(0,-1);continue}d>=" "&&(i+=d)}};n.pause(),ot.write(t),r||ut.setRawMode(!0),ut.resume(),ut.on("data",a)})}function zo(n,t,e,r){let i=n,s=t;return e.switchUser?(i=e.switchUser,s=e.nextCwd??`/home/${i}`,r.vars.USER=i,r.vars.LOGNAME=i,r.vars.HOME=`/home/${i}`,r.vars.PWD=s):e.nextCwd&&(s=e.nextCwd,r.vars.PWD=s),{authUser:i,cwd:s}}q.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));async function Bo(){await q.ensureInitialized();let n=Ro.trim()||"root";q.users.getPasswordHash(n)===null&&(process.stderr.write(`self-standalone: user '${n}' does not exist
1282
+ `),process.exit(1));let t=Tt(n,Ut),e=n,r=`/home/${e}`;t.vars.PWD=r;let i="localhost",s={cols:ot.columns??80,rows:ot.rows??24},o=Do(e),a=Oo({input:ut,output:ot,terminal:!0,completer:Vo(()=>({cwd:r}))}),l=a;l.history=[...o].reverse();async function c(f,S,I){q.vfs.exists(f)&&await Io(I,S,"utf8"),a.pause();let k=fe(I,s,{write:ot.write.bind(ot),exit:()=>{},end:()=>{}}),b=!!ut.isRaw,M=A=>{k.stdin.write(A)};ut.resume(),b||ut.setRawMode(!0),ut.on("data",M),await new Promise(A=>{let v=()=>{ut.off("data",M),b||ut.setRawMode(!1),a.resume()};k.on("error",E=>{v(),ot.write(`nano: ${E.message}\r
1283
+ `),A()}),k.on("close",async()=>{v(),a.write("",{ctrl:!0,name:"u"});try{let E=await Mo(I,"utf8");q.writeFileAsUser(e,f,E),await Jt()}catch{}await ko(I).catch(()=>{}),ot.write(`\r
1284
+ `),A()})})}async function u(f){if(f.onPassword){let b=f.prompt;for(;;){let M=await Zt(a,b),A=await f.onPassword(M,q);if(A.result===null){b=A.nextPrompt??b;continue}await m(A.result);return}}let S=await Zt(a,f.prompt);if(!q.users.verifyPassword(f.username,S)){process.stderr.write(`Sorry, try again.
1285
+ `);return}if(!f.commandLine){e=f.targetUser,r=`/home/${e}`,t.vars.USER=e,t.vars.LOGNAME=e,t.vars.HOME=`/home/${e}`,t.vars.PWD=r;return}let I=f.loginShell?`/home/${f.targetUser}`:r,k=await J(f.commandLine,f.targetUser,Ut,"shell",I,q,void 0,t);await m(k)}async function d(f){let S=await Zt(a,f.prompt);if(f.confirmPrompt&&await Zt(a,f.confirmPrompt)!==S){process.stderr.write(`passwords do not match
1286
+ `);return}switch(f.action){case"passwd":await q.users.setPassword(f.targetUsername,S),ot.write(`passwd: password updated successfully
477
1287
  `);break;case"adduser":if(!f.newUsername){process.stderr.write(`adduser: missing username
478
- `);return}await Z.users.addUser(f.newUsername,S),ot.write(`adduser: user '${f.newUsername}' created
479
- `);break;case"deluser":await Z.users.deleteUser(f.targetUsername),ot.write(`Removing user '${f.targetUsername}' ...
1288
+ `);return}await q.users.addUser(f.newUsername,S),ot.write(`adduser: user '${f.newUsername}' created
1289
+ `);break;case"deluser":await q.users.deleteUser(f.targetUsername),ot.write(`Removing user '${f.targetUsername}' ...
480
1290
  deluser: done.
481
1291
  `);break;case"su":e=f.targetUsername,r=`/home/${e}`,t.vars.USER=e,t.vars.LOGNAME=e,t.vars.HOME=`/home/${e}`,t.vars.PWD=r;break}}async function m(f){if(f.openEditor){await c(f.openEditor.targetPath,f.openEditor.initialContent,f.openEditor.tempPath);return}if(f.sudoChallenge){await u(f.sudoChallenge);return}if(f.passwordChallenge){await d(f.passwordChallenge);return}f.clearScreen&&(ot.write("\x1B[2J\x1B[H"),console.clear()),f.stdout&&ot.write(f.stdout.endsWith(`
482
1292
  `)?f.stdout:`${f.stdout}
483
1293
  `),f.stderr&&process.stderr.write(f.stderr.endsWith(`
484
1294
  `)?f.stderr:`${f.stderr}
485
- `);let S=zo(e,r,f,t);e=S.authUser,r=S.cwd,f.closeSession&&(await Jt(),a.close(),process.exit(f.exitCode??0))}let p=()=>{let f=r===`/home/${e}`?"~":Eo(r)||"/";return ge(e,Lt,f)},h=()=>{a.setPrompt(p()),a.prompt()};if(process.env.USER!=="root"&&Z.users.hasPassword(e)){let f=await Zt(a,`Password for ${e}: `);Z.users.verifyPassword(e,f)||(process.stderr.write(`self-standalone: authentication failed
486
- `),process.exit(1))}ot.write(he(Lt,Z.properties,_o(e))),Io(e,i),await Jt();let y=!1;a.on("line",async f=>{if(y)return;y=!0,a.pause(),f.trim().length>0&&(o.push(f),o.length>500&&(o=o.slice(o.length-500)),Vo(o,e),l.history=[...o].reverse());let F=await J(f,e,Lt,"shell",r,Z,void 0,t);await m(F),await Jt(),y=!1,a.resume(),h()}),a.on("SIGINT",()=>{ot.write(`^C
487
- `),a.write("",{ctrl:!0,name:"u"}),h()}),a.on("close",()=>{Jt().then(()=>{console.log(""),process.exit(0)})}),h()}To().catch(n=>{console.error("Failed to start readline SSH emulation:",n),process.exit(1)});process.on("uncaughtException",n=>{console.error("Uncaught exception:",n)});process.on("unhandledRejection",(n,t)=>{console.error("Unhandled rejection at:",t,"error:",n)});
1295
+ `);let S=zo(e,r,f,t);e=S.authUser,r=S.cwd,f.closeSession&&(await Jt(),a.close(),process.exit(f.exitCode??0))}let p=()=>{let f=r===`/home/${e}`?"~":Ao(r)||"/";return ge(e,Ut,f)},h=()=>{a.setPrompt(p()),a.prompt()};if(process.env.USER!=="root"&&q.users.hasPassword(e)){let f=await Zt(a,`Password for ${e}: `);q.users.verifyPassword(e,f)||(process.stderr.write(`self-standalone: authentication failed
1296
+ `),process.exit(1))}ot.write(he(Ut,q.properties,To(e))),_o(e,i),await Jt();let y=!1;a.on("line",async f=>{if(y)return;y=!0,a.pause(),f.trim().length>0&&(o.push(f),o.length>500&&(o=o.slice(o.length-500)),Uo(o,e),l.history=[...o].reverse());let I=await J(f,e,Ut,"shell",r,q,void 0,t);await m(I),await Jt(),y=!1,a.resume(),h()}),a.on("SIGINT",()=>{ot.write(`^C
1297
+ `),a.write("",{ctrl:!0,name:"u"}),h()}),a.on("close",()=>{Jt().then(()=>{console.log(""),process.exit(0)})}),h()}Bo().catch(n=>{console.error("Failed to start readline SSH emulation:",n),process.exit(1)});var Rs=!1;async function Wo(n){if(!Rs){Rs=!0,process.stdout.write(`
1298
+ [${n}] Saving VFS...
1299
+ `);try{await q.vfs.stopAutoFlush()}catch{}process.exit(0)}}process.on("SIGTERM",()=>{Wo("SIGTERM")});process.on("beforeExit",()=>{q.vfs.stopAutoFlush()});process.on("uncaughtException",n=>{console.error("Uncaught exception:",n)});process.on("unhandledRejection",(n,t)=>{console.error("Unhandled rejection at:",t,"error:",n)});
488
1300
  //# sourceMappingURL=self-standalone.js.map