typescript-virtual-container 1.2.9 → 1.3.0
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 +0 -1
- package/README.md +141 -50
- package/biome.json +7 -0
- package/dist/SSHMimic/exec.d.ts.map +1 -1
- package/dist/SSHMimic/executor.d.ts.map +1 -1
- package/dist/SSHMimic/executor.js +32 -16
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +20 -6
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
- package/dist/VirtualFileSystem/binaryPack.js +29 -6
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +36 -13
- package/dist/VirtualPackageManager/index.d.ts.map +1 -1
- package/dist/VirtualPackageManager/index.js +192 -43
- package/dist/VirtualShell/index.d.ts +10 -4
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +18 -7
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +3 -1
- package/dist/VirtualShell/shellParser.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/commands/adduser.d.ts +6 -0
- package/dist/commands/adduser.d.ts.map +1 -1
- package/dist/commands/adduser.js +6 -0
- package/dist/commands/alias.d.ts +5 -0
- package/dist/commands/alias.d.ts.map +1 -1
- package/dist/commands/alias.js +5 -0
- package/dist/commands/apt.d.ts +5 -0
- package/dist/commands/apt.d.ts.map +1 -1
- package/dist/commands/apt.js +32 -9
- package/dist/commands/awk.d.ts +11 -0
- package/dist/commands/awk.d.ts.map +1 -1
- package/dist/commands/awk.js +15 -2
- package/dist/commands/base64.d.ts +5 -0
- package/dist/commands/base64.d.ts.map +1 -1
- package/dist/commands/base64.js +9 -1
- package/dist/commands/cat.d.ts +5 -0
- package/dist/commands/cat.d.ts.map +1 -1
- package/dist/commands/cat.js +10 -2
- package/dist/commands/cd.d.ts +5 -0
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +5 -0
- package/dist/commands/chmod.d.ts +5 -0
- package/dist/commands/chmod.d.ts.map +1 -1
- package/dist/commands/chmod.js +5 -0
- package/dist/commands/cp.d.ts +5 -0
- package/dist/commands/cp.d.ts.map +1 -1
- package/dist/commands/cp.js +5 -0
- package/dist/commands/curl.d.ts +5 -0
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +34 -6
- package/dist/commands/cut.d.ts +5 -0
- package/dist/commands/cut.d.ts.map +1 -1
- package/dist/commands/cut.js +8 -1
- package/dist/commands/date.d.ts +5 -0
- package/dist/commands/date.d.ts.map +1 -1
- package/dist/commands/date.js +7 -1
- package/dist/commands/declare.d.ts +3 -0
- package/dist/commands/declare.d.ts.map +1 -0
- package/dist/commands/declare.js +39 -0
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +5 -0
- package/dist/commands/dpkg.d.ts +5 -0
- package/dist/commands/dpkg.d.ts.map +1 -1
- package/dist/commands/dpkg.js +24 -7
- package/dist/commands/du.d.ts.map +1 -1
- package/dist/commands/du.js +8 -2
- package/dist/commands/echo.d.ts +5 -0
- package/dist/commands/echo.d.ts.map +1 -1
- package/dist/commands/echo.js +13 -4
- package/dist/commands/env.d.ts +5 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +11 -1
- package/dist/commands/exit.d.ts +5 -0
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +12 -2
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +3 -1
- package/dist/commands/find.d.ts +5 -0
- package/dist/commands/find.d.ts.map +1 -1
- package/dist/commands/find.js +5 -0
- package/dist/commands/free.d.ts +5 -0
- package/dist/commands/free.d.ts.map +1 -1
- package/dist/commands/free.js +5 -0
- package/dist/commands/grep.d.ts +5 -0
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +12 -2
- package/dist/commands/gzip.d.ts +5 -0
- package/dist/commands/gzip.d.ts.map +1 -1
- package/dist/commands/gzip.js +18 -2
- package/dist/commands/head.d.ts +5 -0
- package/dist/commands/head.d.ts.map +1 -1
- package/dist/commands/head.js +5 -0
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +98 -45
- package/dist/commands/history.d.ts +5 -0
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -0
- package/dist/commands/hostname.d.ts +5 -0
- package/dist/commands/hostname.d.ts.map +1 -1
- package/dist/commands/hostname.js +5 -0
- package/dist/commands/id.d.ts.map +1 -1
- package/dist/commands/id.js +4 -1
- package/dist/commands/index.d.ts +2 -17
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -340
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +3 -1
- package/dist/commands/lsb-release.d.ts.map +1 -1
- package/dist/commands/lsb-release.js +8 -2
- package/dist/commands/nano.js +1 -1
- package/dist/commands/neofetch.js +1 -1
- package/dist/commands/node.d.ts +9 -0
- package/dist/commands/node.d.ts.map +1 -0
- package/dist/commands/node.js +316 -0
- package/dist/commands/npm.d.ts +19 -0
- package/dist/commands/npm.d.ts.map +1 -0
- package/dist/commands/npm.js +109 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +3 -1
- package/dist/commands/printf.d.ts +3 -0
- package/dist/commands/printf.d.ts.map +1 -0
- package/dist/commands/printf.js +113 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +4 -1
- package/dist/commands/python.d.ts +30 -0
- package/dist/commands/python.d.ts.map +1 -0
- package/dist/commands/python.js +2058 -0
- package/dist/commands/read.d.ts +3 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +34 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +229 -0
- package/dist/commands/runtime.d.ts +6 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +280 -0
- package/dist/commands/sed.d.ts.map +1 -1
- package/dist/commands/sed.js +11 -3
- package/dist/commands/set.d.ts.map +1 -1
- package/dist/commands/set.js +9 -3
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +57 -36
- package/dist/commands/shift.d.ts +5 -0
- package/dist/commands/shift.d.ts.map +1 -0
- package/dist/commands/shift.js +52 -0
- package/dist/commands/sleep.d.ts.map +1 -1
- package/dist/commands/sort.d.ts.map +1 -1
- package/dist/commands/sort.js +4 -2
- package/dist/commands/source.d.ts.map +1 -1
- package/dist/commands/source.js +5 -2
- package/dist/commands/sudo.js +1 -1
- package/dist/commands/tar.d.ts.map +1 -1
- package/dist/commands/tar.js +11 -3
- package/dist/commands/tee.d.ts.map +1 -1
- package/dist/commands/tee.js +8 -6
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +46 -24
- package/dist/commands/tr.d.ts.map +1 -1
- package/dist/commands/tr.js +3 -1
- package/dist/commands/true.d.ts +4 -0
- package/dist/commands/true.d.ts.map +1 -0
- package/dist/commands/true.js +14 -0
- package/dist/commands/type.d.ts.map +1 -1
- package/dist/commands/type.js +1 -1
- package/dist/commands/uname.d.ts.map +1 -1
- package/dist/commands/uname.js +4 -1
- package/dist/commands/uniq.d.ts.map +1 -1
- package/dist/commands/uptime.d.ts.map +1 -1
- package/dist/commands/uptime.js +4 -1
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +32 -7
- package/dist/commands/which.d.ts.map +1 -1
- package/dist/commands/xargs.d.ts.map +1 -1
- package/dist/commands/xargs.js +1 -1
- package/dist/index.d.ts +15 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/modules/linuxRootfs.d.ts +18 -1
- package/dist/modules/linuxRootfs.d.ts.map +1 -1
- package/dist/modules/linuxRootfs.js +160 -17
- package/dist/standalone-wo-sftp.d.ts +2 -0
- package/dist/standalone-wo-sftp.d.ts.map +1 -0
- package/dist/standalone-wo-sftp.js +30 -0
- package/dist/utils/expand.d.ts +50 -0
- package/dist/utils/expand.d.ts.map +1 -0
- package/dist/utils/expand.js +183 -0
- package/dist/utils/vfsDiff.d.ts +90 -0
- package/dist/utils/vfsDiff.d.ts.map +1 -0
- package/dist/utils/vfsDiff.js +177 -0
- package/package.json +2 -1
- package/src/SSHMimic/exec.ts +10 -1
- package/src/SSHMimic/executor.ts +104 -18
- package/src/SSHMimic/index.ts +49 -15
- package/src/VirtualFileSystem/binaryPack.ts +35 -8
- package/src/VirtualFileSystem/index.ts +78 -28
- package/src/VirtualPackageManager/index.ts +208 -49
- package/src/VirtualShell/index.ts +35 -7
- package/src/VirtualShell/shell.ts +23 -3
- package/src/VirtualShell/shellParser.ts +134 -36
- package/src/VirtualUserManager/index.ts +7 -2
- package/src/commands/adduser.ts +6 -0
- package/src/commands/alias.ts +5 -1
- package/src/commands/apt.ts +47 -17
- package/src/commands/awk.ts +20 -6
- package/src/commands/base64.ts +13 -2
- package/src/commands/cat.ts +13 -5
- package/src/commands/cd.ts +5 -0
- package/src/commands/chmod.ts +5 -0
- package/src/commands/cp.ts +5 -0
- package/src/commands/curl.ts +56 -12
- package/src/commands/cut.ts +8 -1
- package/src/commands/date.ts +7 -1
- package/src/commands/declare.ts +44 -0
- package/src/commands/diff.ts +17 -3
- package/src/commands/dpkg.ts +33 -11
- package/src/commands/du.ts +17 -5
- package/src/commands/echo.ts +22 -9
- package/src/commands/env.ts +11 -1
- package/src/commands/exit.ts +12 -2
- package/src/commands/export.ts +3 -1
- package/src/commands/find.ts +5 -0
- package/src/commands/free.ts +9 -2
- package/src/commands/grep.ts +12 -2
- package/src/commands/gzip.ts +28 -4
- package/src/commands/head.ts +5 -0
- package/src/commands/help.ts +121 -47
- package/src/commands/history.ts +7 -2
- package/src/commands/hostname.ts +5 -0
- package/src/commands/id.ts +4 -1
- package/src/commands/index.ts +9 -360
- package/src/commands/ls.ts +5 -3
- package/src/commands/lsb-release.ts +8 -2
- package/src/commands/nano.ts +1 -1
- package/src/commands/neofetch.ts +1 -1
- package/src/commands/node.ts +341 -0
- package/src/commands/npm.ts +132 -0
- package/src/commands/ping.ts +6 -2
- package/src/commands/printf.ts +112 -0
- package/src/commands/ps.ts +21 -9
- package/src/commands/python.ts +2229 -0
- package/src/commands/read.ts +41 -0
- package/src/commands/registry.ts +244 -0
- package/src/commands/runtime.ts +353 -0
- package/src/commands/sed.ts +27 -9
- package/src/commands/set.ts +9 -3
- package/src/commands/sh.ts +159 -55
- package/src/commands/shift.ts +53 -0
- package/src/commands/sleep.ts +2 -1
- package/src/commands/sort.ts +10 -6
- package/src/commands/source.ts +15 -3
- package/src/commands/sudo.ts +1 -1
- package/src/commands/tar.ts +28 -7
- package/src/commands/tee.ts +7 -1
- package/src/commands/test.ts +61 -26
- package/src/commands/tr.ts +3 -1
- package/src/commands/true.ts +17 -0
- package/src/commands/type.ts +6 -3
- package/src/commands/uname.ts +5 -1
- package/src/commands/uniq.ts +8 -2
- package/src/commands/uptime.ts +4 -1
- package/src/commands/wget.ts +51 -12
- package/src/commands/which.ts +5 -2
- package/src/commands/xargs.ts +11 -2
- package/src/index.ts +23 -24
- package/src/modules/linuxRootfs.ts +233 -30
- package/src/standalone-wo-sftp.ts +38 -0
- package/src/utils/expand.ts +238 -0
- package/src/utils/vfsDiff.ts +275 -0
- package/standalone-wo-sftp.js +507 -0
- package/standalone-wo-sftp.js.map +7 -0
- package/standalone.js +253 -191
- package/standalone.js.map +4 -4
- package/tests/bun-test-shim.ts +9 -1
- package/tests/command-helpers.test.ts +1 -5
- package/tests/new-features.test.ts +415 -5
- package/tests/parser-executor.test.ts +27 -27
- package/tests/sftp.test.ts +122 -42
- package/tests/users.test.ts +23 -5
- package/CHANGELOG.md +0 -150
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostname.d.ts","sourceRoot":"","sources":["../../src/commands/hostname.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,eAAe,EAAE,WAM7B,CAAC"}
|
|
1
|
+
{"version":3,"file":"hostname.d.ts","sourceRoot":"","sources":["../../src/commands/hostname.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,WAM7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/commands/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/commands/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,SAAS,EAAE,WAgBvB,CAAC"}
|
package/dist/commands/id.js
CHANGED
|
@@ -9,6 +9,9 @@ export const idCommand = {
|
|
|
9
9
|
const gid = uid;
|
|
10
10
|
const isSudo = shell.users.isSudoer(target);
|
|
11
11
|
const groups = isSudo ? `${gid}(${target}),0(root)` : `${gid}(${target})`;
|
|
12
|
-
return {
|
|
12
|
+
return {
|
|
13
|
+
stdout: `uid=${uid}(${target}) gid=${gid}(${target}) groups=${groups}`,
|
|
14
|
+
exitCode: 0,
|
|
15
|
+
};
|
|
13
16
|
},
|
|
14
17
|
};
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare function registerCommand(module: ShellModule): void;
|
|
4
|
-
export declare function createCustomCommand(name: string, params: string[], run: (ctx: CommandContext) => CommandResult | Promise<CommandResult>): ShellModule;
|
|
5
|
-
export declare function getCommandNames(): string[];
|
|
6
|
-
export declare function getCommandModulesPublic(): ShellModule[];
|
|
7
|
-
export declare function resolveModule(name: string): ShellModule | undefined;
|
|
8
|
-
export declare function makeDefaultEnv(authUser: string, hostname: string): ShellEnv;
|
|
9
|
-
/**
|
|
10
|
-
* Execute a pre-parsed command directly by name and argument list.
|
|
11
|
-
*
|
|
12
|
-
* Unlike `runCommand`, this function does NOT re-join name+args into a string
|
|
13
|
-
* and re-parse — so arguments that contain special characters (`;`, `|`, `>`,
|
|
14
|
-
* quotes) are passed through verbatim. Use this from the pipeline executor.
|
|
15
|
-
*/
|
|
16
|
-
export declare function runCommandDirect(name: string, args: string[], authUser: string, hostname: string, mode: CommandMode, cwd: string, shell: VirtualShell, stdin: string | undefined, env: ShellEnv): Promise<CommandResult>;
|
|
17
|
-
export declare function runCommand(rawInput: string, authUser: string, hostname: string, mode: CommandMode, cwd: string, shell: VirtualShell, stdin?: string, env?: ShellEnv): Promise<CommandResult>;
|
|
1
|
+
export { createCustomCommand, getCommandModulesPublic, getCommandNames, registerCommand, resolveModule } from "./registry";
|
|
2
|
+
export { makeDefaultEnv, runCommand, runCommandDirect } from "./runtime";
|
|
18
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,EACf,eAAe,EACf,aAAa,EACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/commands/index.js
CHANGED
|
@@ -1,340 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { parseScript } from "../VirtualShell/shellParser";
|
|
4
|
-
import { adduserCommand } from "./adduser";
|
|
5
|
-
import { aliasCommand, unaliasCommand } from "./alias";
|
|
6
|
-
import { testCommand } from "./test";
|
|
7
|
-
import { sourceCommand } from "./source";
|
|
8
|
-
import { historyCommand } from "./history";
|
|
9
|
-
import { aptCacheCommand, aptCommand } from "./apt";
|
|
10
|
-
import { awkCommand } from "./awk";
|
|
11
|
-
import { base64Command } from "./base64";
|
|
12
|
-
import { catCommand } from "./cat";
|
|
13
|
-
import { cdCommand } from "./cd";
|
|
14
|
-
import { chmodCommand } from "./chmod";
|
|
15
|
-
import { clearCommand } from "./clear";
|
|
16
|
-
import { cpCommand } from "./cp";
|
|
17
|
-
import { curlCommand } from "./curl";
|
|
18
|
-
import { cutCommand } from "./cut";
|
|
19
|
-
import { dateCommand } from "./date";
|
|
20
|
-
import { deluserCommand } from "./deluser";
|
|
21
|
-
import { dfCommand } from "./df";
|
|
22
|
-
import { diffCommand } from "./diff";
|
|
23
|
-
import { dpkgCommand, dpkgQueryCommand } from "./dpkg";
|
|
24
|
-
import { duCommand } from "./du";
|
|
25
|
-
import { echoCommand } from "./echo";
|
|
26
|
-
import { envCommand } from "./env";
|
|
27
|
-
import { exitCommand } from "./exit";
|
|
28
|
-
import { exportCommand } from "./export";
|
|
29
|
-
import { findCommand } from "./find";
|
|
30
|
-
import { freeCommand } from "./free";
|
|
31
|
-
import { grepCommand } from "./grep";
|
|
32
|
-
import { groupsCommand } from "./groups";
|
|
33
|
-
import { gunzipCommand, gzipCommand } from "./gzip";
|
|
34
|
-
import { headCommand } from "./head";
|
|
35
|
-
import { createHelpCommand } from "./help";
|
|
36
|
-
import { hostnameCommand } from "./hostname";
|
|
37
|
-
import { htopCommand } from "./htop";
|
|
38
|
-
import { idCommand } from "./id";
|
|
39
|
-
import { killCommand } from "./kill";
|
|
40
|
-
import { lnCommand } from "./ln";
|
|
41
|
-
import { lsCommand } from "./ls";
|
|
42
|
-
import { lsbReleaseCommand } from "./lsb-release";
|
|
43
|
-
import { manCommand } from "./man";
|
|
44
|
-
import { mkdirCommand } from "./mkdir";
|
|
45
|
-
import { mvCommand } from "./mv";
|
|
46
|
-
import { nanoCommand } from "./nano";
|
|
47
|
-
import { neofetchCommand } from "./neofetch";
|
|
48
|
-
import { passwdCommand } from "./passwd";
|
|
49
|
-
import { pingCommand } from "./ping";
|
|
50
|
-
import { psCommand } from "./ps";
|
|
51
|
-
import { pwdCommand } from "./pwd";
|
|
52
|
-
import { rmCommand } from "./rm";
|
|
53
|
-
import { sedCommand } from "./sed";
|
|
54
|
-
import { setCommand } from "./set";
|
|
55
|
-
import { shCommand } from "./sh";
|
|
56
|
-
import { sleepCommand } from "./sleep";
|
|
57
|
-
import { sortCommand } from "./sort";
|
|
58
|
-
import { suCommand } from "./su";
|
|
59
|
-
import { sudoCommand } from "./sudo";
|
|
60
|
-
import { tailCommand } from "./tail";
|
|
61
|
-
import { tarCommand } from "./tar";
|
|
62
|
-
import { teeCommand } from "./tee";
|
|
63
|
-
import { touchCommand } from "./touch";
|
|
64
|
-
import { trCommand } from "./tr";
|
|
65
|
-
import { treeCommand } from "./tree";
|
|
66
|
-
import { typeCommand } from "./type";
|
|
67
|
-
import { unameCommand } from "./uname";
|
|
68
|
-
import { uniqCommand } from "./uniq";
|
|
69
|
-
import { unsetCommand } from "./unset";
|
|
70
|
-
import { uptimeCommand } from "./uptime";
|
|
71
|
-
import { wcCommand } from "./wc";
|
|
72
|
-
import { wgetCommand } from "./wget";
|
|
73
|
-
import { whichCommand } from "./which";
|
|
74
|
-
import { whoCommand } from "./who";
|
|
75
|
-
import { whoamiCommand } from "./whoami";
|
|
76
|
-
import { xargsCommand } from "./xargs";
|
|
77
|
-
const BASE_COMMANDS = [
|
|
78
|
-
// Navigation
|
|
79
|
-
pwdCommand, cdCommand, lsCommand, treeCommand,
|
|
80
|
-
// Files
|
|
81
|
-
catCommand, touchCommand, rmCommand, mkdirCommand, cpCommand, mvCommand, lnCommand,
|
|
82
|
-
chmodCommand, findCommand,
|
|
83
|
-
// Text processing
|
|
84
|
-
grepCommand, sedCommand, awkCommand, sortCommand, uniqCommand, wcCommand,
|
|
85
|
-
headCommand, tailCommand, cutCommand, trCommand, teeCommand, xargsCommand,
|
|
86
|
-
diffCommand,
|
|
87
|
-
// Archives
|
|
88
|
-
tarCommand, gzipCommand, gunzipCommand, base64Command,
|
|
89
|
-
// System info
|
|
90
|
-
whoamiCommand, whoCommand, hostnameCommand, idCommand, groupsCommand, unameCommand,
|
|
91
|
-
psCommand, killCommand, dfCommand, duCommand, dateCommand, sleepCommand, pingCommand,
|
|
92
|
-
// Shell
|
|
93
|
-
echoCommand, envCommand, exportCommand, setCommand, unsetCommand, shCommand,
|
|
94
|
-
clearCommand, exitCommand,
|
|
95
|
-
// Editors
|
|
96
|
-
nanoCommand, htopCommand,
|
|
97
|
-
// Network
|
|
98
|
-
curlCommand, wgetCommand,
|
|
99
|
-
// Users
|
|
100
|
-
adduserCommand, passwdCommand, deluserCommand, sudoCommand, suCommand,
|
|
101
|
-
// Misc
|
|
102
|
-
neofetchCommand,
|
|
103
|
-
// Package management
|
|
104
|
-
aptCommand, aptCacheCommand, dpkgCommand, dpkgQueryCommand,
|
|
105
|
-
// Shell (extended)
|
|
106
|
-
whichCommand, typeCommand, manCommand, aliasCommand, unaliasCommand,
|
|
107
|
-
testCommand, sourceCommand, historyCommand,
|
|
108
|
-
// System (extended)
|
|
109
|
-
uptimeCommand, freeCommand, lsbReleaseCommand,
|
|
110
|
-
];
|
|
111
|
-
const customCommands = [];
|
|
112
|
-
const commandRegistry = new Map();
|
|
113
|
-
let cachedCommandNames = null;
|
|
114
|
-
const helpCommand = createHelpCommand(() => getCommandModules().map((cmd) => cmd.name));
|
|
115
|
-
function buildCache() {
|
|
116
|
-
commandRegistry.clear();
|
|
117
|
-
for (const mod of getCommandModules()) {
|
|
118
|
-
commandRegistry.set(mod.name, mod);
|
|
119
|
-
for (const alias of mod.aliases ?? [])
|
|
120
|
-
commandRegistry.set(alias, mod);
|
|
121
|
-
}
|
|
122
|
-
cachedCommandNames = Array.from(commandRegistry.keys()).sort();
|
|
123
|
-
}
|
|
124
|
-
function getCommandModules() {
|
|
125
|
-
return [...BASE_COMMANDS, ...customCommands, helpCommand];
|
|
126
|
-
}
|
|
127
|
-
export function registerCommand(module) {
|
|
128
|
-
const normalized = {
|
|
129
|
-
...module,
|
|
130
|
-
name: module.name.trim().toLowerCase(),
|
|
131
|
-
aliases: module.aliases?.map((a) => a.trim().toLowerCase()),
|
|
132
|
-
};
|
|
133
|
-
const names = [normalized.name, ...(normalized.aliases ?? [])];
|
|
134
|
-
if (names.some((n) => n.length === 0 || /\s/.test(n))) {
|
|
135
|
-
throw new Error("Command names must be non-empty and contain no spaces");
|
|
136
|
-
}
|
|
137
|
-
customCommands.push(normalized);
|
|
138
|
-
buildCache();
|
|
139
|
-
}
|
|
140
|
-
export function createCustomCommand(name, params, run) {
|
|
141
|
-
return { name, params, run };
|
|
142
|
-
}
|
|
143
|
-
export function getCommandNames() {
|
|
144
|
-
if (!cachedCommandNames)
|
|
145
|
-
buildCache();
|
|
146
|
-
return cachedCommandNames;
|
|
147
|
-
}
|
|
148
|
-
export function getCommandModulesPublic() {
|
|
149
|
-
return getCommandModules();
|
|
150
|
-
}
|
|
151
|
-
export function resolveModule(name) {
|
|
152
|
-
if (!cachedCommandNames)
|
|
153
|
-
buildCache();
|
|
154
|
-
return commandRegistry.get(name.toLowerCase());
|
|
155
|
-
}
|
|
156
|
-
function splitArgsRespectingQuotes(input) {
|
|
157
|
-
const tokens = [];
|
|
158
|
-
let current = "";
|
|
159
|
-
let inQuotes = false;
|
|
160
|
-
let quoteChar = "";
|
|
161
|
-
for (let i = 0; i < input.length; i++) {
|
|
162
|
-
const ch = input[i] || "";
|
|
163
|
-
const prev = i > 0 ? input[i - 1] : "";
|
|
164
|
-
if ((ch === '"' || ch === "'") && prev !== "\\") {
|
|
165
|
-
if (!inQuotes) {
|
|
166
|
-
inQuotes = true;
|
|
167
|
-
quoteChar = ch;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (ch === quoteChar) {
|
|
171
|
-
inQuotes = false;
|
|
172
|
-
quoteChar = "";
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (/\s/.test(ch) && !inQuotes) {
|
|
177
|
-
if (current.length > 0) {
|
|
178
|
-
tokens.push(current);
|
|
179
|
-
current = "";
|
|
180
|
-
}
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
current += ch;
|
|
184
|
-
}
|
|
185
|
-
if (current.length > 0)
|
|
186
|
-
tokens.push(current);
|
|
187
|
-
return tokens;
|
|
188
|
-
}
|
|
189
|
-
function parseInput(rawInput) {
|
|
190
|
-
const parts = splitArgsRespectingQuotes(rawInput.trim());
|
|
191
|
-
return { commandName: parts[0]?.toLowerCase() ?? "", args: parts.slice(1) };
|
|
192
|
-
}
|
|
193
|
-
export function makeDefaultEnv(authUser, hostname) {
|
|
194
|
-
return {
|
|
195
|
-
vars: {
|
|
196
|
-
PATH: "/usr/local/bin:/usr/bin:/bin",
|
|
197
|
-
HOME: `/home/${authUser}`,
|
|
198
|
-
USER: authUser,
|
|
199
|
-
LOGNAME: authUser,
|
|
200
|
-
SHELL: "/bin/sh",
|
|
201
|
-
TERM: "xterm-256color",
|
|
202
|
-
HOSTNAME: hostname,
|
|
203
|
-
PS1: "\\u@\\h:\\w\\$ ",
|
|
204
|
-
},
|
|
205
|
-
lastExitCode: 0,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Execute a pre-parsed command directly by name and argument list.
|
|
210
|
-
*
|
|
211
|
-
* Unlike `runCommand`, this function does NOT re-join name+args into a string
|
|
212
|
-
* and re-parse — so arguments that contain special characters (`;`, `|`, `>`,
|
|
213
|
-
* quotes) are passed through verbatim. Use this from the pipeline executor.
|
|
214
|
-
*/
|
|
215
|
-
export async function runCommandDirect(name, args, authUser, hostname, mode, cwd, shell, stdin, env) {
|
|
216
|
-
// Alias expansion on the command name
|
|
217
|
-
const aliasVal = env.vars[`__alias_${name}`];
|
|
218
|
-
if (aliasVal) {
|
|
219
|
-
// Alias may expand to a multi-word command — re-route through runCommand
|
|
220
|
-
return runCommand(`${aliasVal} ${args.join(" ")}`, authUser, hostname, mode, cwd, shell, stdin, env);
|
|
221
|
-
}
|
|
222
|
-
const mod = resolveModule(name);
|
|
223
|
-
if (!mod)
|
|
224
|
-
return { stderr: `${name}: command not found`, exitCode: 127 };
|
|
225
|
-
try {
|
|
226
|
-
return await mod.run({
|
|
227
|
-
authUser,
|
|
228
|
-
hostname,
|
|
229
|
-
activeSessions: shell.users.listActiveSessions(),
|
|
230
|
-
rawInput: [name, ...args].join(" "),
|
|
231
|
-
mode,
|
|
232
|
-
args,
|
|
233
|
-
stdin,
|
|
234
|
-
cwd,
|
|
235
|
-
shell,
|
|
236
|
-
env,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
return { stderr: error instanceof Error ? error.message : "Command failed", exitCode: 1 };
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
export async function runCommand(rawInput, authUser, hostname, mode, cwd, shell, stdin, env) {
|
|
244
|
-
const trimmed = rawInput.trim();
|
|
245
|
-
if (trimmed.length === 0)
|
|
246
|
-
return { exitCode: 0 };
|
|
247
|
-
const shellEnv = env ?? makeDefaultEnv(authUser, hostname);
|
|
248
|
-
// ── $(cmd) command substitution ──────────────────────────────────────────
|
|
249
|
-
let expanded = trimmed;
|
|
250
|
-
if (expanded.includes("$(")) {
|
|
251
|
-
// Only substitute $(…) that are NOT inside single quotes
|
|
252
|
-
// Strategy: walk char by char, track single-quote state
|
|
253
|
-
let result = "";
|
|
254
|
-
let inSingle = false;
|
|
255
|
-
let i = 0;
|
|
256
|
-
while (i < expanded.length) {
|
|
257
|
-
const ch = expanded[i];
|
|
258
|
-
if (ch === "'" && !inSingle) {
|
|
259
|
-
inSingle = true;
|
|
260
|
-
result += ch;
|
|
261
|
-
i++;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (ch === "'" && inSingle) {
|
|
265
|
-
inSingle = false;
|
|
266
|
-
result += ch;
|
|
267
|
-
i++;
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
if (!inSingle && ch === "$" && expanded[i + 1] === "(") {
|
|
271
|
-
// Find matching closing )
|
|
272
|
-
let depth = 0;
|
|
273
|
-
let j = i + 1;
|
|
274
|
-
while (j < expanded.length) {
|
|
275
|
-
if (expanded[j] === "(")
|
|
276
|
-
depth++;
|
|
277
|
-
else if (expanded[j] === ")") {
|
|
278
|
-
depth--;
|
|
279
|
-
if (depth === 0)
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
j++;
|
|
283
|
-
}
|
|
284
|
-
const sub = expanded.slice(i + 2, j).trim();
|
|
285
|
-
const subResult = await runCommand(sub, authUser, hostname, mode, cwd, shell, undefined, shellEnv);
|
|
286
|
-
const subOut = (subResult.stdout ?? "").replace(/\n$/, "");
|
|
287
|
-
result += subOut;
|
|
288
|
-
i = j + 1;
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
result += ch;
|
|
292
|
-
i++;
|
|
293
|
-
}
|
|
294
|
-
expanded = result;
|
|
295
|
-
}
|
|
296
|
-
// ── alias expansion ───────────────────────────────────────────────────────
|
|
297
|
-
const firstWord = expanded.split(/\s+/)[0] ?? "";
|
|
298
|
-
const aliasVal = shellEnv.vars[`__alias_${firstWord}`];
|
|
299
|
-
if (aliasVal) {
|
|
300
|
-
expanded = expanded.replace(firstWord, aliasVal);
|
|
301
|
-
}
|
|
302
|
-
// Detect shell operators
|
|
303
|
-
if (/(?<![|&])[|](?![|])/.test(expanded) ||
|
|
304
|
-
expanded.includes(">") ||
|
|
305
|
-
expanded.includes("<") ||
|
|
306
|
-
expanded.includes("&&") ||
|
|
307
|
-
expanded.includes("||") ||
|
|
308
|
-
expanded.includes(";")) {
|
|
309
|
-
const script = parseScript(expanded);
|
|
310
|
-
if (!script.isValid)
|
|
311
|
-
return { stderr: script.error || "Syntax error", exitCode: 1 };
|
|
312
|
-
try {
|
|
313
|
-
return await executeStatements(script.statements, authUser, hostname, mode, cwd, shell, shellEnv);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
return { stderr: error instanceof Error ? error.message : "Execution failed", exitCode: 1 };
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const { commandName, args } = parseInput(expanded);
|
|
320
|
-
const mod = resolveModule(commandName);
|
|
321
|
-
if (!mod)
|
|
322
|
-
return { stderr: `${commandName}: command not found`, exitCode: 127 };
|
|
323
|
-
try {
|
|
324
|
-
return await mod.run({
|
|
325
|
-
authUser,
|
|
326
|
-
hostname,
|
|
327
|
-
activeSessions: shell.users.listActiveSessions(),
|
|
328
|
-
rawInput: expanded,
|
|
329
|
-
mode,
|
|
330
|
-
args,
|
|
331
|
-
stdin,
|
|
332
|
-
cwd,
|
|
333
|
-
shell,
|
|
334
|
-
env: shellEnv,
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
return { stderr: error instanceof Error ? error.message : "Command failed", exitCode: 1 };
|
|
339
|
-
}
|
|
340
|
-
}
|
|
1
|
+
export { createCustomCommand, getCommandModulesPublic, getCommandNames, registerCommand, resolveModule } from "./registry";
|
|
2
|
+
export { makeDefaultEnv, runCommand, runCommandDirect } from "./runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../src/commands/ls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA4BrD,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../src/commands/ls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA4BrD,eAAO,MAAM,SAAS,EAAE,WA4BvB,CAAC"}
|
package/dist/commands/ls.js
CHANGED
|
@@ -29,7 +29,9 @@ export const lsCommand = {
|
|
|
29
29
|
run: ({ authUser, shell, cwd, args }) => {
|
|
30
30
|
const longFormat = ifFlag(args, ["-l", "--long"]);
|
|
31
31
|
const showHidden = ifFlag(args, ["-a", "--all"]);
|
|
32
|
-
const targetArg = getArg(args, 0, {
|
|
32
|
+
const targetArg = getArg(args, 0, {
|
|
33
|
+
flags: ["-l", "--long", "-a", "--all", "-la", "-al"],
|
|
34
|
+
});
|
|
33
35
|
const target = resolvePath(cwd, targetArg ?? cwd);
|
|
34
36
|
assertPathAccess(authUser, target, "ls");
|
|
35
37
|
const items = shell.vfs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lsb-release.d.ts","sourceRoot":"","sources":["../../src/commands/lsb-release.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"lsb-release.d.ts","sourceRoot":"","sources":["../../src/commands/lsb-release.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,iBAAiB,EAAE,WAsD/B,CAAC"}
|
|
@@ -12,11 +12,17 @@ export const lsbReleaseCommand = {
|
|
|
12
12
|
const content = shell.vfs.readFile("/etc/os-release");
|
|
13
13
|
for (const line of content.split("\n")) {
|
|
14
14
|
if (line.startsWith("PRETTY_NAME="))
|
|
15
|
-
osName = line
|
|
15
|
+
osName = line
|
|
16
|
+
.slice("PRETTY_NAME=".length)
|
|
17
|
+
.replace(/^"|"$/g, "")
|
|
18
|
+
.trim();
|
|
16
19
|
if (line.startsWith("VERSION_CODENAME="))
|
|
17
20
|
codename = line.slice("VERSION_CODENAME=".length).trim();
|
|
18
21
|
if (line.startsWith("VERSION_ID="))
|
|
19
|
-
version = line
|
|
22
|
+
version = line
|
|
23
|
+
.slice("VERSION_ID=".length)
|
|
24
|
+
.replace(/^"|"$/g, "")
|
|
25
|
+
.trim();
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
catch { }
|
package/dist/commands/nano.js
CHANGED
|
@@ -3,7 +3,7 @@ import { assertPathAccess, resolvePath } from "./helpers";
|
|
|
3
3
|
export const nanoCommand = {
|
|
4
4
|
name: "nano",
|
|
5
5
|
description: "Text editor",
|
|
6
|
-
category: "
|
|
6
|
+
category: "files",
|
|
7
7
|
params: ["<file>"],
|
|
8
8
|
run: ({ authUser, shell, cwd, args }) => {
|
|
9
9
|
const fileArg = args[0];
|
|
@@ -4,7 +4,7 @@ import { getAllEnvVars } from "./set";
|
|
|
4
4
|
export const neofetchCommand = {
|
|
5
5
|
name: "neofetch",
|
|
6
6
|
description: "System info display",
|
|
7
|
-
category: "
|
|
7
|
+
category: "system",
|
|
8
8
|
params: ["[--off]"],
|
|
9
9
|
run: ({ args, authUser, hostname, shell }) => {
|
|
10
10
|
const env = getAllEnvVars(authUser);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShellModule } from "../types/commands";
|
|
2
|
+
/**
|
|
3
|
+
* `node` virtual runtime command. Executes JS in a safe sandbox with
|
|
4
|
+
* limited globals and no host FS/child process access.
|
|
5
|
+
* @category system
|
|
6
|
+
* @params []
|
|
7
|
+
*/
|
|
8
|
+
export declare const nodeCommand: ShellModule;
|
|
9
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/commands/node.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmPrD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,WAkFzB,CAAC"}
|