typescript-virtual-container 1.2.8 → 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 (307) hide show
  1. package/.vscode/settings.json +0 -1
  2. package/README.md +462 -44
  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 +35 -21
  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 +202 -0
  14. package/dist/VirtualPackageManager/index.d.ts.map +1 -0
  15. package/dist/VirtualPackageManager/index.js +825 -0
  16. package/dist/VirtualShell/index.d.ts +93 -12
  17. package/dist/VirtualShell/index.d.ts.map +1 -1
  18. package/dist/VirtualShell/index.js +95 -13
  19. package/dist/VirtualShell/shell.d.ts.map +1 -1
  20. package/dist/VirtualShell/shell.js +3 -1
  21. package/dist/VirtualShell/shellParser.d.ts.map +1 -1
  22. package/dist/VirtualUserManager/index.d.ts +52 -20
  23. package/dist/VirtualUserManager/index.d.ts.map +1 -1
  24. package/dist/VirtualUserManager/index.js +54 -20
  25. package/dist/commands/adduser.d.ts +6 -0
  26. package/dist/commands/adduser.d.ts.map +1 -1
  27. package/dist/commands/adduser.js +6 -0
  28. package/dist/commands/alias.d.ts +9 -0
  29. package/dist/commands/alias.d.ts.map +1 -0
  30. package/dist/commands/alias.js +63 -0
  31. package/dist/commands/apt.d.ts +9 -0
  32. package/dist/commands/apt.d.ts.map +1 -0
  33. package/dist/commands/apt.js +205 -0
  34. package/dist/commands/awk.d.ts +11 -0
  35. package/dist/commands/awk.d.ts.map +1 -1
  36. package/dist/commands/awk.js +15 -2
  37. package/dist/commands/base64.d.ts +5 -0
  38. package/dist/commands/base64.d.ts.map +1 -1
  39. package/dist/commands/base64.js +9 -1
  40. package/dist/commands/cat.d.ts +5 -0
  41. package/dist/commands/cat.d.ts.map +1 -1
  42. package/dist/commands/cat.js +35 -8
  43. package/dist/commands/cd.d.ts +5 -0
  44. package/dist/commands/cd.d.ts.map +1 -1
  45. package/dist/commands/cd.js +5 -0
  46. package/dist/commands/chmod.d.ts +5 -0
  47. package/dist/commands/chmod.d.ts.map +1 -1
  48. package/dist/commands/chmod.js +57 -3
  49. package/dist/commands/command-helpers.d.ts +78 -4
  50. package/dist/commands/command-helpers.d.ts.map +1 -1
  51. package/dist/commands/command-helpers.js +78 -4
  52. package/dist/commands/cp.d.ts +5 -0
  53. package/dist/commands/cp.d.ts.map +1 -1
  54. package/dist/commands/cp.js +5 -0
  55. package/dist/commands/curl.d.ts +5 -0
  56. package/dist/commands/curl.d.ts.map +1 -1
  57. package/dist/commands/curl.js +106 -26
  58. package/dist/commands/cut.d.ts +5 -0
  59. package/dist/commands/cut.d.ts.map +1 -1
  60. package/dist/commands/cut.js +8 -1
  61. package/dist/commands/date.d.ts +5 -0
  62. package/dist/commands/date.d.ts.map +1 -1
  63. package/dist/commands/date.js +7 -1
  64. package/dist/commands/declare.d.ts +3 -0
  65. package/dist/commands/declare.d.ts.map +1 -0
  66. package/dist/commands/declare.js +39 -0
  67. package/dist/commands/diff.d.ts +5 -0
  68. package/dist/commands/diff.d.ts.map +1 -1
  69. package/dist/commands/diff.js +5 -0
  70. package/dist/commands/dpkg.d.ts +9 -0
  71. package/dist/commands/dpkg.d.ts.map +1 -0
  72. package/dist/commands/dpkg.js +161 -0
  73. package/dist/commands/du.d.ts.map +1 -1
  74. package/dist/commands/du.js +8 -2
  75. package/dist/commands/echo.d.ts +5 -0
  76. package/dist/commands/echo.d.ts.map +1 -1
  77. package/dist/commands/echo.js +33 -12
  78. package/dist/commands/env.d.ts +5 -0
  79. package/dist/commands/env.d.ts.map +1 -1
  80. package/dist/commands/env.js +11 -1
  81. package/dist/commands/exit.d.ts +5 -0
  82. package/dist/commands/exit.d.ts.map +1 -1
  83. package/dist/commands/exit.js +12 -2
  84. package/dist/commands/export.d.ts.map +1 -1
  85. package/dist/commands/export.js +3 -1
  86. package/dist/commands/find.d.ts +5 -0
  87. package/dist/commands/find.d.ts.map +1 -1
  88. package/dist/commands/find.js +5 -0
  89. package/dist/commands/free.d.ts +8 -0
  90. package/dist/commands/free.d.ts.map +1 -0
  91. package/dist/commands/free.js +43 -0
  92. package/dist/commands/grep.d.ts +5 -0
  93. package/dist/commands/grep.d.ts.map +1 -1
  94. package/dist/commands/grep.js +12 -2
  95. package/dist/commands/gzip.d.ts +5 -0
  96. package/dist/commands/gzip.d.ts.map +1 -1
  97. package/dist/commands/gzip.js +18 -2
  98. package/dist/commands/head.d.ts +5 -0
  99. package/dist/commands/head.d.ts.map +1 -1
  100. package/dist/commands/head.js +5 -0
  101. package/dist/commands/help.d.ts.map +1 -1
  102. package/dist/commands/help.js +98 -45
  103. package/dist/commands/helpers.d.ts +3 -0
  104. package/dist/commands/helpers.d.ts.map +1 -1
  105. package/dist/commands/helpers.js +3 -0
  106. package/dist/commands/history.d.ts +8 -0
  107. package/dist/commands/history.d.ts.map +1 -0
  108. package/dist/commands/history.js +26 -0
  109. package/dist/commands/hostname.d.ts +5 -0
  110. package/dist/commands/hostname.d.ts.map +1 -1
  111. package/dist/commands/hostname.js +5 -0
  112. package/dist/commands/id.d.ts.map +1 -1
  113. package/dist/commands/id.js +4 -1
  114. package/dist/commands/index.d.ts +2 -10
  115. package/dist/commands/index.d.ts.map +1 -1
  116. package/dist/commands/index.js +2 -231
  117. package/dist/commands/ls.d.ts.map +1 -1
  118. package/dist/commands/ls.js +6 -3
  119. package/dist/commands/lsb-release.d.ts +3 -0
  120. package/dist/commands/lsb-release.d.ts.map +1 -0
  121. package/dist/commands/lsb-release.js +56 -0
  122. package/dist/commands/man.d.ts +3 -0
  123. package/dist/commands/man.d.ts.map +1 -0
  124. package/dist/commands/man.js +155 -0
  125. package/dist/commands/nano.js +1 -1
  126. package/dist/commands/neofetch.d.ts.map +1 -1
  127. package/dist/commands/neofetch.js +6 -1
  128. package/dist/commands/node.d.ts +9 -0
  129. package/dist/commands/node.d.ts.map +1 -0
  130. package/dist/commands/node.js +316 -0
  131. package/dist/commands/npm.d.ts +19 -0
  132. package/dist/commands/npm.d.ts.map +1 -0
  133. package/dist/commands/npm.js +109 -0
  134. package/dist/commands/ping.d.ts.map +1 -1
  135. package/dist/commands/ping.js +7 -2
  136. package/dist/commands/printf.d.ts +3 -0
  137. package/dist/commands/printf.d.ts.map +1 -0
  138. package/dist/commands/printf.js +113 -0
  139. package/dist/commands/ps.d.ts.map +1 -1
  140. package/dist/commands/ps.js +30 -6
  141. package/dist/commands/python.d.ts +30 -0
  142. package/dist/commands/python.d.ts.map +1 -0
  143. package/dist/commands/python.js +2058 -0
  144. package/dist/commands/read.d.ts +3 -0
  145. package/dist/commands/read.d.ts.map +1 -0
  146. package/dist/commands/read.js +34 -0
  147. package/dist/commands/registry.d.ts +8 -0
  148. package/dist/commands/registry.d.ts.map +1 -0
  149. package/dist/commands/registry.js +229 -0
  150. package/dist/commands/runtime.d.ts +6 -0
  151. package/dist/commands/runtime.d.ts.map +1 -0
  152. package/dist/commands/runtime.js +280 -0
  153. package/dist/commands/sed.d.ts.map +1 -1
  154. package/dist/commands/sed.js +11 -3
  155. package/dist/commands/set.d.ts.map +1 -1
  156. package/dist/commands/set.js +9 -3
  157. package/dist/commands/sh.d.ts.map +1 -1
  158. package/dist/commands/sh.js +69 -30
  159. package/dist/commands/shift.d.ts +5 -0
  160. package/dist/commands/shift.d.ts.map +1 -0
  161. package/dist/commands/shift.js +52 -0
  162. package/dist/commands/sleep.d.ts.map +1 -1
  163. package/dist/commands/sort.d.ts.map +1 -1
  164. package/dist/commands/sort.js +4 -2
  165. package/dist/commands/source.d.ts +3 -0
  166. package/dist/commands/source.d.ts.map +1 -0
  167. package/dist/commands/source.js +34 -0
  168. package/dist/commands/sudo.js +1 -1
  169. package/dist/commands/tar.d.ts.map +1 -1
  170. package/dist/commands/tar.js +11 -3
  171. package/dist/commands/tee.d.ts.map +1 -1
  172. package/dist/commands/tee.js +8 -6
  173. package/dist/commands/test.d.ts +3 -0
  174. package/dist/commands/test.d.ts.map +1 -0
  175. package/dist/commands/test.js +114 -0
  176. package/dist/commands/tr.d.ts.map +1 -1
  177. package/dist/commands/tr.js +3 -1
  178. package/dist/commands/true.d.ts +4 -0
  179. package/dist/commands/true.d.ts.map +1 -0
  180. package/dist/commands/true.js +14 -0
  181. package/dist/commands/type.d.ts +3 -0
  182. package/dist/commands/type.d.ts.map +1 -0
  183. package/dist/commands/type.js +34 -0
  184. package/dist/commands/uname.d.ts.map +1 -1
  185. package/dist/commands/uname.js +4 -1
  186. package/dist/commands/uniq.d.ts.map +1 -1
  187. package/dist/commands/uptime.d.ts +3 -0
  188. package/dist/commands/uptime.d.ts.map +1 -0
  189. package/dist/commands/uptime.js +43 -0
  190. package/dist/commands/wget.d.ts.map +1 -1
  191. package/dist/commands/wget.js +92 -96
  192. package/dist/commands/which.d.ts +3 -0
  193. package/dist/commands/which.d.ts.map +1 -0
  194. package/dist/commands/which.js +32 -0
  195. package/dist/commands/xargs.d.ts.map +1 -1
  196. package/dist/commands/xargs.js +1 -1
  197. package/dist/index.d.ts +15 -11
  198. package/dist/index.d.ts.map +1 -1
  199. package/dist/index.js +9 -8
  200. package/dist/modules/linuxRootfs.d.ts +41 -0
  201. package/dist/modules/linuxRootfs.d.ts.map +1 -0
  202. package/dist/modules/linuxRootfs.js +440 -0
  203. package/dist/modules/neofetch.d.ts.map +1 -1
  204. package/dist/modules/neofetch.js +1 -0
  205. package/dist/standalone-wo-sftp.d.ts +2 -0
  206. package/dist/standalone-wo-sftp.d.ts.map +1 -0
  207. package/dist/standalone-wo-sftp.js +30 -0
  208. package/dist/utils/expand.d.ts +50 -0
  209. package/dist/utils/expand.d.ts.map +1 -0
  210. package/dist/utils/expand.js +183 -0
  211. package/dist/utils/vfsDiff.d.ts +90 -0
  212. package/dist/utils/vfsDiff.d.ts.map +1 -0
  213. package/dist/utils/vfsDiff.js +177 -0
  214. package/package.json +3 -1
  215. package/src/SSHMimic/exec.ts +10 -1
  216. package/src/SSHMimic/executor.ts +105 -21
  217. package/src/SSHMimic/index.ts +49 -15
  218. package/src/VirtualFileSystem/binaryPack.ts +35 -8
  219. package/src/VirtualFileSystem/index.ts +78 -28
  220. package/src/VirtualPackageManager/index.ts +979 -0
  221. package/src/VirtualShell/index.ts +133 -14
  222. package/src/VirtualShell/shell.ts +23 -3
  223. package/src/VirtualShell/shellParser.ts +134 -36
  224. package/src/VirtualUserManager/index.ts +62 -22
  225. package/src/commands/adduser.ts +6 -0
  226. package/src/commands/alias.ts +64 -0
  227. package/src/commands/apt.ts +228 -0
  228. package/src/commands/awk.ts +20 -6
  229. package/src/commands/base64.ts +13 -2
  230. package/src/commands/cat.ts +40 -8
  231. package/src/commands/cd.ts +5 -0
  232. package/src/commands/chmod.ts +53 -3
  233. package/src/commands/command-helpers.ts +78 -4
  234. package/src/commands/cp.ts +5 -0
  235. package/src/commands/curl.ts +118 -33
  236. package/src/commands/cut.ts +8 -1
  237. package/src/commands/date.ts +7 -1
  238. package/src/commands/declare.ts +44 -0
  239. package/src/commands/diff.ts +17 -3
  240. package/src/commands/dpkg.ts +180 -0
  241. package/src/commands/du.ts +17 -5
  242. package/src/commands/echo.ts +41 -12
  243. package/src/commands/env.ts +11 -1
  244. package/src/commands/exit.ts +12 -2
  245. package/src/commands/export.ts +3 -1
  246. package/src/commands/find.ts +5 -0
  247. package/src/commands/free.ts +47 -0
  248. package/src/commands/grep.ts +12 -2
  249. package/src/commands/gzip.ts +28 -4
  250. package/src/commands/head.ts +5 -0
  251. package/src/commands/help.ts +121 -47
  252. package/src/commands/helpers.ts +8 -0
  253. package/src/commands/history.ts +34 -0
  254. package/src/commands/hostname.ts +5 -0
  255. package/src/commands/id.ts +4 -1
  256. package/src/commands/index.ts +9 -255
  257. package/src/commands/ls.ts +6 -3
  258. package/src/commands/lsb-release.ts +58 -0
  259. package/src/commands/man.ts +166 -0
  260. package/src/commands/nano.ts +1 -1
  261. package/src/commands/neofetch.ts +6 -1
  262. package/src/commands/node.ts +341 -0
  263. package/src/commands/npm.ts +132 -0
  264. package/src/commands/ping.ts +10 -3
  265. package/src/commands/printf.ts +112 -0
  266. package/src/commands/ps.ts +40 -6
  267. package/src/commands/python.ts +2229 -0
  268. package/src/commands/read.ts +41 -0
  269. package/src/commands/registry.ts +244 -0
  270. package/src/commands/runtime.ts +353 -0
  271. package/src/commands/sed.ts +27 -9
  272. package/src/commands/set.ts +9 -3
  273. package/src/commands/sh.ts +170 -44
  274. package/src/commands/shift.ts +53 -0
  275. package/src/commands/sleep.ts +2 -1
  276. package/src/commands/sort.ts +10 -6
  277. package/src/commands/source.ts +47 -0
  278. package/src/commands/sudo.ts +1 -1
  279. package/src/commands/tar.ts +28 -7
  280. package/src/commands/tee.ts +7 -1
  281. package/src/commands/test.ts +135 -0
  282. package/src/commands/tr.ts +3 -1
  283. package/src/commands/true.ts +17 -0
  284. package/src/commands/type.ts +43 -0
  285. package/src/commands/uname.ts +5 -1
  286. package/src/commands/uniq.ts +8 -2
  287. package/src/commands/uptime.ts +49 -0
  288. package/src/commands/wget.ts +105 -119
  289. package/src/commands/which.ts +37 -0
  290. package/src/commands/xargs.ts +11 -2
  291. package/src/index.ts +27 -18
  292. package/src/modules/linuxRootfs.ts +642 -0
  293. package/src/modules/neofetch.ts +1 -0
  294. package/src/standalone-wo-sftp.ts +38 -0
  295. package/src/utils/expand.ts +238 -0
  296. package/src/utils/vfsDiff.ts +275 -0
  297. package/standalone-wo-sftp.js +507 -0
  298. package/standalone-wo-sftp.js.map +7 -0
  299. package/standalone.js +486 -109
  300. package/standalone.js.map +4 -4
  301. package/tests/bun-test-shim.ts +9 -1
  302. package/tests/command-helpers.test.ts +1 -5
  303. package/tests/new-features.test.ts +1036 -0
  304. package/tests/parser-executor.test.ts +27 -27
  305. package/tests/sftp.test.ts +122 -42
  306. package/tests/users.test.ts +23 -5
  307. package/CHANGELOG.md +0 -150
@@ -2,14 +2,88 @@ type ArgParseOptions = {
2
2
  flags?: string[];
3
3
  flagsWithValue?: string[];
4
4
  };
5
+ /**
6
+ * Returns `true` when any of the given flags appear in `args`.
7
+ *
8
+ * Matches both standalone tokens (`-s`, `--silent`) and inline forms
9
+ * (`--output=file`). Useful for simple boolean flag checks inside command
10
+ * `run` handlers.
11
+ *
12
+ * @param args Tokenized argument array from `CommandContext.args`.
13
+ * @param flags Single flag string or array of equivalent flag strings.
14
+ * @returns `true` if at least one flag is present, otherwise `false`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * ifFlag(args, "-r") // single flag
19
+ * ifFlag(args, ["-r", "--recursive"]) // aliases
20
+ * ```
21
+ */
5
22
  export declare function ifFlag(args: string[], flags: string | string[]): boolean;
23
+ /**
24
+ * Returns the value associated with a flag, or `true` if the flag is present
25
+ * but has no associated value, or `undefined` if the flag is absent.
26
+ *
27
+ * Handles three forms:
28
+ * - `--output file` → returns `"file"` (next token)
29
+ * - `--output=file` → returns `"file"` (inline `=` form)
30
+ * - `--verbose` → returns `true` (flag with no value)
31
+ *
32
+ * @param args Tokenized argument array from `CommandContext.args`.
33
+ * @param flags Single flag string or array of equivalent flag strings.
34
+ * @returns The flag value string, `true` when valueless, or `undefined`.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const output = getFlag(args, ["-o", "--output"]);
39
+ * if (typeof output === "string") { /* use path *\/ }
40
+ * ```
41
+ */
6
42
  export declare function getFlag(args: string[], flags: string | string[]): string | true | undefined;
43
+ /**
44
+ * Returns the positional argument at the given zero-based index, skipping
45
+ * known flags and their values.
46
+ *
47
+ * Flags declared in `options.flags` are treated as boolean and skipped.
48
+ * Flags declared in `options.flagsWithValue` consume the next token too.
49
+ * Tokens after `--` are always treated as positionals.
50
+ *
51
+ * @param args Tokenized argument array from `CommandContext.args`.
52
+ * @param index Zero-based positional index to retrieve.
53
+ * @param options Optional flag declarations to skip during positional collection.
54
+ * @returns The positional value, or `undefined` if the index is out of range.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // args = ["-r", "src", "dest"]
59
+ * getArg(args, 0, { flags: ["-r"] }) // "src"
60
+ * getArg(args, 1, { flags: ["-r"] }) // "dest"
61
+ * ```
62
+ */
7
63
  export declare function getArg(args: string[], index: number, options?: ArgParseOptions): string | undefined;
8
64
  /**
9
- * Parse arguments into flags, flags with values, and positionals.
10
- * @param args - Array of arguments to parse.
11
- * @param options - Parsing options for flags and flags with values.
12
- * @returns Parsed arguments as { flags, flagsWithValues, positionals }.
65
+ * Parses an argument array into structured flags, flag values, and positionals.
66
+ *
67
+ * - `options.flags` boolean flags (e.g. `["-r", "--recursive"]`); collected
68
+ * into a `Set<string>` and not treated as positionals.
69
+ * - `options.flagsWithValue` — flags that consume the next token or an inline
70
+ * `=value`; collected into a `Map<string, string>`.
71
+ * - All remaining tokens are positionals.
72
+ * - Tokens after `--` are always positionals, regardless of `-` prefix.
73
+ *
74
+ * @param args Tokenized argument array from `CommandContext.args`.
75
+ * @param options Flag declaration lists.
76
+ * @returns `{ flags, flagsWithValues, positionals }`.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const { flags, flagsWithValues, positionals } = parseArgs(args, {
81
+ * flags: ["-r", "--recursive"],
82
+ * flagsWithValue: ["-o", "--output"],
83
+ * });
84
+ * const recursive = flags.has("-r");
85
+ * const output = flagsWithValues.get("-o");
86
+ * ```
13
87
  */
14
88
  export declare function parseArgs(args: string[], options?: {
15
89
  flags?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../src/commands/command-helpers.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AA+EF,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAYxE;AAED,wBAAgB,OAAO,CACtB,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GACtB,MAAM,GAAG,IAAI,GAAG,SAAS,CA0B3B;AAED,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC3B,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAC3D;IACF,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB,CAiDA"}
1
+ {"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../src/commands/command-helpers.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AA+EF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAYxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CACtB,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GACtB,MAAM,GAAG,IAAI,GAAG,SAAS,CA0B3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC3B,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAC3D;IACF,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB,CAiDA"}
@@ -54,6 +54,23 @@ function collectPositionals(args, options = {}) {
54
54
  }
55
55
  return positionals;
56
56
  }
57
+ /**
58
+ * Returns `true` when any of the given flags appear in `args`.
59
+ *
60
+ * Matches both standalone tokens (`-s`, `--silent`) and inline forms
61
+ * (`--output=file`). Useful for simple boolean flag checks inside command
62
+ * `run` handlers.
63
+ *
64
+ * @param args Tokenized argument array from `CommandContext.args`.
65
+ * @param flags Single flag string or array of equivalent flag strings.
66
+ * @returns `true` if at least one flag is present, otherwise `false`.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * ifFlag(args, "-r") // single flag
71
+ * ifFlag(args, ["-r", "--recursive"]) // aliases
72
+ * ```
73
+ */
57
74
  export function ifFlag(args, flags) {
58
75
  const allFlags = toFlagList(flags);
59
76
  for (const arg of args) {
@@ -65,6 +82,25 @@ export function ifFlag(args, flags) {
65
82
  }
66
83
  return false;
67
84
  }
85
+ /**
86
+ * Returns the value associated with a flag, or `true` if the flag is present
87
+ * but has no associated value, or `undefined` if the flag is absent.
88
+ *
89
+ * Handles three forms:
90
+ * - `--output file` → returns `"file"` (next token)
91
+ * - `--output=file` → returns `"file"` (inline `=` form)
92
+ * - `--verbose` → returns `true` (flag with no value)
93
+ *
94
+ * @param args Tokenized argument array from `CommandContext.args`.
95
+ * @param flags Single flag string or array of equivalent flag strings.
96
+ * @returns The flag value string, `true` when valueless, or `undefined`.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const output = getFlag(args, ["-o", "--output"]);
101
+ * if (typeof output === "string") { /* use path *\/ }
102
+ * ```
103
+ */
68
104
  export function getFlag(args, flags) {
69
105
  const allFlags = toFlagList(flags);
70
106
  for (let index = 0; index < args.length; index += 1) {
@@ -86,15 +122,53 @@ export function getFlag(args, flags) {
86
122
  }
87
123
  return undefined;
88
124
  }
125
+ /**
126
+ * Returns the positional argument at the given zero-based index, skipping
127
+ * known flags and their values.
128
+ *
129
+ * Flags declared in `options.flags` are treated as boolean and skipped.
130
+ * Flags declared in `options.flagsWithValue` consume the next token too.
131
+ * Tokens after `--` are always treated as positionals.
132
+ *
133
+ * @param args Tokenized argument array from `CommandContext.args`.
134
+ * @param index Zero-based positional index to retrieve.
135
+ * @param options Optional flag declarations to skip during positional collection.
136
+ * @returns The positional value, or `undefined` if the index is out of range.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * // args = ["-r", "src", "dest"]
141
+ * getArg(args, 0, { flags: ["-r"] }) // "src"
142
+ * getArg(args, 1, { flags: ["-r"] }) // "dest"
143
+ * ```
144
+ */
89
145
  export function getArg(args, index, options = {}) {
90
146
  const positionals = collectPositionals(args, options);
91
147
  return positionals[index];
92
148
  }
93
149
  /**
94
- * Parse arguments into flags, flags with values, and positionals.
95
- * @param args - Array of arguments to parse.
96
- * @param options - Parsing options for flags and flags with values.
97
- * @returns Parsed arguments as { flags, flagsWithValues, positionals }.
150
+ * Parses an argument array into structured flags, flag values, and positionals.
151
+ *
152
+ * - `options.flags` boolean flags (e.g. `["-r", "--recursive"]`); collected
153
+ * into a `Set<string>` and not treated as positionals.
154
+ * - `options.flagsWithValue` — flags that consume the next token or an inline
155
+ * `=value`; collected into a `Map<string, string>`.
156
+ * - All remaining tokens are positionals.
157
+ * - Tokens after `--` are always positionals, regardless of `-` prefix.
158
+ *
159
+ * @param args Tokenized argument array from `CommandContext.args`.
160
+ * @param options Flag declaration lists.
161
+ * @returns `{ flags, flagsWithValues, positionals }`.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * const { flags, flagsWithValues, positionals } = parseArgs(args, {
166
+ * flags: ["-r", "--recursive"],
167
+ * flagsWithValue: ["-o", "--output"],
168
+ * });
169
+ * const recursive = flags.has("-r");
170
+ * const output = flagsWithValues.get("-o");
171
+ * ```
98
172
  */
99
173
  export function parseArgs(args, options = {}) {
100
174
  const flags = new Set();
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * Copy files or directories inside the virtual filesystem.
4
+ * @category files
5
+ * @params ["[-r] <source> <dest>"]
6
+ */
2
7
  export declare const cpCommand: ShellModule;
3
8
  //# sourceMappingURL=cp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cp.d.ts","sourceRoot":"","sources":["../../src/commands/cp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,SAAS,EAAE,WAyEvB,CAAC"}
1
+ {"version":3,"file":"cp.d.ts","sourceRoot":"","sources":["../../src/commands/cp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,WAyEvB,CAAC"}
@@ -1,5 +1,10 @@
1
1
  import { ifFlag } from "./command-helpers";
2
2
  import { assertPathAccess, resolvePath } from "./helpers";
3
+ /**
4
+ * Copy files or directories inside the virtual filesystem.
5
+ * @category files
6
+ * @params ["[-r] <source> <dest>"]
7
+ */
3
8
  export const cpCommand = {
4
9
  name: "cp",
5
10
  description: "Copy files or directories",
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * HTTP client wrapper using `fetch()` semantics (virtual curl).
4
+ * @category network
5
+ * @params ["[options] <url>"]
6
+ */
2
7
  export declare const curlCommand: ShellModule;
3
8
  //# sourceMappingURL=curl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/commands/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrD,eAAO,MAAM,WAAW,EAAE,WAmDzB,CAAC"}
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/commands/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WAwIzB,CAAC"}
@@ -1,46 +1,126 @@
1
- import { parseArgs } from "./command-helpers";
2
- import { assertPathAccess, normalizeTerminalOutput, resolvePath, runHostCommand, } from "./helpers";
1
+ import { ifFlag, parseArgs } from "./command-helpers";
2
+ import { assertPathAccess, resolvePath } from "./helpers";
3
+ /**
4
+ * HTTP client wrapper using `fetch()` semantics (virtual curl).
5
+ * @category network
6
+ * @params ["[options] <url>"]
7
+ */
3
8
  export const curlCommand = {
4
9
  name: "curl",
5
- description: "HTTP client",
10
+ description: "Transfer data from or to a server (pure fetch)",
6
11
  category: "network",
7
- params: ["[-o file] <url>"],
12
+ params: ["[options] <url>"],
8
13
  run: async ({ authUser, cwd, args, shell }) => {
9
14
  const { flagsWithValues, positionals } = parseArgs(args, {
10
- flagsWithValue: ["-o", "--output"],
15
+ flagsWithValue: [
16
+ "-o",
17
+ "--output",
18
+ "-X",
19
+ "--request",
20
+ "-d",
21
+ "--data",
22
+ "-H",
23
+ "--header",
24
+ "-u",
25
+ "--user",
26
+ ],
11
27
  });
12
- const outputPath = flagsWithValues.get("-o") || flagsWithValues.get("--output") || null;
28
+ if (ifFlag(args, ["--help", "-h"])) {
29
+ return {
30
+ stdout: [
31
+ "Usage: curl [options] <url>",
32
+ " -o, --output <file> Write to file",
33
+ " -X, --request <method> HTTP method",
34
+ " -d, --data <data> POST data",
35
+ " -H, --header <hdr> Extra header",
36
+ " -s, --silent Silent mode",
37
+ " -I, --head Fetch headers only",
38
+ " -L, --location Follow redirects",
39
+ " -v, --verbose Verbose",
40
+ ].join("\n"),
41
+ exitCode: 0,
42
+ };
43
+ }
13
44
  const url = positionals[0];
14
- if (!url) {
15
- return { stderr: "curl: missing URL", exitCode: 1 };
16
- }
17
- const passthroughArgs = outputPath
18
- ? [...positionals, "-o", "-"]
19
- : positionals;
20
- const result = await runHostCommand("curl", passthroughArgs);
21
- if (result.exitCode !== 0) {
45
+ if (!url)
46
+ return { stderr: "curl: no URL specified", exitCode: 1 };
47
+ const outputPath = flagsWithValues.get("-o") ?? flagsWithValues.get("--output") ?? null;
48
+ const method = (flagsWithValues.get("-X") ??
49
+ flagsWithValues.get("--request") ??
50
+ "GET").toUpperCase();
51
+ const postData = flagsWithValues.get("-d") ?? flagsWithValues.get("--data") ?? null;
52
+ const headerRaw = flagsWithValues.get("-H") ?? flagsWithValues.get("--header") ?? null;
53
+ const silent = ifFlag(args, ["-s", "--silent"]);
54
+ const headOnly = ifFlag(args, ["-I", "--head"]);
55
+ const followRedirects = ifFlag(args, ["-L", "--location"]);
56
+ const verbose = ifFlag(args, ["-v", "--verbose"]);
57
+ const extraHeaders = {
58
+ "User-Agent": "curl/7.88.1",
59
+ };
60
+ if (headerRaw) {
61
+ const idx = headerRaw.indexOf(":");
62
+ if (idx !== -1)
63
+ extraHeaders[headerRaw.slice(0, idx).trim()] = headerRaw
64
+ .slice(idx + 1)
65
+ .trim();
66
+ }
67
+ const finalMethod = postData && method === "GET" ? "POST" : method;
68
+ const fetchOpts = {
69
+ method: finalMethod,
70
+ headers: extraHeaders,
71
+ redirect: followRedirects ? "follow" : "manual",
72
+ };
73
+ if (postData) {
74
+ extraHeaders["Content-Type"] ??= "application/x-www-form-urlencoded";
75
+ fetchOpts.body = postData;
76
+ }
77
+ const stderrLines = [];
78
+ if (verbose) {
79
+ stderrLines.push(`* Trying ${url}...`, `* Connected`);
80
+ stderrLines.push(`> ${finalMethod} / HTTP/1.1`, `> Host: ${new URL(url).host}`);
81
+ }
82
+ let response;
83
+ try {
84
+ response = await fetch(url, fetchOpts);
85
+ }
86
+ catch (err) {
87
+ const msg = err instanceof Error ? err.message : String(err);
22
88
  return {
23
- stderr: normalizeTerminalOutput(result.stderr || `curl: exited with code ${result.exitCode}`),
24
- exitCode: result.exitCode,
89
+ stderr: `curl: (6) Could not resolve host: ${msg}`,
90
+ exitCode: 6,
25
91
  };
26
92
  }
93
+ if (verbose) {
94
+ stderrLines.push(`< HTTP/1.1 ${response.status} ${response.statusText}`);
95
+ }
96
+ if (headOnly) {
97
+ const lines = [`HTTP/1.1 ${response.status} ${response.statusText}`];
98
+ for (const [k, v] of response.headers.entries())
99
+ lines.push(`${k}: ${v}`);
100
+ return { stdout: `${lines.join("\r\n")}\r\n`, exitCode: 0 };
101
+ }
102
+ let body;
103
+ try {
104
+ body = await response.text();
105
+ }
106
+ catch {
107
+ return { stderr: "curl: failed to read response body", exitCode: 1 };
108
+ }
27
109
  if (outputPath) {
28
110
  const target = resolvePath(cwd, outputPath);
29
111
  assertPathAccess(authUser, target, "curl");
30
- shell.writeFileAsUser(authUser, target, result.stdout);
112
+ shell.writeFileAsUser(authUser, target, body);
113
+ if (!silent)
114
+ stderrLines.push(` % Total % Received\n100 ${body.length} 100 ${body.length}`);
31
115
  return {
32
- stderr: result.stderr
33
- ? normalizeTerminalOutput(result.stderr)
34
- : undefined,
35
- exitCode: 0,
116
+ stderr: stderrLines.join("\n") || undefined,
117
+ exitCode: response.ok ? 0 : 22,
36
118
  };
37
119
  }
38
120
  return {
39
- stdout: result.stdout,
40
- stderr: result.stderr
41
- ? normalizeTerminalOutput(result.stderr)
42
- : undefined,
43
- exitCode: 0,
121
+ stdout: body,
122
+ stderr: stderrLines.length > 0 ? stderrLines.join("\n") : undefined,
123
+ exitCode: response.ok ? 0 : 22,
44
124
  };
45
125
  },
46
126
  };
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * Extract selected fields from each line of input.
4
+ * @category text
5
+ * @params ["-d <delim> -f <fields> [file]"]
6
+ */
2
7
  export declare const cutCommand: ShellModule;
3
8
  //# sourceMappingURL=cut.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cut.d.ts","sourceRoot":"","sources":["../../src/commands/cut.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,UAAU,EAAE,WAyBxB,CAAC"}
1
+ {"version":3,"file":"cut.d.ts","sourceRoot":"","sources":["../../src/commands/cut.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,WA2BxB,CAAC"}
@@ -1,4 +1,9 @@
1
1
  import { getFlag } from "./command-helpers";
2
+ /**
3
+ * Extract selected fields from each line of input.
4
+ * @category text
5
+ * @params ["-d <delim> -f <fields> [file]"]
6
+ */
2
7
  export const cutCommand = {
3
8
  name: "cut",
4
9
  description: "Remove sections from lines",
@@ -9,7 +14,9 @@ export const cutCommand = {
9
14
  const fields = getFlag(args, ["-f"]) ?? "1";
10
15
  const cols = fields.split(",").map((f) => {
11
16
  const [a, b] = f.split("-").map(Number);
12
- return b !== undefined ? { from: (a ?? 1) - 1, to: b - 1 } : { from: (a ?? 1) - 1, to: (a ?? 1) - 1 };
17
+ return b !== undefined
18
+ ? { from: (a ?? 1) - 1, to: b - 1 }
19
+ : { from: (a ?? 1) - 1, to: (a ?? 1) - 1 };
13
20
  });
14
21
  const lines = (stdin ?? "").split("\n");
15
22
  const out = lines.map((line) => {
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * Print the current date/time or a formatted representation.
4
+ * @category system
5
+ * @params ["[+format]"]
6
+ */
2
7
  export declare const dateCommand: ShellModule;
3
8
  //# sourceMappingURL=date.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/commands/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,WAAW,EAAE,WAqBzB,CAAC"}
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/commands/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WAsBzB,CAAC"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Print the current date/time or a formatted representation.
3
+ * @category system
4
+ * @params ["[+format]"]
5
+ */
1
6
  export const dateCommand = {
2
7
  name: "date",
3
8
  description: "Print current date and time",
@@ -7,7 +12,8 @@ export const dateCommand = {
7
12
  const now = new Date();
8
13
  const fmt = args[0];
9
14
  if (fmt?.startsWith("+")) {
10
- const f = fmt.slice(1)
15
+ const f = fmt
16
+ .slice(1)
11
17
  .replace("%Y", String(now.getFullYear()))
12
18
  .replace("%m", String(now.getMonth() + 1).padStart(2, "0"))
13
19
  .replace("%d", String(now.getDate()).padStart(2, "0"))
@@ -0,0 +1,3 @@
1
+ import type { ShellModule } from "../types/commands";
2
+ export declare const declareCommand: ShellModule;
3
+ //# sourceMappingURL=declare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declare.d.ts","sourceRoot":"","sources":["../../src/commands/declare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,cAAc,EAAE,WAwC5B,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { ifFlag } from "./command-helpers";
2
+ export const declareCommand = {
3
+ name: "declare",
4
+ aliases: ["local", "typeset"],
5
+ description: "Declare variables and give them attributes",
6
+ category: "shell",
7
+ params: ["[-i] [-r] [-x] [-a] [name[=value]...]"],
8
+ run: ({ args, env }) => {
9
+ if (!env)
10
+ return { exitCode: 0 };
11
+ const integer = ifFlag(args, ["-i"]);
12
+ const _readonly = ifFlag(args, ["-r"]);
13
+ const _export_ = ifFlag(args, ["-x"]);
14
+ const printAll = args.filter((a) => !a.startsWith("-")).length === 0;
15
+ if (printAll) {
16
+ const lines = Object.entries(env.vars).map(([k, v]) => `declare -- ${k}="${v}"`);
17
+ return { stdout: lines.join("\n"), exitCode: 0 };
18
+ }
19
+ const assignments = args.filter((a) => !a.startsWith("-"));
20
+ for (const token of assignments) {
21
+ const eq = token.indexOf("=");
22
+ if (eq === -1) {
23
+ // Just declare (no value)
24
+ if (!(token in env.vars))
25
+ env.vars[token] = "";
26
+ }
27
+ else {
28
+ const name = token.slice(0, eq);
29
+ let val = token.slice(eq + 1);
30
+ if (integer) {
31
+ const n = parseInt(val, 10);
32
+ val = Number.isNaN(n) ? "0" : String(n);
33
+ }
34
+ env.vars[name] = val;
35
+ }
36
+ }
37
+ return { exitCode: 0 };
38
+ },
39
+ };
@@ -1,3 +1,8 @@
1
1
  import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * Compare files line-by-line and print differing lines.
4
+ * @category text
5
+ * @params ["<file1> <file2>"]
6
+ */
2
7
  export declare const diffCommand: ShellModule;
3
8
  //# sourceMappingURL=diff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/commands/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,WAAW,EAAE,WAyBzB,CAAC"}
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/commands/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WAkCzB,CAAC"}
@@ -1,4 +1,9 @@
1
1
  import { resolvePath } from "./helpers";
2
+ /**
3
+ * Compare files line-by-line and print differing lines.
4
+ * @category text
5
+ * @params ["<file1> <file2>"]
6
+ */
2
7
  export const diffCommand = {
3
8
  name: "diff",
4
9
  description: "Compare files line by line",
@@ -0,0 +1,9 @@
1
+ import type { ShellModule } from "../types/commands";
2
+ /**
3
+ * dpkg compatibility command (query/remove/list) backed by the virtual package manager.
4
+ * @category package
5
+ * @params ["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"]
6
+ */
7
+ export declare const dpkgCommand: ShellModule;
8
+ export declare const dpkgQueryCommand: ShellModule;
9
+ //# sourceMappingURL=dpkg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dpkg.d.ts","sourceRoot":"","sources":["../../src/commands/dpkg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WA0HzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,WA8C9B,CAAC"}