typescript-virtual-container 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +2 -2
- package/README.md +34 -28
- package/build.js +22 -0
- package/builds/{fortune-nyx-v1.5.1-directbash-k6.1.0.mjs → fortune-nyx-v1.5.3-directbash-k6.1.0.mjs} +187 -191
- package/builds/{fortune-nyx-v1.5.1-ssh-nosftp.js → fortune-nyx-v1.5.3-ssh-nosftp.js} +214 -218
- package/builds/{fortune-nyx-v1.5.1-ssh.cjs → fortune-nyx-v1.5.3-ssh.cjs} +142 -146
- package/builds/fortune-nyx-v1.5.3-web.min.js +17036 -0
- package/bun.lock +74 -0
- package/dist/Honeypot/index.d.ts +0 -1
- package/dist/Honeypot/index.js +0 -1
- package/dist/SSHClient/index.d.ts +0 -1
- package/dist/SSHClient/index.js +0 -1
- package/dist/SSHMimic/exec.d.ts +0 -1
- package/dist/SSHMimic/exec.js +0 -1
- package/dist/SSHMimic/executor.d.ts +0 -1
- package/dist/SSHMimic/executor.js +0 -1
- package/dist/SSHMimic/hostKey.d.ts +0 -1
- package/dist/SSHMimic/hostKey.js +0 -1
- package/dist/SSHMimic/index.d.ts +0 -1
- package/dist/SSHMimic/index.js +0 -1
- package/dist/SSHMimic/loginBanner.d.ts +0 -1
- package/dist/SSHMimic/loginBanner.js +0 -1
- package/dist/SSHMimic/loginFormat.d.ts +0 -1
- package/dist/SSHMimic/loginFormat.js +0 -1
- package/dist/SSHMimic/prompt.d.ts +0 -1
- package/dist/SSHMimic/prompt.js +0 -1
- package/dist/SSHMimic/sftp.d.ts +0 -1
- package/dist/SSHMimic/sftp.js +0 -1
- package/dist/VirtualFileSystem/binaryPack.d.ts +0 -1
- package/dist/VirtualFileSystem/binaryPack.js +0 -1
- package/dist/VirtualFileSystem/index.d.ts +0 -1
- package/dist/VirtualFileSystem/index.js +0 -1
- package/dist/VirtualFileSystem/internalTypes.d.ts +0 -1
- package/dist/VirtualFileSystem/internalTypes.js +0 -1
- package/dist/VirtualFileSystem/journal.d.ts +0 -1
- package/dist/VirtualFileSystem/journal.js +0 -1
- package/dist/VirtualFileSystem/path.d.ts +0 -1
- package/dist/VirtualFileSystem/path.js +0 -1
- package/dist/VirtualPackageManager/index.d.ts +0 -1
- package/dist/VirtualPackageManager/index.js +3 -14
- package/dist/VirtualShell/idleManager.d.ts +0 -1
- package/dist/VirtualShell/idleManager.js +0 -1
- package/dist/VirtualShell/index.d.ts +3 -2
- package/dist/VirtualShell/index.js +4 -2
- package/dist/VirtualShell/shell.d.ts +0 -1
- package/dist/VirtualShell/shell.js +0 -1
- package/dist/VirtualShell/shellParser.d.ts +0 -1
- package/dist/VirtualShell/shellParser.js +0 -1
- package/dist/VirtualUserManager/index.d.ts +0 -1
- package/dist/VirtualUserManager/index.js +0 -1
- package/dist/commands/adduser.d.ts +0 -1
- package/dist/commands/adduser.js +0 -1
- package/dist/commands/alias.d.ts +0 -1
- package/dist/commands/alias.js +0 -1
- package/dist/commands/apt.d.ts +0 -1
- package/dist/commands/apt.js +0 -1
- package/dist/commands/awk.d.ts +0 -1
- package/dist/commands/awk.js +0 -1
- package/dist/commands/base64.d.ts +0 -1
- package/dist/commands/base64.js +0 -1
- package/dist/commands/cat.d.ts +0 -1
- package/dist/commands/cat.js +0 -1
- package/dist/commands/cd.d.ts +0 -1
- package/dist/commands/cd.js +0 -1
- package/dist/commands/chmod.d.ts +0 -1
- package/dist/commands/chmod.js +0 -1
- package/dist/commands/clear.d.ts +0 -1
- package/dist/commands/clear.js +0 -1
- package/dist/commands/command-helpers.d.ts +0 -1
- package/dist/commands/command-helpers.js +0 -1
- package/dist/commands/cp.d.ts +0 -1
- package/dist/commands/cp.js +0 -1
- package/dist/commands/curl.d.ts +0 -1
- package/dist/commands/curl.js +0 -1
- package/dist/commands/cut.d.ts +0 -1
- package/dist/commands/cut.js +0 -1
- package/dist/commands/date.d.ts +0 -1
- package/dist/commands/date.js +0 -1
- package/dist/commands/declare.d.ts +0 -1
- package/dist/commands/declare.js +0 -1
- package/dist/commands/deluser.d.ts +0 -1
- package/dist/commands/deluser.js +0 -1
- package/dist/commands/df.d.ts +0 -1
- package/dist/commands/df.js +0 -1
- package/dist/commands/diff.d.ts +0 -1
- package/dist/commands/diff.js +0 -1
- package/dist/commands/dpkg.d.ts +0 -1
- package/dist/commands/dpkg.js +0 -1
- package/dist/commands/du.d.ts +0 -1
- package/dist/commands/du.js +0 -1
- package/dist/commands/echo.d.ts +0 -1
- package/dist/commands/echo.js +0 -1
- package/dist/commands/env.d.ts +0 -1
- package/dist/commands/env.js +0 -1
- package/dist/commands/exit.d.ts +0 -1
- package/dist/commands/exit.js +0 -1
- package/dist/commands/export.d.ts +0 -1
- package/dist/commands/export.js +0 -1
- package/dist/commands/find.d.ts +0 -1
- package/dist/commands/find.js +0 -1
- package/dist/commands/free.d.ts +0 -1
- package/dist/commands/free.js +0 -1
- package/dist/commands/grep.d.ts +0 -1
- package/dist/commands/grep.js +0 -1
- package/dist/commands/groups.d.ts +0 -1
- package/dist/commands/groups.js +0 -1
- package/dist/commands/gzip.d.ts +0 -1
- package/dist/commands/gzip.js +0 -1
- package/dist/commands/head.d.ts +0 -1
- package/dist/commands/head.js +0 -1
- package/dist/commands/help.d.ts +0 -1
- package/dist/commands/help.js +0 -1
- package/dist/commands/helpers.d.ts +0 -1
- package/dist/commands/helpers.js +0 -1
- package/dist/commands/history.d.ts +0 -1
- package/dist/commands/history.js +0 -1
- package/dist/commands/hostname.d.ts +0 -1
- package/dist/commands/hostname.js +0 -1
- package/dist/commands/htop.d.ts +0 -1
- package/dist/commands/htop.js +0 -1
- package/dist/commands/id.d.ts +0 -1
- package/dist/commands/id.js +0 -1
- package/dist/commands/index.d.ts +0 -1
- package/dist/commands/index.js +0 -1
- package/dist/commands/kill.d.ts +0 -1
- package/dist/commands/kill.js +0 -1
- package/dist/commands/ln.d.ts +0 -1
- package/dist/commands/ln.js +0 -1
- package/dist/commands/ls.d.ts +0 -1
- package/dist/commands/ls.js +0 -1
- package/dist/commands/lsb-release.d.ts +0 -1
- package/dist/commands/lsb-release.js +0 -1
- package/dist/commands/man.d.ts +0 -1
- package/dist/commands/man.js +0 -1
- package/dist/commands/manuals-bundle.d.ts +0 -1
- package/dist/commands/manuals-bundle.js +0 -1
- package/dist/commands/mkdir.d.ts +0 -1
- package/dist/commands/mkdir.js +0 -1
- package/dist/commands/mv.d.ts +0 -1
- package/dist/commands/mv.js +0 -1
- package/dist/commands/nano.d.ts +0 -1
- package/dist/commands/nano.js +0 -1
- package/dist/commands/neofetch.d.ts +0 -1
- package/dist/commands/neofetch.js +0 -1
- package/dist/commands/node.d.ts +0 -1
- package/dist/commands/node.js +0 -1
- package/dist/commands/npm.d.ts +0 -1
- package/dist/commands/npm.js +0 -1
- package/dist/commands/passwd.d.ts +0 -1
- package/dist/commands/passwd.js +0 -1
- package/dist/commands/ping.d.ts +0 -1
- package/dist/commands/ping.js +0 -1
- package/dist/commands/printf.d.ts +0 -1
- package/dist/commands/printf.js +0 -1
- package/dist/commands/ps.d.ts +0 -1
- package/dist/commands/ps.js +0 -1
- package/dist/commands/pwd.d.ts +0 -1
- package/dist/commands/pwd.js +0 -1
- package/dist/commands/python.d.ts +0 -1
- package/dist/commands/python.js +0 -1
- package/dist/commands/read.d.ts +0 -1
- package/dist/commands/read.js +0 -1
- package/dist/commands/registry.d.ts +0 -1
- package/dist/commands/registry.js +0 -1
- package/dist/commands/rm.d.ts +0 -1
- package/dist/commands/rm.js +0 -1
- package/dist/commands/runtime.d.ts +0 -1
- package/dist/commands/runtime.js +139 -107
- package/dist/commands/sed.d.ts +0 -1
- package/dist/commands/sed.js +0 -1
- package/dist/commands/seq.d.ts +0 -1
- package/dist/commands/seq.js +0 -1
- package/dist/commands/set.d.ts +0 -1
- package/dist/commands/set.js +0 -1
- package/dist/commands/sh.d.ts +0 -1
- package/dist/commands/sh.js +0 -1
- package/dist/commands/shift.d.ts +0 -1
- package/dist/commands/shift.js +0 -1
- package/dist/commands/sleep.d.ts +0 -1
- package/dist/commands/sleep.js +0 -1
- package/dist/commands/sort.d.ts +0 -1
- package/dist/commands/sort.js +0 -1
- package/dist/commands/source.d.ts +0 -1
- package/dist/commands/source.js +0 -1
- package/dist/commands/stat.d.ts +0 -1
- package/dist/commands/stat.js +0 -1
- package/dist/commands/su.d.ts +0 -1
- package/dist/commands/su.js +0 -1
- package/dist/commands/sudo.d.ts +0 -1
- package/dist/commands/sudo.js +0 -1
- package/dist/commands/tail.d.ts +0 -1
- package/dist/commands/tail.js +0 -1
- package/dist/commands/tar.d.ts +0 -1
- package/dist/commands/tar.js +0 -1
- package/dist/commands/tee.d.ts +0 -1
- package/dist/commands/tee.js +0 -1
- package/dist/commands/test.d.ts +0 -1
- package/dist/commands/test.js +0 -1
- package/dist/commands/touch.d.ts +0 -1
- package/dist/commands/touch.js +0 -1
- package/dist/commands/tr.d.ts +0 -1
- package/dist/commands/tr.js +0 -1
- package/dist/commands/tree.d.ts +0 -1
- package/dist/commands/tree.js +0 -1
- package/dist/commands/true.d.ts +0 -1
- package/dist/commands/true.js +0 -1
- package/dist/commands/type.d.ts +0 -1
- package/dist/commands/type.js +0 -1
- package/dist/commands/uname.d.ts +0 -1
- package/dist/commands/uname.js +0 -1
- package/dist/commands/uniq.d.ts +0 -1
- package/dist/commands/uniq.js +0 -1
- package/dist/commands/unset.d.ts +0 -1
- package/dist/commands/unset.js +0 -1
- package/dist/commands/uptime.d.ts +0 -1
- package/dist/commands/uptime.js +0 -1
- package/dist/commands/wc.d.ts +0 -1
- package/dist/commands/wc.js +0 -1
- package/dist/commands/wget.d.ts +0 -1
- package/dist/commands/wget.js +0 -1
- package/dist/commands/which.d.ts +0 -1
- package/dist/commands/which.js +0 -1
- package/dist/commands/who.d.ts +0 -1
- package/dist/commands/who.js +0 -1
- package/dist/commands/whoami.d.ts +0 -1
- package/dist/commands/whoami.js +0 -1
- package/dist/commands/xargs.d.ts +0 -1
- package/dist/commands/xargs.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/modules/linuxRootfs.d.ts +0 -1
- package/dist/modules/linuxRootfs.js +0 -1
- package/dist/modules/neofetch.d.ts +0 -1
- package/dist/modules/neofetch.js +0 -1
- package/dist/modules/shellInteractive.d.ts +0 -1
- package/dist/modules/shellInteractive.js +0 -1
- package/dist/modules/shellRuntime.d.ts +0 -1
- package/dist/modules/shellRuntime.js +0 -1
- package/dist/self-standalone.d.ts +0 -1
- package/dist/self-standalone.js +0 -1
- package/dist/standalone-wo-sftp.d.ts +0 -1
- package/dist/standalone-wo-sftp.js +0 -1
- package/dist/standalone.d.ts +0 -1
- package/dist/standalone.js +0 -1
- package/dist/types/commands.d.ts +0 -1
- package/dist/types/commands.js +0 -1
- package/dist/types/pipeline.d.ts +0 -1
- package/dist/types/pipeline.js +0 -1
- package/dist/types/streams.d.ts +0 -1
- package/dist/types/streams.js +0 -1
- package/dist/types/vfs.d.ts +0 -1
- package/dist/types/vfs.js +0 -1
- package/dist/utils/expand.d.ts +0 -1
- package/dist/utils/expand.js +0 -1
- package/dist/utils/perfLogger.d.ts +0 -1
- package/dist/utils/perfLogger.js +0 -1
- package/dist/utils/tokenize.d.ts +0 -1
- package/dist/utils/tokenize.js +0 -1
- package/dist/utils/vfsDiff.d.ts +0 -1
- package/dist/utils/vfsDiff.js +0 -1
- package/docs/app.js +1751 -0
- package/docs/classes/HoneyPot.html +17 -17
- package/docs/classes/IdleManager.html +8 -8
- package/docs/classes/SshClient.html +34 -34
- package/docs/classes/VirtualFileSystem.html +38 -38
- package/docs/classes/VirtualPackageManager.html +19 -19
- package/docs/classes/VirtualSftpServer.html +3 -3
- package/docs/classes/VirtualShell.html +41 -40
- package/docs/classes/VirtualSshServer.html +8 -8
- package/docs/classes/VirtualUserManager.html +32 -32
- package/docs/demo.html +82 -0
- package/docs/functions/assertDiff.html +3 -3
- package/docs/functions/diffSnapshots.html +5 -5
- package/docs/functions/formatDiff.html +3 -3
- package/docs/functions/getArg.html +3 -3
- package/docs/functions/getFlag.html +2 -2
- package/docs/functions/ifFlag.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +41 -19
- package/docs/interfaces/AuditLogEntry.html +3 -3
- package/docs/interfaces/CommandContext.html +13 -13
- package/docs/interfaces/CommandResult.html +13 -13
- package/docs/interfaces/ExecStream.html +6 -6
- package/docs/interfaces/HoneyPotStats.html +3 -3
- package/docs/interfaces/IdleManagerOptions.html +3 -3
- package/docs/interfaces/InstalledPackage.html +11 -11
- package/docs/interfaces/NanoEditorSession.html +5 -5
- package/docs/interfaces/PackageDefinition.html +14 -14
- package/docs/interfaces/PackageFile.html +5 -5
- package/docs/interfaces/PasswordChallenge.html +9 -9
- package/docs/interfaces/RemoveOptions.html +3 -3
- package/docs/interfaces/ShellEnv.html +4 -4
- package/docs/interfaces/ShellModule.html +8 -8
- package/docs/interfaces/ShellProperties.html +5 -5
- package/docs/interfaces/ShellStream.html +7 -7
- package/docs/interfaces/SudoChallenge.html +9 -9
- package/docs/interfaces/VfsBaseNode.html +7 -7
- package/docs/interfaces/VfsDiff.html +7 -7
- package/docs/interfaces/VfsDiffEntry.html +4 -4
- package/docs/interfaces/VfsDiffModified.html +6 -6
- package/docs/interfaces/VfsDirectoryNode.html +8 -8
- package/docs/interfaces/VfsFileNode.html +9 -9
- package/docs/interfaces/VfsOptions.html +6 -6
- package/docs/interfaces/VfsSnapshot.html +3 -3
- package/docs/interfaces/VfsSnapshotBaseNode.html +4 -4
- package/docs/interfaces/VfsSnapshotDirectoryNode.html +5 -5
- package/docs/interfaces/VfsSnapshotFileNode.html +6 -6
- package/docs/interfaces/VirtualActiveSession.html +7 -7
- package/docs/interfaces/VirtualSftpServerOptions.html +3 -3
- package/docs/interfaces/VirtualShellVfsLike.html +4 -4
- package/docs/interfaces/VirtualShellVfsOptions.html +3 -3
- package/docs/interfaces/WriteFileOptions.html +4 -4
- package/docs/modules.html +1 -1
- package/docs/types/ArgParseOptions.html +3 -3
- package/docs/types/CommandMode.html +2 -2
- package/docs/types/CommandOutcome.html +2 -2
- package/docs/types/IdleState.html +1 -1
- package/docs/types/VfsNodeStats.html +2 -2
- package/docs/types/VfsNodeType.html +2 -2
- package/docs/types/VfsPersistenceMode.html +2 -2
- package/docs/types/VfsSnapshotNode.html +2 -2
- package/examples/app.js +1751 -28
- package/examples/app.ts +299 -0
- package/examples/build.js +27 -0
- package/examples/demo.html +33 -0
- package/examples/index.html +68 -13
- package/package.json +3 -2
- package/polyfills/buffer.js +117 -0
- package/polyfills/node_crypto/index.js +167 -7
- package/polyfills/node_fs/index.js +202 -8
- package/polyfills/node_path/index.js +23 -9
- package/polyfills/process.js +14 -0
- package/polyfills/ssh2/index.js +75 -0
- package/scripts/build-all.mjs +77 -49
- package/scripts/build-names.mjs +2 -3
- package/src/VirtualPackageManager/index.ts +4 -15
- package/src/VirtualShell/index.ts +5 -2
- package/src/commands/runtime.ts +44 -1
- package/tsconfig.json +6 -3
- package/typedoc.json +4 -2
- package/builds/fortune-nyx-v1.5.1-web-full.min.js +0 -12
- package/builds/fortune-nyx-v1.5.1-web.min.js +0 -12
- package/dist/Honeypot/index.d.ts.map +0 -1
- package/dist/Honeypot/index.js.map +0 -1
- package/dist/SSHClient/index.d.ts.map +0 -1
- package/dist/SSHClient/index.js.map +0 -1
- package/dist/SSHMimic/exec.d.ts.map +0 -1
- package/dist/SSHMimic/exec.js.map +0 -1
- package/dist/SSHMimic/executor.d.ts.map +0 -1
- package/dist/SSHMimic/executor.js.map +0 -1
- package/dist/SSHMimic/hostKey.d.ts.map +0 -1
- package/dist/SSHMimic/hostKey.js.map +0 -1
- package/dist/SSHMimic/index.d.ts.map +0 -1
- package/dist/SSHMimic/index.js.map +0 -1
- package/dist/SSHMimic/loginBanner.d.ts.map +0 -1
- package/dist/SSHMimic/loginBanner.js.map +0 -1
- package/dist/SSHMimic/loginFormat.d.ts.map +0 -1
- package/dist/SSHMimic/loginFormat.js.map +0 -1
- package/dist/SSHMimic/prompt.d.ts.map +0 -1
- package/dist/SSHMimic/prompt.js.map +0 -1
- package/dist/SSHMimic/sftp.d.ts.map +0 -1
- package/dist/SSHMimic/sftp.js.map +0 -1
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +0 -1
- package/dist/VirtualFileSystem/binaryPack.js.map +0 -1
- package/dist/VirtualFileSystem/index.d.ts.map +0 -1
- package/dist/VirtualFileSystem/index.js.map +0 -1
- package/dist/VirtualFileSystem/internalTypes.d.ts.map +0 -1
- package/dist/VirtualFileSystem/internalTypes.js.map +0 -1
- package/dist/VirtualFileSystem/journal.d.ts.map +0 -1
- package/dist/VirtualFileSystem/journal.js.map +0 -1
- package/dist/VirtualFileSystem/path.d.ts.map +0 -1
- package/dist/VirtualFileSystem/path.js.map +0 -1
- package/dist/VirtualPackageManager/index.d.ts.map +0 -1
- package/dist/VirtualPackageManager/index.js.map +0 -1
- package/dist/VirtualShell/idleManager.d.ts.map +0 -1
- package/dist/VirtualShell/idleManager.js.map +0 -1
- package/dist/VirtualShell/index.d.ts.map +0 -1
- package/dist/VirtualShell/index.js.map +0 -1
- package/dist/VirtualShell/shell.d.ts.map +0 -1
- package/dist/VirtualShell/shell.js.map +0 -1
- package/dist/VirtualShell/shellParser.d.ts.map +0 -1
- package/dist/VirtualShell/shellParser.js.map +0 -1
- package/dist/VirtualUserManager/index.d.ts.map +0 -1
- package/dist/VirtualUserManager/index.js.map +0 -1
- package/dist/commands/adduser.d.ts.map +0 -1
- package/dist/commands/adduser.js.map +0 -1
- package/dist/commands/alias.d.ts.map +0 -1
- package/dist/commands/alias.js.map +0 -1
- package/dist/commands/apt.d.ts.map +0 -1
- package/dist/commands/apt.js.map +0 -1
- package/dist/commands/awk.d.ts.map +0 -1
- package/dist/commands/awk.js.map +0 -1
- package/dist/commands/base64.d.ts.map +0 -1
- package/dist/commands/base64.js.map +0 -1
- package/dist/commands/cat.d.ts.map +0 -1
- package/dist/commands/cat.js.map +0 -1
- package/dist/commands/cd.d.ts.map +0 -1
- package/dist/commands/cd.js.map +0 -1
- package/dist/commands/chmod.d.ts.map +0 -1
- package/dist/commands/chmod.js.map +0 -1
- package/dist/commands/clear.d.ts.map +0 -1
- package/dist/commands/clear.js.map +0 -1
- package/dist/commands/command-helpers.d.ts.map +0 -1
- package/dist/commands/command-helpers.js.map +0 -1
- package/dist/commands/cp.d.ts.map +0 -1
- package/dist/commands/cp.js.map +0 -1
- package/dist/commands/curl.d.ts.map +0 -1
- package/dist/commands/curl.js.map +0 -1
- package/dist/commands/cut.d.ts.map +0 -1
- package/dist/commands/cut.js.map +0 -1
- package/dist/commands/date.d.ts.map +0 -1
- package/dist/commands/date.js.map +0 -1
- package/dist/commands/declare.d.ts.map +0 -1
- package/dist/commands/declare.js.map +0 -1
- package/dist/commands/deluser.d.ts.map +0 -1
- package/dist/commands/deluser.js.map +0 -1
- package/dist/commands/df.d.ts.map +0 -1
- package/dist/commands/df.js.map +0 -1
- package/dist/commands/diff.d.ts.map +0 -1
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/dpkg.d.ts.map +0 -1
- package/dist/commands/dpkg.js.map +0 -1
- package/dist/commands/du.d.ts.map +0 -1
- package/dist/commands/du.js.map +0 -1
- package/dist/commands/echo.d.ts.map +0 -1
- package/dist/commands/echo.js.map +0 -1
- package/dist/commands/env.d.ts.map +0 -1
- package/dist/commands/env.js.map +0 -1
- package/dist/commands/exit.d.ts.map +0 -1
- package/dist/commands/exit.js.map +0 -1
- package/dist/commands/export.d.ts.map +0 -1
- package/dist/commands/export.js.map +0 -1
- package/dist/commands/find.d.ts.map +0 -1
- package/dist/commands/find.js.map +0 -1
- package/dist/commands/free.d.ts.map +0 -1
- package/dist/commands/free.js.map +0 -1
- package/dist/commands/grep.d.ts.map +0 -1
- package/dist/commands/grep.js.map +0 -1
- package/dist/commands/groups.d.ts.map +0 -1
- package/dist/commands/groups.js.map +0 -1
- package/dist/commands/gzip.d.ts.map +0 -1
- package/dist/commands/gzip.js.map +0 -1
- package/dist/commands/head.d.ts.map +0 -1
- package/dist/commands/head.js.map +0 -1
- package/dist/commands/help.d.ts.map +0 -1
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/helpers.d.ts.map +0 -1
- package/dist/commands/helpers.js.map +0 -1
- package/dist/commands/history.d.ts.map +0 -1
- package/dist/commands/history.js.map +0 -1
- package/dist/commands/hostname.d.ts.map +0 -1
- package/dist/commands/hostname.js.map +0 -1
- package/dist/commands/htop.d.ts.map +0 -1
- package/dist/commands/htop.js.map +0 -1
- package/dist/commands/id.d.ts.map +0 -1
- package/dist/commands/id.js.map +0 -1
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/kill.d.ts.map +0 -1
- package/dist/commands/kill.js.map +0 -1
- package/dist/commands/ln.d.ts.map +0 -1
- package/dist/commands/ln.js.map +0 -1
- package/dist/commands/ls.d.ts.map +0 -1
- package/dist/commands/ls.js.map +0 -1
- package/dist/commands/lsb-release.d.ts.map +0 -1
- package/dist/commands/lsb-release.js.map +0 -1
- package/dist/commands/man.d.ts.map +0 -1
- package/dist/commands/man.js.map +0 -1
- package/dist/commands/manuals-bundle.d.ts.map +0 -1
- package/dist/commands/manuals-bundle.js.map +0 -1
- package/dist/commands/mkdir.d.ts.map +0 -1
- package/dist/commands/mkdir.js.map +0 -1
- package/dist/commands/mv.d.ts.map +0 -1
- package/dist/commands/mv.js.map +0 -1
- package/dist/commands/nano.d.ts.map +0 -1
- package/dist/commands/nano.js.map +0 -1
- package/dist/commands/neofetch.d.ts.map +0 -1
- package/dist/commands/neofetch.js.map +0 -1
- package/dist/commands/node.d.ts.map +0 -1
- package/dist/commands/node.js.map +0 -1
- package/dist/commands/npm.d.ts.map +0 -1
- package/dist/commands/npm.js.map +0 -1
- package/dist/commands/passwd.d.ts.map +0 -1
- package/dist/commands/passwd.js.map +0 -1
- package/dist/commands/ping.d.ts.map +0 -1
- package/dist/commands/ping.js.map +0 -1
- package/dist/commands/printf.d.ts.map +0 -1
- package/dist/commands/printf.js.map +0 -1
- package/dist/commands/ps.d.ts.map +0 -1
- package/dist/commands/ps.js.map +0 -1
- package/dist/commands/pwd.d.ts.map +0 -1
- package/dist/commands/pwd.js.map +0 -1
- package/dist/commands/python.d.ts.map +0 -1
- package/dist/commands/python.js.map +0 -1
- package/dist/commands/read.d.ts.map +0 -1
- package/dist/commands/read.js.map +0 -1
- package/dist/commands/registry.d.ts.map +0 -1
- package/dist/commands/registry.js.map +0 -1
- package/dist/commands/rm.d.ts.map +0 -1
- package/dist/commands/rm.js.map +0 -1
- package/dist/commands/runtime.d.ts.map +0 -1
- package/dist/commands/runtime.js.map +0 -1
- package/dist/commands/sed.d.ts.map +0 -1
- package/dist/commands/sed.js.map +0 -1
- package/dist/commands/seq.d.ts.map +0 -1
- package/dist/commands/seq.js.map +0 -1
- package/dist/commands/set.d.ts.map +0 -1
- package/dist/commands/set.js.map +0 -1
- package/dist/commands/sh.d.ts.map +0 -1
- package/dist/commands/sh.js.map +0 -1
- package/dist/commands/shift.d.ts.map +0 -1
- package/dist/commands/shift.js.map +0 -1
- package/dist/commands/sleep.d.ts.map +0 -1
- package/dist/commands/sleep.js.map +0 -1
- package/dist/commands/sort.d.ts.map +0 -1
- package/dist/commands/sort.js.map +0 -1
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/source.js.map +0 -1
- package/dist/commands/stat.d.ts.map +0 -1
- package/dist/commands/stat.js.map +0 -1
- package/dist/commands/su.d.ts.map +0 -1
- package/dist/commands/su.js.map +0 -1
- package/dist/commands/sudo.d.ts.map +0 -1
- package/dist/commands/sudo.js.map +0 -1
- package/dist/commands/tail.d.ts.map +0 -1
- package/dist/commands/tail.js.map +0 -1
- package/dist/commands/tar.d.ts.map +0 -1
- package/dist/commands/tar.js.map +0 -1
- package/dist/commands/tee.d.ts.map +0 -1
- package/dist/commands/tee.js.map +0 -1
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/commands/test.js.map +0 -1
- package/dist/commands/touch.d.ts.map +0 -1
- package/dist/commands/touch.js.map +0 -1
- package/dist/commands/tr.d.ts.map +0 -1
- package/dist/commands/tr.js.map +0 -1
- package/dist/commands/tree.d.ts.map +0 -1
- package/dist/commands/tree.js.map +0 -1
- package/dist/commands/true.d.ts.map +0 -1
- package/dist/commands/true.js.map +0 -1
- package/dist/commands/type.d.ts.map +0 -1
- package/dist/commands/type.js.map +0 -1
- package/dist/commands/uname.d.ts.map +0 -1
- package/dist/commands/uname.js.map +0 -1
- package/dist/commands/uniq.d.ts.map +0 -1
- package/dist/commands/uniq.js.map +0 -1
- package/dist/commands/unset.d.ts.map +0 -1
- package/dist/commands/unset.js.map +0 -1
- package/dist/commands/uptime.d.ts.map +0 -1
- package/dist/commands/uptime.js.map +0 -1
- package/dist/commands/wc.d.ts.map +0 -1
- package/dist/commands/wc.js.map +0 -1
- package/dist/commands/wget.d.ts.map +0 -1
- package/dist/commands/wget.js.map +0 -1
- package/dist/commands/which.d.ts.map +0 -1
- package/dist/commands/which.js.map +0 -1
- package/dist/commands/who.d.ts.map +0 -1
- package/dist/commands/who.js.map +0 -1
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/commands/whoami.js.map +0 -1
- package/dist/commands/xargs.d.ts.map +0 -1
- package/dist/commands/xargs.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/modules/linuxRootfs.d.ts.map +0 -1
- package/dist/modules/linuxRootfs.js.map +0 -1
- package/dist/modules/neofetch.d.ts.map +0 -1
- package/dist/modules/neofetch.js.map +0 -1
- package/dist/modules/shellInteractive.d.ts.map +0 -1
- package/dist/modules/shellInteractive.js.map +0 -1
- package/dist/modules/shellRuntime.d.ts.map +0 -1
- package/dist/modules/shellRuntime.js.map +0 -1
- package/dist/self-standalone.d.ts.map +0 -1
- package/dist/self-standalone.js.map +0 -1
- package/dist/standalone-wo-sftp.d.ts.map +0 -1
- package/dist/standalone-wo-sftp.js.map +0 -1
- package/dist/standalone.d.ts.map +0 -1
- package/dist/standalone.js.map +0 -1
- package/dist/types/commands.d.ts.map +0 -1
- package/dist/types/commands.js.map +0 -1
- package/dist/types/pipeline.d.ts.map +0 -1
- package/dist/types/pipeline.js.map +0 -1
- package/dist/types/streams.d.ts.map +0 -1
- package/dist/types/streams.js.map +0 -1
- package/dist/types/vfs.d.ts.map +0 -1
- package/dist/types/vfs.js.map +0 -1
- package/dist/utils/expand.d.ts.map +0 -1
- package/dist/utils/expand.js.map +0 -1
- package/dist/utils/perfLogger.d.ts.map +0 -1
- package/dist/utils/perfLogger.js.map +0 -1
- package/dist/utils/tokenize.d.ts.map +0 -1
- package/dist/utils/tokenize.js.map +0 -1
- package/dist/utils/vfsDiff.d.ts.map +0 -1
- package/dist/utils/vfsDiff.js.map +0 -1
- package/dist/web-api.d.ts +0 -26
- package/dist/web-api.d.ts.map +0 -1
- package/dist/web-api.js +0 -47
- package/dist/web-api.js.map +0 -1
- package/dist/web-full.d.ts +0 -4
- package/dist/web-full.d.ts.map +0 -1
- package/dist/web-full.js +0 -9
- package/dist/web-full.js.map +0 -1
- package/dist/web.d.ts +0 -108
- package/dist/web.d.ts.map +0 -1
- package/dist/web.js +0 -774
- package/dist/web.js.map +0 -1
- package/examples/app-iife.js +0 -58
- package/examples/index-cf.html +0 -27
- package/examples/web-iife.min.js +0 -13
- package/examples/web.min.js +0 -12
- package/src/web-api.ts +0 -62
- package/src/web-full.ts +0 -11
- package/src/web.ts +0 -930
- package/tests/web.test.ts +0 -182
package/examples/app.ts
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noControlCharactersInRegex: need to parse ANSI */
|
|
2
|
+
import { getCommandNames } from '../src/commands/registry.js';
|
|
3
|
+
import { makeDefaultEnv, runCommand, userHome } from '../src/commands/runtime.js';
|
|
4
|
+
import { VirtualShell } from '../src/index.js';
|
|
5
|
+
import { resolvePath } from '../src/modules/shellRuntime.js';
|
|
6
|
+
import { type LoginBannerState, buildLoginBanner } from '../src/SSHMimic/loginBanner.js';
|
|
7
|
+
import { buildPrompt } from '../src/SSHMimic/prompt.js';
|
|
8
|
+
import type { CommandResult } from '../src/types/commands.js';
|
|
9
|
+
|
|
10
|
+
const HOSTNAME = 'my-vm';
|
|
11
|
+
const MAX_HISTORY = 500;
|
|
12
|
+
|
|
13
|
+
const terminal = document.getElementById('terminal') as HTMLElement;
|
|
14
|
+
const out = document.getElementById('output') as HTMLElement;
|
|
15
|
+
const cmd = document.getElementById('cmd') as HTMLInputElement;
|
|
16
|
+
|
|
17
|
+
function scrollToBottom(): void {
|
|
18
|
+
terminal.scrollTop = terminal.scrollHeight;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
cmd.focus();
|
|
22
|
+
document.addEventListener('click', () => {
|
|
23
|
+
if (!window.getSelection()?.toString()) cmd.focus();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ANSI to HTML
|
|
27
|
+
const FG_COLORS: Record<number, string> = {
|
|
28
|
+
30: '#000', 31: '#c00', 32: '#0c0', 33: '#cc0',
|
|
29
|
+
34: '#00c', 35: '#c0c', 36: '#0cc', 37: '#ccc',
|
|
30
|
+
90: '#555', 91: '#f55', 92: '#5f5', 93: '#ff5',
|
|
31
|
+
94: '#55f', 95: '#f5f', 96: '#5ff', 97: '#fff',
|
|
32
|
+
};
|
|
33
|
+
const BG_COLORS: Record<number, string> = {
|
|
34
|
+
40: '#000', 41: '#c00', 42: '#0c0', 43: '#cc0',
|
|
35
|
+
44: '#00c', 45: '#c0c', 46: '#0cc', 47: '#ccc',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function ansiToHtml(s: string): string {
|
|
39
|
+
let html = '';
|
|
40
|
+
let bold = false, fg = '', bg = '';
|
|
41
|
+
for (const part of s.split(/(\x1b\[[0-9;]*m)/)) {
|
|
42
|
+
const m = part.match(/^\x1b\[([0-9;]*)m$/);
|
|
43
|
+
if (m) {
|
|
44
|
+
for (const code of m[1].split(';').map(Number)) {
|
|
45
|
+
if (code === 0) { bold = false; fg = ''; bg = ''; }
|
|
46
|
+
else if (code === 1) bold = true;
|
|
47
|
+
else if (FG_COLORS[code]) fg = FG_COLORS[code];
|
|
48
|
+
else if (BG_COLORS[code]) bg = BG_COLORS[code];
|
|
49
|
+
}
|
|
50
|
+
} else if (part) {
|
|
51
|
+
const style = [
|
|
52
|
+
fg ? `color:${fg}` : '',
|
|
53
|
+
bg ? `background:${bg}` : '',
|
|
54
|
+
bold ? 'font-weight:bold' : '',
|
|
55
|
+
].filter(Boolean).join(';');
|
|
56
|
+
const escaped = part.replace(/&/g, '&').replace(/</g, '<');
|
|
57
|
+
html += style ? `<span style="${style}">${escaped}</span>` : escaped;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return html;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// All output goes into a single <span> appended to #output.
|
|
64
|
+
// #output is pre-wrap so \n = newline, no extra divs needed.
|
|
65
|
+
function print(s: string): void {
|
|
66
|
+
const span = document.createElement('span');
|
|
67
|
+
span.innerHTML = ansiToHtml(s);
|
|
68
|
+
if (inputLineEl) {
|
|
69
|
+
out.insertBefore(span, inputLineEl);
|
|
70
|
+
} else {
|
|
71
|
+
out.appendChild(span);
|
|
72
|
+
}
|
|
73
|
+
scrollToBottom();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Live input line — sits at bottom of #output as an inline element
|
|
77
|
+
let inputLineEl: HTMLSpanElement | null = null;
|
|
78
|
+
|
|
79
|
+
function printPrompt(): void {
|
|
80
|
+
if (inputLineEl) { inputLineEl.remove(); inputLineEl = null; }
|
|
81
|
+
cmd.value = '';
|
|
82
|
+
|
|
83
|
+
inputLineEl = document.createElement('span');
|
|
84
|
+
inputLineEl.className = 'input-line';
|
|
85
|
+
|
|
86
|
+
const promptSpan = document.createElement('span');
|
|
87
|
+
const cwdLabel = cwd === userHome(authUser) ? '~' : (cwd.split('/').at(-1) || '/');
|
|
88
|
+
promptSpan.innerHTML = ansiToHtml(buildPrompt(authUser, HOSTNAME, cwdLabel));
|
|
89
|
+
|
|
90
|
+
const textSpan = document.createElement('span');
|
|
91
|
+
textSpan.className = 'typed';
|
|
92
|
+
|
|
93
|
+
const cursor = document.createElement('span');
|
|
94
|
+
cursor.className = 'cursor';
|
|
95
|
+
cursor.textContent = '\u00a0';
|
|
96
|
+
|
|
97
|
+
inputLineEl.appendChild(promptSpan);
|
|
98
|
+
inputLineEl.appendChild(textSpan);
|
|
99
|
+
inputLineEl.appendChild(cursor);
|
|
100
|
+
out.appendChild(inputLineEl);
|
|
101
|
+
scrollToBottom();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
cmd.addEventListener('input', () => {
|
|
105
|
+
if (!inputLineEl) return;
|
|
106
|
+
(inputLineEl.querySelector('.typed') as HTMLSpanElement).textContent = cmd.value;
|
|
107
|
+
scrollToBottom();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Wait for IndexedDB fs shim memCache
|
|
111
|
+
// biome-ignore lint/suspicious/noExplicitAny: globalThis shim
|
|
112
|
+
await (globalThis as any).__fsReady__;
|
|
113
|
+
|
|
114
|
+
const shell = new VirtualShell(HOSTNAME, undefined, {
|
|
115
|
+
mode: 'fs',
|
|
116
|
+
snapshotPath: '/vfs-data',
|
|
117
|
+
flushIntervalMs: 10_000,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const vfs = shell.vfs;
|
|
121
|
+
|
|
122
|
+
await vfs.restoreMirror();
|
|
123
|
+
|
|
124
|
+
const isFirstRun = !vfs.exists('/bin');
|
|
125
|
+
if (isFirstRun) {
|
|
126
|
+
await shell.ensureInitialized();
|
|
127
|
+
if (!vfs.exists('/root')) vfs.mkdir('/root', 0o700);
|
|
128
|
+
vfs.writeFile('/root/README.txt', `Welcome to ${HOSTNAME}\n`);
|
|
129
|
+
await vfs.flushMirror();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
window.addEventListener('beforeunload', () => { vfs.flushMirror(); });
|
|
133
|
+
|
|
134
|
+
// Session state
|
|
135
|
+
let authUser = 'root';
|
|
136
|
+
let cwd = userHome(authUser);
|
|
137
|
+
const shellEnv = makeDefaultEnv(authUser, HOSTNAME);
|
|
138
|
+
shellEnv.vars.PWD = cwd;
|
|
139
|
+
|
|
140
|
+
function applyResult(result: CommandResult): void {
|
|
141
|
+
if (result.switchUser) {
|
|
142
|
+
authUser = result.switchUser;
|
|
143
|
+
cwd = result.nextCwd ?? userHome(authUser);
|
|
144
|
+
shellEnv.vars.USER = authUser;
|
|
145
|
+
shellEnv.vars.LOGNAME = authUser;
|
|
146
|
+
shellEnv.vars.HOME = userHome(authUser);
|
|
147
|
+
shellEnv.vars.PWD = cwd;
|
|
148
|
+
} else if (result.nextCwd) {
|
|
149
|
+
cwd = result.nextCwd;
|
|
150
|
+
shellEnv.vars.PWD = cwd;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// History
|
|
155
|
+
function historyPath(): string { return `${userHome(authUser)}/.bash_history`; }
|
|
156
|
+
|
|
157
|
+
function loadHistory(): string[] {
|
|
158
|
+
try {
|
|
159
|
+
if (!vfs.exists(historyPath())) return [];
|
|
160
|
+
return (vfs.readFile(historyPath()) as string)
|
|
161
|
+
.split('\n').map((l: string) => l.trim()).filter((l: string) => l.length > 0);
|
|
162
|
+
} catch { return []; }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function saveHistory(): void {
|
|
166
|
+
vfs.writeFile(historyPath(), history.length > 0 ? `${history.join('\n')}\n` : '');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let history: string[] = loadHistory();
|
|
170
|
+
let historyIdx = -1;
|
|
171
|
+
|
|
172
|
+
// Login banner + lastlog
|
|
173
|
+
function readLastLogin(): LoginBannerState | null {
|
|
174
|
+
try {
|
|
175
|
+
if (!vfs.exists('/root/.lastlog')) return null;
|
|
176
|
+
return JSON.parse(vfs.readFile('/root/.lastlog'));
|
|
177
|
+
} catch { return null; }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function writeLastLogin(): void {
|
|
181
|
+
vfs.writeFile('/root/.lastlog', JSON.stringify({ at: new Date().toISOString(), from: 'browser' }));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
print(buildLoginBanner(HOSTNAME, shell.properties, readLastLogin()));
|
|
185
|
+
writeLastLogin();
|
|
186
|
+
await vfs.flushMirror();
|
|
187
|
+
printPrompt();
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// Tab completion
|
|
191
|
+
function listPathCompletions(prefix: string): string[] {
|
|
192
|
+
const slashIndex = prefix.lastIndexOf('/');
|
|
193
|
+
const dirPart = slashIndex >= 0 ? prefix.slice(0, slashIndex + 1) : '';
|
|
194
|
+
const namePart = slashIndex >= 0 ? prefix.slice(slashIndex + 1) : prefix;
|
|
195
|
+
const basePath = resolvePath(cwd, dirPart || '.');
|
|
196
|
+
try {
|
|
197
|
+
return vfs.list(basePath)
|
|
198
|
+
.filter((e: string) => !e.startsWith('.') && e.startsWith(namePart))
|
|
199
|
+
.map((e: string) => {
|
|
200
|
+
const fullPath = `${basePath}/${e}`.replace(/\/+/g, '/');
|
|
201
|
+
const st = vfs.stat(fullPath);
|
|
202
|
+
return `${dirPart}${e}${st.type === 'directory' ? '/' : ''}`;
|
|
203
|
+
})
|
|
204
|
+
.sort();
|
|
205
|
+
} catch { return []; }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const commandNames = Array.from(new Set(getCommandNames())).sort();
|
|
209
|
+
|
|
210
|
+
function getCompletions(line: string): [string[], string] {
|
|
211
|
+
const token = line.split(/\s+/).at(-1) ?? '';
|
|
212
|
+
const isFirstToken = line.trimStart() === token;
|
|
213
|
+
const cmdHits = isFirstToken ? commandNames.filter(n => n.startsWith(token)) : [];
|
|
214
|
+
const pathHits = listPathCompletions(token);
|
|
215
|
+
const hits = Array.from(new Set([...cmdHits, ...pathHits])).sort();
|
|
216
|
+
return [hits, token];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Input handler
|
|
220
|
+
cmd.addEventListener('keydown', async (e: KeyboardEvent) => {
|
|
221
|
+
if (e.key === 'Tab') {
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
const line = cmd.value;
|
|
224
|
+
const [hits, token] = getCompletions(line);
|
|
225
|
+
if (hits.length === 0) return;
|
|
226
|
+
if (hits.length === 1) {
|
|
227
|
+
// Unique match — complete inline
|
|
228
|
+
cmd.value = line.slice(0, line.length - token.length) + hits[0];
|
|
229
|
+
if (inputLineEl) (inputLineEl.querySelector('.typed') as HTMLSpanElement).textContent = cmd.value;
|
|
230
|
+
} else {
|
|
231
|
+
// Multiple matches — print them below current line, re-prompt
|
|
232
|
+
const prevLine = inputLineEl;
|
|
233
|
+
inputLineEl = null;
|
|
234
|
+
prevLine?.querySelector('.cursor')?.remove();
|
|
235
|
+
out.appendChild(document.createTextNode('\n'));
|
|
236
|
+
print(`${hits.join(' ')}
|
|
237
|
+
`);
|
|
238
|
+
printPrompt();
|
|
239
|
+
cmd.value = line;
|
|
240
|
+
if (inputLineEl) ((inputLineEl as HTMLSpanElement).querySelector('.typed') as HTMLSpanElement).textContent = cmd.value;
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (e.key === 'ArrowUp') {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
if (historyIdx < history.length - 1) {
|
|
248
|
+
historyIdx++;
|
|
249
|
+
cmd.value = history[history.length - 1 - historyIdx];
|
|
250
|
+
if (inputLineEl) (inputLineEl.querySelector('.typed') as HTMLSpanElement).textContent = cmd.value;
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (e.key === 'ArrowDown') {
|
|
256
|
+
e.preventDefault();
|
|
257
|
+
if (historyIdx > 0) { historyIdx--; cmd.value = history[history.length - 1 - historyIdx]; }
|
|
258
|
+
else { historyIdx = -1; cmd.value = ''; }
|
|
259
|
+
if (inputLineEl) (inputLineEl.querySelector('.typed') as HTMLSpanElement).textContent = cmd.value;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (e.key !== 'Enter') return;
|
|
264
|
+
|
|
265
|
+
const value = cmd.value.trim();
|
|
266
|
+
historyIdx = -1;
|
|
267
|
+
|
|
268
|
+
// Freeze input line: remove cursor span, null the ref (keeps prompt+typed in DOM)
|
|
269
|
+
if (inputLineEl) {
|
|
270
|
+
inputLineEl.querySelector('.cursor')?.remove();
|
|
271
|
+
inputLineEl = null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Newline after the frozen line
|
|
275
|
+
out.appendChild(document.createTextNode('\n'));
|
|
276
|
+
|
|
277
|
+
if (value) {
|
|
278
|
+
history.push(value);
|
|
279
|
+
if (history.length > MAX_HISTORY) history = history.slice(history.length - MAX_HISTORY);
|
|
280
|
+
saveHistory();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
const result = await runCommand(value, authUser, HOSTNAME, 'shell', cwd, shell, undefined, shellEnv);
|
|
285
|
+
|
|
286
|
+
if (result.clearScreen) out.innerHTML = '';
|
|
287
|
+
if (result.stdout) print(`${result.stdout.trim()}\n`);
|
|
288
|
+
if (result.stderr) print(`${result.stderr.trim()}\n`);
|
|
289
|
+
|
|
290
|
+
applyResult(result);
|
|
291
|
+
await vfs.flushMirror();
|
|
292
|
+
|
|
293
|
+
if (result.closeSession) { print('\nSession closed.\n'); return; }
|
|
294
|
+
} catch (err) {
|
|
295
|
+
print(`${String(err)}\n`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
printPrompt();
|
|
299
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import esbuild from 'esbuild';
|
|
2
|
+
|
|
3
|
+
const ctx = await esbuild.context({
|
|
4
|
+
entryPoints: ['app.ts'],
|
|
5
|
+
bundle: true,
|
|
6
|
+
format: 'esm',
|
|
7
|
+
outfile: `app.js`,
|
|
8
|
+
platform: 'browser',
|
|
9
|
+
alias: {
|
|
10
|
+
'node:events': '../polyfills/node_events/index.js',
|
|
11
|
+
'node:path': '../polyfills/node_path/index.js',
|
|
12
|
+
'node:os': '../polyfills/node_os/index.js',
|
|
13
|
+
'node:fs': '../polyfills/node_fs/index.js',
|
|
14
|
+
'node:fs/promises': '../polyfills/node_fs/promises.js',
|
|
15
|
+
'node:crypto': '../polyfills/node_crypto/index.js',
|
|
16
|
+
'node:child_process': '../polyfills/node_child_process/index.js',
|
|
17
|
+
'node:zlib': '../polyfills/node_zlib/index.js',
|
|
18
|
+
'node:vm': '../polyfills/node_vm/index.js',
|
|
19
|
+
'ssh2': '../polyfills/ssh2/index.js',
|
|
20
|
+
},
|
|
21
|
+
minify: true,
|
|
22
|
+
treeShaking: true,
|
|
23
|
+
inject: ['../polyfills/process.js', '../polyfills/buffer.js'],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await ctx.watch();
|
|
27
|
+
console.log('watching...');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Virtual Env JS</title>
|
|
7
|
+
<script type="module">
|
|
8
|
+
import { VirtualShell, VirtualFileSystem } from '../builds/fortune-nyx-v1.5.3-web.min.js';
|
|
9
|
+
|
|
10
|
+
const now1 = new Date();
|
|
11
|
+
const ready = await globalThis.__fsReady__;
|
|
12
|
+
window.ready = ready; // Expose for debugging
|
|
13
|
+
const now2 = new Date();
|
|
14
|
+
console.log(`IndexedDB VFS ready in ${now2 - now1}ms`);
|
|
15
|
+
const shell = new VirtualShell('my-vm', undefined, {
|
|
16
|
+
mode: 'fs',
|
|
17
|
+
snapshotPath: '/vfs-data',
|
|
18
|
+
flushIntervalMs: 10_000,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
window.addEventListener('beforeunload', () => {
|
|
22
|
+
shell.vfs.flushMirror();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
window.shell = shell; // Expose shell for debugging
|
|
26
|
+
const result = await shell.executeCommand("ls -l", "root", "/root");
|
|
27
|
+
await shell.vfs.flushMirror()
|
|
28
|
+
console.log(shell.vfs.getMode());
|
|
29
|
+
</script>
|
|
30
|
+
</head>
|
|
31
|
+
<body>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
package/examples/index.html
CHANGED
|
@@ -5,23 +5,78 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
6
|
<title>Virtual Shell — Web Demo</title>
|
|
7
7
|
<style>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
9
|
+
|
|
10
|
+
html, body {
|
|
11
|
+
height: 100%;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
|
|
19
|
+
font-size: 14px;
|
|
20
|
+
line-height: 1.5;
|
|
21
|
+
background: #0b0f14;
|
|
22
|
+
color: #e6eef6;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#terminal {
|
|
26
|
+
flex: 1;
|
|
27
|
+
overflow-y: auto;
|
|
28
|
+
padding: 12px 16px;
|
|
29
|
+
cursor: text;
|
|
30
|
+
user-select: text;
|
|
31
|
+
scrollbar-width: none; /* Firefox */
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#terminal::-webkit-scrollbar {
|
|
35
|
+
display: none; /* Chrome/Safari */
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#output {
|
|
39
|
+
white-space: pre-wrap;
|
|
40
|
+
word-break: break-all;
|
|
41
|
+
user-select: text;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#output span,
|
|
45
|
+
#output .input-line {
|
|
46
|
+
user-select: text;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Hidden input — keystroke sink only */
|
|
50
|
+
#cmd {
|
|
51
|
+
position: fixed;
|
|
52
|
+
left: -9999px;
|
|
53
|
+
opacity: 0;
|
|
54
|
+
width: 1px;
|
|
55
|
+
height: 1px;
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.cursor {
|
|
60
|
+
display: inline-block;
|
|
61
|
+
min-width: 0.6em;
|
|
62
|
+
background: #e6eef6;
|
|
63
|
+
color: #0b0f14;
|
|
64
|
+
animation: blink 1s step-start infinite;
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
user-select: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@keyframes blink {
|
|
70
|
+
0%, 100% { opacity: 1; }
|
|
71
|
+
50% { opacity: 0; }
|
|
72
|
+
}
|
|
15
73
|
</style>
|
|
16
74
|
</head>
|
|
17
75
|
<body>
|
|
18
76
|
<div id="terminal">
|
|
19
|
-
<div id="output"
|
|
20
|
-
<div id="inputRow">
|
|
21
|
-
<div id="prompt">$</div>
|
|
22
|
-
<input id="cmd" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
|
23
|
-
</div>
|
|
77
|
+
<div id="output"></div>
|
|
24
78
|
</div>
|
|
79
|
+
<input id="cmd" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
|
25
80
|
<script type="module" src="./app.js"></script>
|
|
26
81
|
</body>
|
|
27
|
-
</html>
|
|
82
|
+
</html>
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "1.5.
|
|
7
|
+
"version": "1.5.3",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"self-standalone-build": "node scripts/build-all.mjs",
|
|
41
41
|
"standalone-build": "bunx esbuild src/standalone.ts --bundle --platform=node --target=node18 --outfile=builds/standalone.cjs --tree-shaking=true --minify --banner:js='#!/usr/bin/env node'",
|
|
42
42
|
"build-all": "node scripts/build-all.mjs",
|
|
43
|
-
"publish-doc": "bunx typedoc && bunx gh-pages -d docs",
|
|
43
|
+
"publish-doc": "bunx typedoc && bun build-all && bunx gh-pages -d docs && git add docs && git commit -m 'docs: update documentation' && git push",
|
|
44
44
|
"generate-manuals": "node scripts/generate-manuals-bundle.mjs"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@types/bun": "^1.3.14",
|
|
49
49
|
"@types/node": "^25.7.0",
|
|
50
50
|
"@types/ssh2": "^1.15.5",
|
|
51
|
+
"esbuild": "^0.28.0",
|
|
51
52
|
"gh-pages": "^6.3.0",
|
|
52
53
|
"rimraf": "^6.1.3",
|
|
53
54
|
"typescript": "^6.0.3"
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
class BrowserBuffer extends Uint8Array {
|
|
2
|
+
static from(data, encoding) {
|
|
3
|
+
if (typeof data === 'string') {
|
|
4
|
+
const enc = encoding || 'utf8';
|
|
5
|
+
if (enc === 'hex') {
|
|
6
|
+
const arr = new BrowserBuffer(data.length / 2);
|
|
7
|
+
for (let i = 0; i < arr.length; i++)
|
|
8
|
+
arr[i] = parseInt(data.slice(i * 2, i * 2 + 2), 16);
|
|
9
|
+
return arr;
|
|
10
|
+
}
|
|
11
|
+
if (enc === 'base64') {
|
|
12
|
+
const bin = atob(data);
|
|
13
|
+
const arr = new BrowserBuffer(bin.length);
|
|
14
|
+
for (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);
|
|
15
|
+
return arr;
|
|
16
|
+
}
|
|
17
|
+
return new BrowserBuffer(new TextEncoder().encode(data));
|
|
18
|
+
}
|
|
19
|
+
if (data instanceof ArrayBuffer) return new BrowserBuffer(data);
|
|
20
|
+
return new BrowserBuffer(data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static alloc(size, fill = 0) {
|
|
24
|
+
return new BrowserBuffer(size).fill(fill);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static allocUnsafe(size) {
|
|
28
|
+
return new BrowserBuffer(size);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static isBuffer(obj) {
|
|
32
|
+
return obj instanceof BrowserBuffer || obj instanceof Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static concat(bufs, totalLength) {
|
|
36
|
+
const len = totalLength ?? bufs.reduce((s, b) => s + b.length, 0);
|
|
37
|
+
const out = new BrowserBuffer(len);
|
|
38
|
+
let offset = 0;
|
|
39
|
+
for (const b of bufs) { out.set(b, offset); offset += b.length; }
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static byteLength(str, enc = 'utf8') {
|
|
44
|
+
if (enc === 'hex') return str.length / 2;
|
|
45
|
+
if (enc === 'base64') return Math.floor(str.length * 3 / 4);
|
|
46
|
+
return new TextEncoder().encode(str).length;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ── write methods ──────────────────────────────────────────────────────────
|
|
50
|
+
writeUInt8(val, offset = 0) { this[offset] = val & 0xff; return offset + 1; }
|
|
51
|
+
writeInt8(val, offset = 0) { this[offset] = val & 0xff; return offset + 1; }
|
|
52
|
+
|
|
53
|
+
writeUInt16BE(val, offset = 0) { this[offset] = (val >>> 8) & 0xff; this[offset + 1] = val & 0xff; return offset + 2; }
|
|
54
|
+
writeUInt16LE(val, offset = 0) { this[offset] = val & 0xff; this[offset + 1] = (val >>> 8) & 0xff; return offset + 2; }
|
|
55
|
+
writeInt16BE(val, offset = 0) { return this.writeUInt16BE(val, offset); }
|
|
56
|
+
writeInt16LE(val, offset = 0) { return this.writeUInt16LE(val, offset); }
|
|
57
|
+
|
|
58
|
+
writeUInt32BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setUint32(0, val, false); return offset + 4; }
|
|
59
|
+
writeUInt32LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setUint32(0, val, true); return offset + 4; }
|
|
60
|
+
writeInt32BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setInt32(0, val, false); return offset + 4; }
|
|
61
|
+
writeInt32LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setInt32(0, val, true); return offset + 4; }
|
|
62
|
+
|
|
63
|
+
writeBigUInt64BE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setBigUint64(0, BigInt(val), false); return offset + 8; }
|
|
64
|
+
writeBigUInt64LE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setBigUint64(0, BigInt(val), true); return offset + 8; }
|
|
65
|
+
|
|
66
|
+
writeFloatBE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat32(0, val, false); return offset + 4; }
|
|
67
|
+
writeFloatLE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat32(0, val, true); return offset + 4; }
|
|
68
|
+
writeDoubleBE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat64(0, val, false); return offset + 8; }
|
|
69
|
+
writeDoubleLE(val, offset = 0) { new DataView(this.buffer, this.byteOffset + offset).setFloat64(0, val, true); return offset + 8; }
|
|
70
|
+
|
|
71
|
+
// ── read methods ───────────────────────────────────────────────────────────
|
|
72
|
+
readUInt8(offset = 0) { return this[offset]; }
|
|
73
|
+
readInt8(offset = 0) { const v = this[offset]; return v >= 128 ? v - 256 : v; }
|
|
74
|
+
|
|
75
|
+
readUInt16BE(offset = 0) { return (this[offset] << 8) | this[offset + 1]; }
|
|
76
|
+
readUInt16LE(offset = 0) { return this[offset] | (this[offset + 1] << 8); }
|
|
77
|
+
readInt16BE(offset = 0) { const v = this.readUInt16BE(offset); return v >= 0x8000 ? v - 0x10000 : v; }
|
|
78
|
+
readInt16LE(offset = 0) { const v = this.readUInt16LE(offset); return v >= 0x8000 ? v - 0x10000 : v; }
|
|
79
|
+
|
|
80
|
+
readUInt32BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getUint32(0, false); }
|
|
81
|
+
readUInt32LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getUint32(0, true); }
|
|
82
|
+
readInt32BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getInt32(0, false); }
|
|
83
|
+
readInt32LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getInt32(0, true); }
|
|
84
|
+
|
|
85
|
+
readBigUInt64BE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getBigUint64(0, false); }
|
|
86
|
+
readBigUInt64LE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getBigUint64(0, true); }
|
|
87
|
+
|
|
88
|
+
readFloatBE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat32(0, false); }
|
|
89
|
+
readFloatLE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat32(0, true); }
|
|
90
|
+
readDoubleBE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat64(0, false); }
|
|
91
|
+
readDoubleLE(offset = 0) { return new DataView(this.buffer, this.byteOffset + offset).getFloat64(0, true); }
|
|
92
|
+
|
|
93
|
+
// ── misc ───────────────────────────────────────────────────────────────────
|
|
94
|
+
toString(enc = 'utf8', start = 0, end = this.length) {
|
|
95
|
+
const slice = this.subarray(start, end);
|
|
96
|
+
if (enc === 'hex') return Array.from(slice).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
97
|
+
if (enc === 'base64') return btoa(String.fromCharCode(...slice));
|
|
98
|
+
return new TextDecoder(enc === 'utf8' ? 'utf-8' : enc).decode(slice);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.length) {
|
|
102
|
+
target.set(this.subarray(sourceStart, sourceEnd), targetStart);
|
|
103
|
+
}
|
|
104
|
+
equals(other) {
|
|
105
|
+
if (this.length !== other.length) return false;
|
|
106
|
+
for (let i = 0; i < this.length; i++)
|
|
107
|
+
if (this[i] !== other[i]) return false;
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
slice(start, end) { return new BrowserBuffer(super.slice(start, end)); }
|
|
112
|
+
subarray(start, end) { return new BrowserBuffer(super.subarray(start, end)); }
|
|
113
|
+
|
|
114
|
+
get length() { return this.byteLength; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
globalThis.Buffer = BrowserBuffer;
|