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.
Files changed (281) hide show
  1. package/.vscode/settings.json +0 -1
  2. package/README.md +141 -50
  3. package/biome.json +7 -0
  4. package/dist/SSHMimic/exec.d.ts.map +1 -1
  5. package/dist/SSHMimic/executor.d.ts.map +1 -1
  6. package/dist/SSHMimic/executor.js +32 -16
  7. package/dist/SSHMimic/index.d.ts.map +1 -1
  8. package/dist/SSHMimic/index.js +20 -6
  9. package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
  10. package/dist/VirtualFileSystem/binaryPack.js +29 -6
  11. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  12. package/dist/VirtualFileSystem/index.js +36 -13
  13. package/dist/VirtualPackageManager/index.d.ts.map +1 -1
  14. package/dist/VirtualPackageManager/index.js +192 -43
  15. package/dist/VirtualShell/index.d.ts +10 -4
  16. package/dist/VirtualShell/index.d.ts.map +1 -1
  17. package/dist/VirtualShell/index.js +18 -7
  18. package/dist/VirtualShell/shell.d.ts.map +1 -1
  19. package/dist/VirtualShell/shell.js +3 -1
  20. package/dist/VirtualShell/shellParser.d.ts.map +1 -1
  21. package/dist/VirtualUserManager/index.d.ts.map +1 -1
  22. package/dist/commands/adduser.d.ts +6 -0
  23. package/dist/commands/adduser.d.ts.map +1 -1
  24. package/dist/commands/adduser.js +6 -0
  25. package/dist/commands/alias.d.ts +5 -0
  26. package/dist/commands/alias.d.ts.map +1 -1
  27. package/dist/commands/alias.js +5 -0
  28. package/dist/commands/apt.d.ts +5 -0
  29. package/dist/commands/apt.d.ts.map +1 -1
  30. package/dist/commands/apt.js +32 -9
  31. package/dist/commands/awk.d.ts +11 -0
  32. package/dist/commands/awk.d.ts.map +1 -1
  33. package/dist/commands/awk.js +15 -2
  34. package/dist/commands/base64.d.ts +5 -0
  35. package/dist/commands/base64.d.ts.map +1 -1
  36. package/dist/commands/base64.js +9 -1
  37. package/dist/commands/cat.d.ts +5 -0
  38. package/dist/commands/cat.d.ts.map +1 -1
  39. package/dist/commands/cat.js +10 -2
  40. package/dist/commands/cd.d.ts +5 -0
  41. package/dist/commands/cd.d.ts.map +1 -1
  42. package/dist/commands/cd.js +5 -0
  43. package/dist/commands/chmod.d.ts +5 -0
  44. package/dist/commands/chmod.d.ts.map +1 -1
  45. package/dist/commands/chmod.js +5 -0
  46. package/dist/commands/cp.d.ts +5 -0
  47. package/dist/commands/cp.d.ts.map +1 -1
  48. package/dist/commands/cp.js +5 -0
  49. package/dist/commands/curl.d.ts +5 -0
  50. package/dist/commands/curl.d.ts.map +1 -1
  51. package/dist/commands/curl.js +34 -6
  52. package/dist/commands/cut.d.ts +5 -0
  53. package/dist/commands/cut.d.ts.map +1 -1
  54. package/dist/commands/cut.js +8 -1
  55. package/dist/commands/date.d.ts +5 -0
  56. package/dist/commands/date.d.ts.map +1 -1
  57. package/dist/commands/date.js +7 -1
  58. package/dist/commands/declare.d.ts +3 -0
  59. package/dist/commands/declare.d.ts.map +1 -0
  60. package/dist/commands/declare.js +39 -0
  61. package/dist/commands/diff.d.ts +5 -0
  62. package/dist/commands/diff.d.ts.map +1 -1
  63. package/dist/commands/diff.js +5 -0
  64. package/dist/commands/dpkg.d.ts +5 -0
  65. package/dist/commands/dpkg.d.ts.map +1 -1
  66. package/dist/commands/dpkg.js +24 -7
  67. package/dist/commands/du.d.ts.map +1 -1
  68. package/dist/commands/du.js +8 -2
  69. package/dist/commands/echo.d.ts +5 -0
  70. package/dist/commands/echo.d.ts.map +1 -1
  71. package/dist/commands/echo.js +13 -4
  72. package/dist/commands/env.d.ts +5 -0
  73. package/dist/commands/env.d.ts.map +1 -1
  74. package/dist/commands/env.js +11 -1
  75. package/dist/commands/exit.d.ts +5 -0
  76. package/dist/commands/exit.d.ts.map +1 -1
  77. package/dist/commands/exit.js +12 -2
  78. package/dist/commands/export.d.ts.map +1 -1
  79. package/dist/commands/export.js +3 -1
  80. package/dist/commands/find.d.ts +5 -0
  81. package/dist/commands/find.d.ts.map +1 -1
  82. package/dist/commands/find.js +5 -0
  83. package/dist/commands/free.d.ts +5 -0
  84. package/dist/commands/free.d.ts.map +1 -1
  85. package/dist/commands/free.js +5 -0
  86. package/dist/commands/grep.d.ts +5 -0
  87. package/dist/commands/grep.d.ts.map +1 -1
  88. package/dist/commands/grep.js +12 -2
  89. package/dist/commands/gzip.d.ts +5 -0
  90. package/dist/commands/gzip.d.ts.map +1 -1
  91. package/dist/commands/gzip.js +18 -2
  92. package/dist/commands/head.d.ts +5 -0
  93. package/dist/commands/head.d.ts.map +1 -1
  94. package/dist/commands/head.js +5 -0
  95. package/dist/commands/help.d.ts.map +1 -1
  96. package/dist/commands/help.js +98 -45
  97. package/dist/commands/history.d.ts +5 -0
  98. package/dist/commands/history.d.ts.map +1 -1
  99. package/dist/commands/history.js +5 -0
  100. package/dist/commands/hostname.d.ts +5 -0
  101. package/dist/commands/hostname.d.ts.map +1 -1
  102. package/dist/commands/hostname.js +5 -0
  103. package/dist/commands/id.d.ts.map +1 -1
  104. package/dist/commands/id.js +4 -1
  105. package/dist/commands/index.d.ts +2 -17
  106. package/dist/commands/index.d.ts.map +1 -1
  107. package/dist/commands/index.js +2 -340
  108. package/dist/commands/ls.d.ts.map +1 -1
  109. package/dist/commands/ls.js +3 -1
  110. package/dist/commands/lsb-release.d.ts.map +1 -1
  111. package/dist/commands/lsb-release.js +8 -2
  112. package/dist/commands/nano.js +1 -1
  113. package/dist/commands/neofetch.js +1 -1
  114. package/dist/commands/node.d.ts +9 -0
  115. package/dist/commands/node.d.ts.map +1 -0
  116. package/dist/commands/node.js +316 -0
  117. package/dist/commands/npm.d.ts +19 -0
  118. package/dist/commands/npm.d.ts.map +1 -0
  119. package/dist/commands/npm.js +109 -0
  120. package/dist/commands/ping.d.ts.map +1 -1
  121. package/dist/commands/ping.js +3 -1
  122. package/dist/commands/printf.d.ts +3 -0
  123. package/dist/commands/printf.d.ts.map +1 -0
  124. package/dist/commands/printf.js +113 -0
  125. package/dist/commands/ps.d.ts.map +1 -1
  126. package/dist/commands/ps.js +4 -1
  127. package/dist/commands/python.d.ts +30 -0
  128. package/dist/commands/python.d.ts.map +1 -0
  129. package/dist/commands/python.js +2058 -0
  130. package/dist/commands/read.d.ts +3 -0
  131. package/dist/commands/read.d.ts.map +1 -0
  132. package/dist/commands/read.js +34 -0
  133. package/dist/commands/registry.d.ts +8 -0
  134. package/dist/commands/registry.d.ts.map +1 -0
  135. package/dist/commands/registry.js +229 -0
  136. package/dist/commands/runtime.d.ts +6 -0
  137. package/dist/commands/runtime.d.ts.map +1 -0
  138. package/dist/commands/runtime.js +280 -0
  139. package/dist/commands/sed.d.ts.map +1 -1
  140. package/dist/commands/sed.js +11 -3
  141. package/dist/commands/set.d.ts.map +1 -1
  142. package/dist/commands/set.js +9 -3
  143. package/dist/commands/sh.d.ts.map +1 -1
  144. package/dist/commands/sh.js +57 -36
  145. package/dist/commands/shift.d.ts +5 -0
  146. package/dist/commands/shift.d.ts.map +1 -0
  147. package/dist/commands/shift.js +52 -0
  148. package/dist/commands/sleep.d.ts.map +1 -1
  149. package/dist/commands/sort.d.ts.map +1 -1
  150. package/dist/commands/sort.js +4 -2
  151. package/dist/commands/source.d.ts.map +1 -1
  152. package/dist/commands/source.js +5 -2
  153. package/dist/commands/sudo.js +1 -1
  154. package/dist/commands/tar.d.ts.map +1 -1
  155. package/dist/commands/tar.js +11 -3
  156. package/dist/commands/tee.d.ts.map +1 -1
  157. package/dist/commands/tee.js +8 -6
  158. package/dist/commands/test.d.ts.map +1 -1
  159. package/dist/commands/test.js +46 -24
  160. package/dist/commands/tr.d.ts.map +1 -1
  161. package/dist/commands/tr.js +3 -1
  162. package/dist/commands/true.d.ts +4 -0
  163. package/dist/commands/true.d.ts.map +1 -0
  164. package/dist/commands/true.js +14 -0
  165. package/dist/commands/type.d.ts.map +1 -1
  166. package/dist/commands/type.js +1 -1
  167. package/dist/commands/uname.d.ts.map +1 -1
  168. package/dist/commands/uname.js +4 -1
  169. package/dist/commands/uniq.d.ts.map +1 -1
  170. package/dist/commands/uptime.d.ts.map +1 -1
  171. package/dist/commands/uptime.js +4 -1
  172. package/dist/commands/wget.d.ts.map +1 -1
  173. package/dist/commands/wget.js +32 -7
  174. package/dist/commands/which.d.ts.map +1 -1
  175. package/dist/commands/xargs.d.ts.map +1 -1
  176. package/dist/commands/xargs.js +1 -1
  177. package/dist/index.d.ts +15 -14
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +9 -9
  180. package/dist/modules/linuxRootfs.d.ts +18 -1
  181. package/dist/modules/linuxRootfs.d.ts.map +1 -1
  182. package/dist/modules/linuxRootfs.js +160 -17
  183. package/dist/standalone-wo-sftp.d.ts +2 -0
  184. package/dist/standalone-wo-sftp.d.ts.map +1 -0
  185. package/dist/standalone-wo-sftp.js +30 -0
  186. package/dist/utils/expand.d.ts +50 -0
  187. package/dist/utils/expand.d.ts.map +1 -0
  188. package/dist/utils/expand.js +183 -0
  189. package/dist/utils/vfsDiff.d.ts +90 -0
  190. package/dist/utils/vfsDiff.d.ts.map +1 -0
  191. package/dist/utils/vfsDiff.js +177 -0
  192. package/package.json +2 -1
  193. package/src/SSHMimic/exec.ts +10 -1
  194. package/src/SSHMimic/executor.ts +104 -18
  195. package/src/SSHMimic/index.ts +49 -15
  196. package/src/VirtualFileSystem/binaryPack.ts +35 -8
  197. package/src/VirtualFileSystem/index.ts +78 -28
  198. package/src/VirtualPackageManager/index.ts +208 -49
  199. package/src/VirtualShell/index.ts +35 -7
  200. package/src/VirtualShell/shell.ts +23 -3
  201. package/src/VirtualShell/shellParser.ts +134 -36
  202. package/src/VirtualUserManager/index.ts +7 -2
  203. package/src/commands/adduser.ts +6 -0
  204. package/src/commands/alias.ts +5 -1
  205. package/src/commands/apt.ts +47 -17
  206. package/src/commands/awk.ts +20 -6
  207. package/src/commands/base64.ts +13 -2
  208. package/src/commands/cat.ts +13 -5
  209. package/src/commands/cd.ts +5 -0
  210. package/src/commands/chmod.ts +5 -0
  211. package/src/commands/cp.ts +5 -0
  212. package/src/commands/curl.ts +56 -12
  213. package/src/commands/cut.ts +8 -1
  214. package/src/commands/date.ts +7 -1
  215. package/src/commands/declare.ts +44 -0
  216. package/src/commands/diff.ts +17 -3
  217. package/src/commands/dpkg.ts +33 -11
  218. package/src/commands/du.ts +17 -5
  219. package/src/commands/echo.ts +22 -9
  220. package/src/commands/env.ts +11 -1
  221. package/src/commands/exit.ts +12 -2
  222. package/src/commands/export.ts +3 -1
  223. package/src/commands/find.ts +5 -0
  224. package/src/commands/free.ts +9 -2
  225. package/src/commands/grep.ts +12 -2
  226. package/src/commands/gzip.ts +28 -4
  227. package/src/commands/head.ts +5 -0
  228. package/src/commands/help.ts +121 -47
  229. package/src/commands/history.ts +7 -2
  230. package/src/commands/hostname.ts +5 -0
  231. package/src/commands/id.ts +4 -1
  232. package/src/commands/index.ts +9 -360
  233. package/src/commands/ls.ts +5 -3
  234. package/src/commands/lsb-release.ts +8 -2
  235. package/src/commands/nano.ts +1 -1
  236. package/src/commands/neofetch.ts +1 -1
  237. package/src/commands/node.ts +341 -0
  238. package/src/commands/npm.ts +132 -0
  239. package/src/commands/ping.ts +6 -2
  240. package/src/commands/printf.ts +112 -0
  241. package/src/commands/ps.ts +21 -9
  242. package/src/commands/python.ts +2229 -0
  243. package/src/commands/read.ts +41 -0
  244. package/src/commands/registry.ts +244 -0
  245. package/src/commands/runtime.ts +353 -0
  246. package/src/commands/sed.ts +27 -9
  247. package/src/commands/set.ts +9 -3
  248. package/src/commands/sh.ts +159 -55
  249. package/src/commands/shift.ts +53 -0
  250. package/src/commands/sleep.ts +2 -1
  251. package/src/commands/sort.ts +10 -6
  252. package/src/commands/source.ts +15 -3
  253. package/src/commands/sudo.ts +1 -1
  254. package/src/commands/tar.ts +28 -7
  255. package/src/commands/tee.ts +7 -1
  256. package/src/commands/test.ts +61 -26
  257. package/src/commands/tr.ts +3 -1
  258. package/src/commands/true.ts +17 -0
  259. package/src/commands/type.ts +6 -3
  260. package/src/commands/uname.ts +5 -1
  261. package/src/commands/uniq.ts +8 -2
  262. package/src/commands/uptime.ts +4 -1
  263. package/src/commands/wget.ts +51 -12
  264. package/src/commands/which.ts +5 -2
  265. package/src/commands/xargs.ts +11 -2
  266. package/src/index.ts +23 -24
  267. package/src/modules/linuxRootfs.ts +233 -30
  268. package/src/standalone-wo-sftp.ts +38 -0
  269. package/src/utils/expand.ts +238 -0
  270. package/src/utils/vfsDiff.ts +275 -0
  271. package/standalone-wo-sftp.js +507 -0
  272. package/standalone-wo-sftp.js.map +7 -0
  273. package/standalone.js +253 -191
  274. package/standalone.js.map +4 -4
  275. package/tests/bun-test-shim.ts +9 -1
  276. package/tests/command-helpers.test.ts +1 -5
  277. package/tests/new-features.test.ts +415 -5
  278. package/tests/parser-executor.test.ts +27 -27
  279. package/tests/sftp.test.ts +122 -42
  280. package/tests/users.test.ts +23 -5
  281. package/CHANGELOG.md +0 -150
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * Print the configured hostname for the virtual shell.
4
+ * @category system
5
+ * @params []
6
+ */
2
7
  export declare const hostnameCommand: ShellModule;
3
8
  //# sourceMappingURL=hostname.d.ts.map
@@ -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,3 +1,8 @@
1
+ /**
2
+ * Print the configured hostname for the virtual shell.
3
+ * @category system
4
+ * @params []
5
+ */
1
6
  export const hostnameCommand = {
2
7
  name: "hostname",
3
8
  description: "Print hostname",
@@ -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,WAavB,CAAC"}
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"}
@@ -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 { stdout: `uid=${uid}(${target}) gid=${gid}(${target}) groups=${groups}`, exitCode: 0 };
12
+ return {
13
+ stdout: `uid=${uid}(${target}) gid=${gid}(${target}) groups=${groups}`,
14
+ exitCode: 0,
15
+ };
13
16
  },
14
17
  };
@@ -1,18 +1,3 @@
1
- import type { VirtualShell } from "../VirtualShell";
2
- import type { CommandContext, CommandMode, CommandResult, ShellEnv, ShellModule } from "../types/commands";
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":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EACX,cAAc,EACd,WAAW,EACX,aAAa,EACb,QAAQ,EACR,WAAW,EACX,MAAM,mBAAmB,CAAC;AAiI3B,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAYzD;AAED,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,EAChB,GAAG,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,GAClE,WAAW,CAEb;AAED,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAG1C;AAED,wBAAgB,uBAAuB,IAAI,WAAW,EAAE,CAEvD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAGnE;AA8BD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAc3E;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,GAAG,EAAE,QAAQ,GACX,OAAO,CAAC,aAAa,CAAC,CA2BxB;AAED,wBAAsB,UAAU,CAC/B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,QAAQ,GACZ,OAAO,CAAC,aAAa,CAAC,CAqFxB"}
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"}
@@ -1,340 +1,2 @@
1
- /** biome-ignore-all lint/style/useNamingConvention: ENV VARIABLES */
2
- import { executeStatements } from "../SSHMimic/executor";
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,WA0BvB,CAAC"}
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"}
@@ -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, { flags: ["-l", "--long", "-a", "--all", "-la", "-al"] });
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,WAgD/B,CAAC"}
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.slice("PRETTY_NAME=".length).replace(/^"|"$/g, "").trim();
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.slice("VERSION_ID=".length).replace(/^"|"$/g, "").trim();
22
+ version = line
23
+ .slice("VERSION_ID=".length)
24
+ .replace(/^"|"$/g, "")
25
+ .trim();
20
26
  }
21
27
  }
22
28
  catch { }
@@ -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: "shell",
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: "misc",
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"}