just-bash 2.3.1 → 2.4.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 (112) hide show
  1. package/README.md +4 -4
  2. package/dist/Bash.d.ts +0 -6
  3. package/dist/bin/chunks/cat-ZEMMQGY5.js +6 -0
  4. package/dist/bin/chunks/chunk-45SNFRCY.js +3 -0
  5. package/dist/bin/chunks/chunk-OBH7XN5N.js +1 -0
  6. package/dist/bin/{shell/chunks/chunk-OQRRF62X.js → chunks/chunk-UUQYHLBO.js} +3 -3
  7. package/dist/bin/chunks/cut-WWPJ2PYT.js +6 -0
  8. package/dist/bin/chunks/du-XQPYLN3H.js +8 -0
  9. package/dist/bin/chunks/find-4D6S5MQR.js +11 -0
  10. package/dist/bin/chunks/grep-U2RCKOEG.js +15 -0
  11. package/dist/bin/chunks/jq-63OXR3LZ.js +15 -0
  12. package/dist/bin/chunks/ls-BEHQBUMC.js +26 -0
  13. package/dist/bin/chunks/sort-C3F6LCNY.js +16 -0
  14. package/dist/bin/chunks/sqlite3-PZRKN3TT.js +37 -0
  15. package/dist/bin/chunks/tree-DQBEJH47.js +12 -0
  16. package/dist/bin/chunks/uniq-DKS7RIAE.js +5 -0
  17. package/dist/bin/chunks/wc-4LMTC3QD.js +6 -0
  18. package/dist/bin/{shell/chunks/xan-ASGSTJP4.js → chunks/xan-WNN2ZOAX.js} +48 -48
  19. package/dist/bin/chunks/{xan-view-YGORUYA2.js → xan-view-6Z6TWXMY.js} +1 -1
  20. package/dist/bin/chunks/xargs-IWT2HHEA.js +5 -0
  21. package/dist/bin/just-bash.js +77 -77
  22. package/dist/bin/shell/chunks/cat-ZEMMQGY5.js +6 -0
  23. package/dist/bin/shell/chunks/chunk-45SNFRCY.js +3 -0
  24. package/dist/bin/shell/chunks/chunk-OBH7XN5N.js +1 -0
  25. package/dist/bin/{chunks/chunk-OQRRF62X.js → shell/chunks/chunk-UUQYHLBO.js} +3 -3
  26. package/dist/bin/shell/chunks/cut-WWPJ2PYT.js +6 -0
  27. package/dist/bin/shell/chunks/du-XQPYLN3H.js +8 -0
  28. package/dist/bin/shell/chunks/find-4D6S5MQR.js +11 -0
  29. package/dist/bin/shell/chunks/grep-U2RCKOEG.js +15 -0
  30. package/dist/bin/shell/chunks/jq-63OXR3LZ.js +15 -0
  31. package/dist/bin/shell/chunks/ls-BEHQBUMC.js +26 -0
  32. package/dist/bin/shell/chunks/sort-C3F6LCNY.js +16 -0
  33. package/dist/bin/shell/chunks/sqlite3-PZRKN3TT.js +37 -0
  34. package/dist/bin/shell/chunks/tree-DQBEJH47.js +12 -0
  35. package/dist/bin/shell/chunks/uniq-DKS7RIAE.js +5 -0
  36. package/dist/bin/shell/chunks/wc-4LMTC3QD.js +6 -0
  37. package/dist/bin/{chunks/xan-ASGSTJP4.js → shell/chunks/xan-WNN2ZOAX.js} +48 -48
  38. package/dist/bin/shell/chunks/{xan-view-YGORUYA2.js → xan-view-6Z6TWXMY.js} +1 -1
  39. package/dist/bin/shell/chunks/xargs-IWT2HHEA.js +5 -0
  40. package/dist/bin/shell/shell.js +69 -69
  41. package/dist/bundle/browser.js +432 -432
  42. package/dist/bundle/chunks/cat-W5XITXDC.js +5 -0
  43. package/dist/bundle/chunks/chunk-4ACWXGKW.js +2 -0
  44. package/dist/bundle/chunks/{chunk-U4UYWYTO.js → chunk-A263W2RD.js} +3 -3
  45. package/dist/bundle/chunks/chunk-NUFRM6SI.js +0 -0
  46. package/dist/bundle/chunks/cut-KKAAQJVD.js +5 -0
  47. package/dist/bundle/chunks/du-NQXEC3EF.js +7 -0
  48. package/dist/bundle/chunks/find-GPKJFOPK.js +10 -0
  49. package/dist/bundle/chunks/grep-CTJRP2G3.js +14 -0
  50. package/dist/bundle/chunks/jq-WOKA22RE.js +14 -0
  51. package/dist/bundle/chunks/ls-5W3NU5OJ.js +23 -0
  52. package/dist/bundle/chunks/sort-JHO22QVO.js +15 -0
  53. package/dist/bundle/chunks/sqlite3-CX5D36A5.js +36 -0
  54. package/dist/bundle/chunks/tree-MEM64BW3.js +11 -0
  55. package/dist/bundle/chunks/uniq-SEKCFR7B.js +4 -0
  56. package/dist/bundle/chunks/wc-52FZ4QGS.js +5 -0
  57. package/dist/bundle/chunks/{xan-B3RI2BDO.js → xan-ZHXYF6B4.js} +48 -48
  58. package/dist/bundle/chunks/{xan-view-33AU6NPN.js → xan-view-DMFUMZG7.js} +1 -1
  59. package/dist/bundle/chunks/xargs-4FRA6OJ7.js +4 -0
  60. package/dist/bundle/index.js +59 -59
  61. package/dist/commands/browser-excluded.d.ts +0 -3
  62. package/dist/commands/find/matcher.d.ts +5 -0
  63. package/dist/commands/registry.d.ts +5 -16
  64. package/dist/commands/sqlite3/sqlite3.d.ts +4 -1
  65. package/dist/commands/sqlite3/worker.d.ts +3 -0
  66. package/dist/commands/xan/csv.d.ts +5 -0
  67. package/dist/index.d.ts +2 -2
  68. package/dist/utils/constants.d.ts +15 -0
  69. package/dist/utils/file-reader.d.ts +4 -1
  70. package/package.json +3 -3
  71. package/dist/bin/chunks/cat-7TVSOZLU.js +0 -6
  72. package/dist/bin/chunks/chunk-J7MJV6WO.js +0 -3
  73. package/dist/bin/chunks/cut-VCKWLT2T.js +0 -6
  74. package/dist/bin/chunks/du-ZONJJZUK.js +0 -8
  75. package/dist/bin/chunks/find-P6UQXFKX.js +0 -11
  76. package/dist/bin/chunks/grep-L5HBHEEQ.js +0 -15
  77. package/dist/bin/chunks/jq-MTQKMJJI.js +0 -16
  78. package/dist/bin/chunks/ls-FSSC77F4.js +0 -26
  79. package/dist/bin/chunks/sort-J5ARYV56.js +0 -16
  80. package/dist/bin/chunks/sqlite3-6WCINK3O.js +0 -38
  81. package/dist/bin/chunks/tree-ESVATRDW.js +0 -12
  82. package/dist/bin/chunks/uniq-7JNZWE5D.js +0 -5
  83. package/dist/bin/chunks/wc-OFU3HUEZ.js +0 -6
  84. package/dist/bin/chunks/xargs-WIJC4RTG.js +0 -4
  85. package/dist/bin/shell/chunks/cat-7TVSOZLU.js +0 -6
  86. package/dist/bin/shell/chunks/chunk-J7MJV6WO.js +0 -3
  87. package/dist/bin/shell/chunks/cut-VCKWLT2T.js +0 -6
  88. package/dist/bin/shell/chunks/du-ZONJJZUK.js +0 -8
  89. package/dist/bin/shell/chunks/find-P6UQXFKX.js +0 -11
  90. package/dist/bin/shell/chunks/grep-L5HBHEEQ.js +0 -15
  91. package/dist/bin/shell/chunks/jq-MTQKMJJI.js +0 -16
  92. package/dist/bin/shell/chunks/ls-FSSC77F4.js +0 -26
  93. package/dist/bin/shell/chunks/sort-J5ARYV56.js +0 -16
  94. package/dist/bin/shell/chunks/sqlite3-6WCINK3O.js +0 -38
  95. package/dist/bin/shell/chunks/tree-ESVATRDW.js +0 -12
  96. package/dist/bin/shell/chunks/uniq-7JNZWE5D.js +0 -5
  97. package/dist/bin/shell/chunks/wc-OFU3HUEZ.js +0 -6
  98. package/dist/bin/shell/chunks/xargs-WIJC4RTG.js +0 -4
  99. package/dist/bundle/chunks/cat-CE7XIAD2.js +0 -5
  100. package/dist/bundle/chunks/chunk-3YNHMZ5M.js +0 -2
  101. package/dist/bundle/chunks/cut-MCCSW2TZ.js +0 -5
  102. package/dist/bundle/chunks/du-3NURMGXT.js +0 -7
  103. package/dist/bundle/chunks/find-QJDJJ5KW.js +0 -10
  104. package/dist/bundle/chunks/grep-4K5T3MYL.js +0 -14
  105. package/dist/bundle/chunks/jq-QAA4WF2O.js +0 -15
  106. package/dist/bundle/chunks/ls-CS3TIKWR.js +0 -23
  107. package/dist/bundle/chunks/sort-PMLMEZ4E.js +0 -15
  108. package/dist/bundle/chunks/sqlite3-GFVRV2TN.js +0 -37
  109. package/dist/bundle/chunks/tree-5TYW7S7K.js +0 -11
  110. package/dist/bundle/chunks/uniq-ONGDGSEB.js +0 -4
  111. package/dist/bundle/chunks/wc-Y5MNUNQQ.js +0 -5
  112. package/dist/bundle/chunks/xargs-2IMBHM4N.js +0 -3
@@ -5,9 +5,6 @@
5
5
  * - Use Node.js-specific APIs that don't have browser equivalents
6
6
  * - Have dependencies that don't work in browsers
7
7
  *
8
- * Note: sqlite3 is opt-in (requires `sqlite: true` option) so it's not
9
- * listed here - it will show "command not found" like any other unknown command.
10
- *
11
8
  * When a user tries to use one of these commands in a browser environment,
12
9
  * they should get a helpful error message explaining why the command
13
10
  * is not available.
@@ -4,4 +4,9 @@ import type { EvalContext, EvalResult, Expression } from "./types.js";
4
4
  * The prune flag is set when -prune is evaluated and returns true.
5
5
  */
6
6
  export declare function evaluateExpressionWithPrune(expr: Expression, ctx: EvalContext): EvalResult;
7
+ /**
8
+ * Check if an expression needs full stat metadata (size, mtime, mode)
9
+ * vs just type info (isFile/isDirectory) which can come from dirent
10
+ */
11
+ export declare function expressionNeedsStatMetadata(expr: Expression | null): boolean;
7
12
  export declare function collectNewerRefs(expr: Expression | null): string[];
@@ -1,14 +1,12 @@
1
1
  import type { Command } from "../types.js";
2
- /** All available built-in command names (excludes network and sqlite commands) */
3
- export type CommandName = "echo" | "cat" | "printf" | "ls" | "mkdir" | "touch" | "rm" | "cp" | "mv" | "ln" | "chmod" | "pwd" | "readlink" | "head" | "tail" | "wc" | "stat" | "grep" | "fgrep" | "egrep" | "sed" | "awk" | "sort" | "uniq" | "comm" | "cut" | "paste" | "tr" | "rev" | "nl" | "fold" | "expand" | "unexpand" | "strings" | "split" | "column" | "join" | "tee" | "find" | "basename" | "dirname" | "tree" | "du" | "env" | "printenv" | "alias" | "unalias" | "history" | "xargs" | "true" | "false" | "clear" | "bash" | "sh" | "jq" | "base64" | "diff" | "date" | "sleep" | "timeout" | "seq" | "expr" | "md5sum" | "sha1sum" | "sha256sum" | "file" | "html-to-markdown" | "help" | "which" | "tac" | "hostname" | "od" | "gzip" | "gunzip" | "zcat" | "yq" | "xan";
2
+ /** All available built-in command names (excludes network commands) */
3
+ export type CommandName = "echo" | "cat" | "printf" | "ls" | "mkdir" | "touch" | "rm" | "cp" | "mv" | "ln" | "chmod" | "pwd" | "readlink" | "head" | "tail" | "wc" | "stat" | "grep" | "fgrep" | "egrep" | "sed" | "awk" | "sort" | "uniq" | "comm" | "cut" | "paste" | "tr" | "rev" | "nl" | "fold" | "expand" | "unexpand" | "strings" | "split" | "column" | "join" | "tee" | "find" | "basename" | "dirname" | "tree" | "du" | "env" | "printenv" | "alias" | "unalias" | "history" | "xargs" | "true" | "false" | "clear" | "bash" | "sh" | "jq" | "base64" | "diff" | "date" | "sleep" | "timeout" | "seq" | "expr" | "md5sum" | "sha1sum" | "sha256sum" | "file" | "html-to-markdown" | "help" | "which" | "tac" | "hostname" | "od" | "gzip" | "gunzip" | "zcat" | "yq" | "xan" | "sqlite3";
4
4
  /** Network command names (only available when network is configured) */
5
5
  export type NetworkCommandName = "curl";
6
- /** SQLite command names (only available when sqlite is enabled) */
7
- export type SqliteCommandName = "sqlite3";
8
- /** All command names including network and sqlite commands */
9
- export type AllCommandName = CommandName | NetworkCommandName | SqliteCommandName;
6
+ /** All command names including network commands */
7
+ export type AllCommandName = CommandName | NetworkCommandName;
10
8
  /**
11
- * Gets all available command names (excludes network and sqlite commands)
9
+ * Gets all available command names (excludes network commands)
12
10
  */
13
11
  export declare function getCommandNames(): string[];
14
12
  /**
@@ -25,15 +23,6 @@ export declare function createLazyCommands(filter?: CommandName[]): Command[];
25
23
  * These are only registered when network is explicitly configured.
26
24
  */
27
25
  export declare function createNetworkCommands(): Command[];
28
- /**
29
- * Gets all sqlite command names
30
- */
31
- export declare function getSqliteCommandNames(): string[];
32
- /**
33
- * Creates sqlite commands for registration (sqlite3, etc.)
34
- * These are only registered when sqlite is explicitly enabled.
35
- */
36
- export declare function createSqliteCommands(): Command[];
37
26
  /**
38
27
  * Clears the command cache (for testing)
39
28
  */
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * sqlite3 - SQLite database CLI
3
3
  *
4
- * Wraps better-sqlite3 to provide SQLite database access through the virtual filesystem.
4
+ * Wraps sql.js (WASM) to provide SQLite database access through the virtual filesystem.
5
5
  * Databases are loaded from buffers and written back after modifications.
6
6
  *
7
7
  * Queries run in a worker thread with a timeout to prevent runaway queries
8
8
  * (e.g., infinite recursive CTEs) from blocking execution.
9
+ *
10
+ * Security: sql.js is fully sandboxed - it cannot access the real filesystem,
11
+ * making ATTACH DATABASE and VACUUM INTO safe (they only operate on virtual buffers).
9
12
  */
10
13
  import type { Command } from "../../types.js";
11
14
  export declare const sqlite3Command: Command;
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * This isolates potentially long-running queries so they can be
5
5
  * terminated if they exceed the timeout.
6
+ *
7
+ * Uses sql.js (WASM-based SQLite) which is fully sandboxed and cannot
8
+ * access the real filesystem.
6
9
  */
7
10
  export interface WorkerInput {
8
11
  dbBuffer: Uint8Array | null;
@@ -6,6 +6,11 @@ export interface CsvRow {
6
6
  [key: string]: string | number | boolean | null;
7
7
  }
8
8
  export type CsvData = CsvRow[];
9
+ /** Parse CSV input string to array of row objects */
10
+ export declare function parseCsv(input: string): {
11
+ headers: string[];
12
+ data: CsvData;
13
+ };
9
14
  /** Format array of row objects back to CSV string */
10
15
  export declare function formatCsv(headers: string[], data: CsvData): string;
11
16
  /** Read CSV input from file or stdin */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { BashLogger, BashOptions, ExecOptions } from "./Bash.js";
2
2
  export { Bash } from "./Bash.js";
3
- export type { AllCommandName, CommandName, NetworkCommandName, SqliteCommandName, } from "./commands/registry.js";
4
- export { getCommandNames, getNetworkCommandNames, getSqliteCommandNames, } from "./commands/registry.js";
3
+ export type { AllCommandName, CommandName, NetworkCommandName, } from "./commands/registry.js";
4
+ export { getCommandNames, getNetworkCommandNames, } from "./commands/registry.js";
5
5
  export type { CustomCommand, LazyCommand } from "./custom-commands.js";
6
6
  export { defineCommand } from "./custom-commands.js";
7
7
  export { InMemoryFs } from "./fs/in-memory-fs/index.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared constants for the bash environment.
3
+ */
4
+ /**
5
+ * Default batch size for parallel I/O operations.
6
+ *
7
+ * This value is used across multiple commands (find, ls, tree, du, etc.) to
8
+ * control how many filesystem operations are performed concurrently. A larger
9
+ * value provides more parallelism but uses more memory; a smaller value is
10
+ * more conservative.
11
+ *
12
+ * 100 is a good default that provides significant parallelism without
13
+ * overwhelming the system or using excessive memory.
14
+ */
15
+ export declare const DEFAULT_BATCH_SIZE = 100;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * File reading utilities for command implementations.
3
3
  *
4
- * Provides common patterns for reading from files or stdin.
4
+ * Provides common patterns for reading from files or stdin,
5
+ * including parallel batch reading for performance.
5
6
  */
6
7
  import type { CommandContext, ExecResult } from "../types.js";
7
8
  export interface ReadFilesOptions {
@@ -11,6 +12,8 @@ export interface ReadFilesOptions {
11
12
  allowStdinMarker?: boolean;
12
13
  /** If true, stop on first error. If false, collect errors and continue */
13
14
  stopOnError?: boolean;
15
+ /** Number of files to read in parallel (default: 100). Set to 1 for sequential. */
16
+ batchSize?: number;
14
17
  }
15
18
  export interface FileContent {
16
19
  /** File name (or "-" for stdin, or "" if stdin with no files) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,11 +52,11 @@
52
52
  "license": "Apache-2.0",
53
53
  "devDependencies": {
54
54
  "@biomejs/biome": "^2.3.10",
55
- "@types/better-sqlite3": "^7.6.11",
56
55
  "@types/ini": "^4.1.1",
57
56
  "@types/node": "^25.0.3",
58
57
  "@types/papaparse": "^5.5.2",
59
58
  "@types/sprintf-js": "^1.1.4",
59
+ "@types/sql.js": "^1.4.9",
60
60
  "@types/turndown": "^5.0.6",
61
61
  "esbuild": "^0.27.2",
62
62
  "knip": "^5.41.1",
@@ -64,7 +64,6 @@
64
64
  "vitest": "^4.0.16"
65
65
  },
66
66
  "dependencies": {
67
- "better-sqlite3": "^11.9.1",
68
67
  "diff": "^8.0.2",
69
68
  "fast-xml-parser": "^5.3.3",
70
69
  "file-type": "^21.2.0",
@@ -73,6 +72,7 @@
73
72
  "papaparse": "^5.5.3",
74
73
  "smol-toml": "^1.6.0",
75
74
  "sprintf-js": "^1.1.3",
75
+ "sql.js": "^1.13.0",
76
76
  "turndown": "^7.2.2",
77
77
  "yaml": "^2.8.2"
78
78
  },
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as p}from"./chunk-J7MJV6WO.js";import{a as d}from"./chunk-TA7RUHGQ.js";import{a as c,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var f={name:"cat",summary:"concatenate files and print on the standard output",usage:"cat [OPTION]... [FILE]...",options:["-n, --number number all output lines"," --help display this help and exit"]},b={number:{short:"n",long:"number",type:"boolean"}},w={name:"cat",async execute(t,r){if(m(t))return c(f);let e=d("cat",t,b);if(!e.ok)return e.error;let s=e.result.flags.number,o=e.result.positional,a=await p(r,o,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),n="",i=1;for(let{content:l}of a.files)if(s){let u=h(l,i);n+=u.content,i=u.nextLineNumber}else n+=l;return{stdout:n,stderr:a.stderr,exitCode:a.exitCode}}};function h(t,r){let e=t.split(`
3
- `),s=t.endsWith(`
4
- `),o=s?e.slice(0,-1):e;return{content:o.map((n,i)=>`${String(r+i).padStart(6," ")} ${n}`).join(`
5
- `)+(s?`
6
- `:""),nextLineNumber:r+o.length}}export{w as catCommand};
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- async function u(e,n,s){let{cmdName:t,allowStdinMarker:f=!0,stopOnError:i=!1}=s;if(n.length===0)return{files:[{filename:"",content:e.stdin}],stderr:"",exitCode:0};let r=[],a="",c=0;for(let o of n){if(f&&o==="-"){r.push({filename:"-",content:e.stdin});continue}try{let l=e.fs.resolvePath(e.cwd,o),d=await e.fs.readFile(l);r.push({filename:o,content:d})}catch{if(a+=`${t}: ${o}: No such file or directory
3
- `,c=1,i)return{files:r,stderr:a,exitCode:c}}}return{files:r,stderr:a,exitCode:c}}async function h(e,n,s){let t=await u(e,n,{...s,stopOnError:!0});return t.exitCode!==0?{ok:!1,error:{stdout:"",stderr:t.stderr,exitCode:t.exitCode}}:{ok:!0,content:t.files.map(i=>i.content).join("")}}export{u as a,h as b};
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- import{b as x}from"./chunk-J7MJV6WO.js";import{a as y,b as I,c as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var W={name:"cut",summary:"remove sections from each line of files",usage:"cut [OPTION]... [FILE]...",options:["-c LIST select only these characters","-d DELIM use DELIM instead of TAB for field delimiter","-f LIST select only these fields","-s, --only-delimited do not print lines without delimiters"," --help display this help and exit"]};function k(t){let c=[],l=t.split(",");for(let n of l)if(n.includes("-")){let[s,r]=n.split("-");c.push({start:s?parseInt(s,10):1,end:r?parseInt(r,10):null})}else{let s=parseInt(n,10);c.push({start:s,end:s})}return c}function C(t,c){let l=[];for(let n of c){let s=n.start-1,r=n.end===null?t.length:n.end;for(let i=s;i<r&&i<t.length;i++)i>=0&&!l.includes(t[i])&&l.push(t[i])}return l}var E={name:"cut",async execute(t,c){if(I(t))return y(W);let l=" ",n=null,s=null,r=!1,i=[];for(let o=0;o<t.length;o++){let e=t[o];if(e==="-d")l=t[++o]||" ";else if(e.startsWith("-d"))l=e.slice(2);else if(e==="-f")n=t[++o];else if(e.startsWith("-f"))n=e.slice(2);else if(e==="-c")s=t[++o];else if(e.startsWith("-c"))s=e.slice(2);else if(e==="-s"||e==="--only-delimited")r=!0;else{if(e.startsWith("--"))return m("cut",e);if(e.startsWith("-")){let f=!1;for(let u of e.slice(1))if(u==="s")r=!0;else if(!"dfc".includes(u)){f=!0;break}if(f)return m("cut",e)}else i.push(e)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
3
- `,exitCode:1};let p=await x(c,i,{cmdName:"cut"});if(!p.ok)return p.error;let a=p.content.split(`
4
- `);a.length>0&&a[a.length-1]===""&&a.pop();let g=k(n||s||"1"),h="";for(let o of a)if(s){let e=o.split(""),f=[];for(let u of g){let w=u.start-1,L=u.end===null?e.length:u.end;for(let d=w;d<L&&d<e.length;d++)d>=0&&f.push(e[d])}h+=`${f.join("")}
5
- `}else{if(r&&!o.includes(l))continue;let e=o.split(l),f=C(e,g);h+=`${f.join(l)}
6
- `}return{stdout:h,stderr:"",exitCode:0}}};export{E as cutCommand};
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as z}from"./chunk-TA7RUHGQ.js";import{a as p,b as g}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var $={name:"du",summary:"estimate file space usage",usage:"du [OPTION]... [FILE]...",options:["-a write counts for all files, not just directories","-h print sizes in human readable format","-s display only a total for each argument","-c produce a grand total","--max-depth=N print total for directory only if N or fewer levels deep"," --help display this help and exit"]},D={allFiles:{short:"a",type:"boolean"},humanReadable:{short:"h",type:"boolean"},summarize:{short:"s",type:"boolean"},grandTotal:{short:"c",type:"boolean"},maxDepth:{long:"max-depth",type:"number"}},F={name:"du",async execute(t,l){if(g(t))return p($);let a=z("du",t,D);if(!a.ok)return a.error;let e={allFiles:a.result.flags.allFiles,humanReadable:a.result.flags.humanReadable,summarize:a.result.flags.summarize,grandTotal:a.result.flags.grandTotal,maxDepth:a.result.flags.maxDepth??null},s=a.result.positional;s.length===0&&s.push(".");let r="",n="",m=0;for(let o of s){let i=l.fs.resolvePath(l.cwd,o);try{await l.fs.stat(i);let u=await y(l,i,o,e,0);r+=u.output,m+=u.totalSize,n+=u.stderr}catch{n+=`du: cannot access '${o}': No such file or directory
3
- `}}return e.grandTotal&&s.length>0&&(r+=`${d(m,e.humanReadable)} total
4
- `),{stdout:r,stderr:n,exitCode:n?1:0}}};async function y(t,l,a,e,s){let r={output:"",totalSize:0,stderr:""};try{let n=await t.fs.stat(l);if(!n.isDirectory)return r.totalSize=n.size,(e.allFiles||s===0)&&(r.output=d(n.size,e.humanReadable)+" "+a+`
5
- `),r;let m=await t.fs.readdir(l),o=0;for(let i of m){let u=l==="/"?`/${i}`:`${l}/${i}`,f=a==="."?i:`${a}/${i}`;try{let c=await t.fs.stat(u);if(c.isDirectory){let h=await y(t,u,f,e,s+1);o+=h.totalSize,e.summarize||(e.maxDepth===null||s+1<=e.maxDepth?r.output+=h.output:o+=0)}else o+=c.size,e.allFiles&&!e.summarize&&(r.output+=d(c.size,e.humanReadable)+" "+f+`
6
- `)}catch{}}r.totalSize=o,(e.summarize||e.maxDepth===null||s<=e.maxDepth)&&(r.output+=`${d(o,e.humanReadable)} ${a}
7
- `)}catch{r.stderr=`du: cannot read directory '${a}': Permission denied
8
- `}return r}function d(t,l){return l?t<1024?`${t}`:t<1024*1024?`${(t/1024).toFixed(1)}K`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)}M`:`${(t/(1024*1024*1024)).toFixed(1)}G`:String(Math.ceil(t/1024)||1)}export{F as duCommand};
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as N}from"./chunk-26Q3PZQ6.js";import{a as L,b as B,c as H}from"./chunk-PM2DS2YW.js";import{a as I,b as O}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let i=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=i>e.days:e.comparison==="less"?t=i<e.days:t=Math.floor(i)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let i;return e.comparison==="more"?i=s.size>n:e.comparison==="less"?i=s.size<n:e.unit==="b"?i=Math.ceil(s.size/512)===e.value:i=s.size===n,{matches:i,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,i=e.mode&511,t;return e.matchType==="exact"?t=n===i:e.matchType==="all"?t=(n&i)===i:t=(n&i)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let i=w(e.right,s);return{matches:i.matches,pruned:n.pruned||i.pruned,printed:n.printed||i.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let i=w(e.right,s);return{matches:i.matches,pruned:n.pruned||i.pruned,printed:i.printed}}}}function G(e){let s=[],n=i=>{i&&(i.type==="newer"?s.push(i.refPath):i.type==="not"?n(i.expr):(i.type==="and"||i.type==="or")&&(n(i.left),n(i.right)))};return n(e),s}function j(e,s){let n=[],i=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let r=e[++t];if(r==="f"||r==="d")n.push({type:"expr",expr:{type:"type",fileType:r}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${r}
3
- `,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("+")?(c="more",o=r.slice(1)):r.startsWith("-")&&(c="less",o=r.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let r=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:r}})}else if(a==="-size"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("+")?(c="more",o=r.slice(1)):r.startsWith("-")&&(c="less",o=r.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("-")?(c="all",o=r.slice(1)):r.startsWith("/")&&(c="any",o=r.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let r=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)r.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";i.push({type:"exec",command:r,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),i.push({type:"print"});else if(a==="-print0")i.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let r=e[++t];i.push({type:"printf",format:r})}else if(a==="-delete")i.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
4
- `,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:i};let m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:i}:{expr:m.expr,pathIndex:t,actions:i}}function _(e){let s=0;function n(){let r=i();if(!r)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let o=i();if(!o)return r;r={type:"or",left:r,right:o}}else break}return r}function i(){let r=t();if(!r)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let o=t();if(!o)return r;r={type:"and",left:r,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return r;r={type:"and",left:r,right:o}}else break}return r}function t(){if(s<e.length&&e[s].type==="not"){s++;let r=t();return r?{type:"not",expr:r}:null}return m()}function m(){if(s>=e.length)return null;let r=e[s];if(r.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return r.type==="expr"?(s++,r.expr):(r.type==="rparen",null)}return{expr:n()}}var K={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],i=null,t=null,m=!1,a=!1;for(let l=0;l<e.length;l++){let p=e[l];if(p==="-maxdepth"&&l+1<e.length)a=!0,i=parseInt(e[++l],10);else if(p==="-mindepth"&&l+1<e.length)a=!0,t=parseInt(e[++l],10);else if(p==="-depth")a=!0,m=!0;else if(p==="-exec")for(a=!0,l++;l<e.length&&e[l]!==";"&&e[l]!=="+";)l++;else!p.startsWith("-")&&p!==";"&&p!=="+"&&p!=="("&&p!==")"&&p!=="\\("&&p!=="\\)"&&p!=="!"?a||n.push(p):U.has(p)?(a=!0,l++):(p.startsWith("-")||p==="("||p==="\\("||p==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:r,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(l=>l.type==="print"),b=o.length===0,y=[],Y=o.some(l=>l.type==="printf"),F=[],T="",D=0,V=G(r),k=new Map;for(let l of V){let p=s.fs.resolvePath(s.cwd,l);try{let g=await s.fs.stat(p);k.set(l,g.mtime?.getTime()??Date.now())}catch{}}for(let l of n){l.length>1&&l.endsWith("/")&&(l=l.slice(0,-1));let p=s.fs.resolvePath(s.cwd,l);try{await s.fs.stat(p)}catch{T+=`find: ${l}: No such file or directory
5
- `,D=1;continue}async function g(u,d){if(i!==null&&d>i)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===p?E=l.split("/").pop()||l:E=u.split("/").pop()||"";let $=u===p?l:l==="."?`./${u.slice(p==="/"?p.length:p.length+1)}`:l+u.slice(p.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,v=!1;if(x&&r!==null){let J={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},z=w(r,J);x=z.matches,h?v=z.printed:v=x}else x&&(v=!0);v&&(y.push($),Y&&F.push({path:$,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:l}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},W=!1;if(!m&&r!==null){let P={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};W=w(r,P).pruned}m?(await A(),C()):(C(),W||await A())}await g(p,0)}let S="";if(o.length>0)for(let l of o)switch(l.type){case"print":S+=y.length>0?`${y.join(`
6
- `)}
7
- `:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let p=[...y].sort((g,u)=>u.length-g.length);for(let g of p){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
8
- `,D=1}}break}case"printf":for(let p of F)S+=q(l.format,p);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
9
- `,exitCode:1};if(l.batchMode){let p=[];for(let d of l.command)d==="{}"?p.push(...y):p.push(d);let g=p.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let p of y){let u=l.command.map(f=>f==="{}"?p:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
10
- `)}
11
- `:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),i="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){i+="%",t++;continue}let[m,a,r]=B(n,t);if(t+=r,t>=n.length){i+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:i+=`%${m!==0||a!==-1?`${m}.${a}`:""}${c}`,t++;continue}i+=L(o,m,a)}else i+=n[t],t++;return i}function Q(e,s){let n=e&511,i=s?"d":"-";return i+=n&256?"r":"-",i+=n&128?"w":"-",i+=n&64?"x":"-",i+=n&32?"r":"-",i+=n&16?"w":"-",i+=n&8?"x":"-",i+=n&4?"r":"-",i+=n&2?"w":"-",i+=n&1?"x":"-",i}function X(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],i=s[e.getDay()],t=n[e.getMonth()],m=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),r=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),o=e.getFullYear();return`${i} ${t} ${m} ${a}:${r}:${c} ${o}`}function Z(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{oe as findCommand};
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as M}from"./chunk-26Q3PZQ6.js";import{a as G,b as D,c as Q}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var K={name:"grep",summary:"print lines that match patterns",usage:"grep [OPTION]... PATTERN [FILE]...",options:["-E, --extended-regexp PATTERN is an extended regular expression","-P, --perl-regexp PATTERN is a Perl regular expression","-F, --fixed-strings PATTERN is a set of newline-separated strings","-i, --ignore-case ignore case distinctions","-v, --invert-match select non-matching lines","-w, --word-regexp match only whole words","-x, --line-regexp match only whole lines","-c, --count print only a count of matching lines","-l, --files-with-matches print only names of files with matches","-L, --files-without-match print names of files with no matches","-m NUM, --max-count=NUM stop after NUM matches","-n, --line-number print line number with output lines","-h, --no-filename suppress the file name prefix on output","-o, --only-matching show only nonempty parts of lines that match","-q, --quiet, --silent suppress all normal output","-r, -R, --recursive search directories recursively","-A NUM print NUM lines of trailing context","-B NUM print NUM lines of leading context","-C NUM print NUM lines of context","-e PATTERN use PATTERN for matching"," --include=GLOB search only files matching GLOB"," --exclude=GLOB skip files matching GLOB"," --exclude-dir=DIR skip directories matching DIR"," --help display this help and exit"]},j={name:"grep",async execute(s,e){if(D(s))return G(K);let i=!1,r=!1,f=!1,c=!1,w=!1,d=!1,h=!1,m=!1,p=!1,g=!1,C=!1,I=!1,E=!1,N=!1,T=!1,a=0,y=0,o=0,n=[],x=[],W=[],$=null,F=[];for(let u=0;u<s.length;u++){let l=s[u];if(l.startsWith("-")&&l!=="-"){if(l==="-e"&&u+1<s.length){$=s[++u];continue}if(l.startsWith("--include=")){n.push(l.slice(10));continue}if(l.startsWith("--exclude=")){x.push(l.slice(10));continue}if(l.startsWith("--exclude-dir=")){W.push(l.slice(14));continue}if(l.startsWith("--max-count=")){a=parseInt(l.slice(12),10);continue}let P=l.match(/^-m(\d+)$/);if(P){a=parseInt(P[1],10);continue}if(l==="-m"&&u+1<s.length){a=parseInt(s[++u],10);continue}let v=l.match(/^-([ABC])(\d+)$/);if(v){let t=parseInt(v[2],10);v[1]==="A"?o=t:v[1]==="B"?y=t:v[1]==="C"&&(y=t,o=t);continue}if((l==="-A"||l==="-B"||l==="-C")&&u+1<s.length){let t=parseInt(s[++u],10);l==="-A"?o=t:l==="-B"?y=t:(y=t,o=t);continue}let U=l.startsWith("--")?[l]:l.slice(1).split("");for(let t of U)if(t==="i"||t==="--ignore-case")i=!0;else if(t==="n"||t==="--line-number")r=!0;else if(t==="v"||t==="--invert-match")f=!0;else if(t==="c"||t==="--count")c=!0;else if(t==="l"||t==="--files-with-matches")w=!0;else if(t==="L"||t==="--files-without-match")d=!0;else if(t==="r"||t==="R"||t==="--recursive")h=!0;else if(t==="w"||t==="--word-regexp")m=!0;else if(t==="x"||t==="--line-regexp")p=!0;else if(t==="E"||t==="--extended-regexp")g=!0;else if(t==="P"||t==="--perl-regexp")C=!0;else if(t==="F"||t==="--fixed-strings")I=!0;else if(t==="o"||t==="--only-matching")E=!0;else if(t==="h"||t==="--no-filename")N=!0;else if(t==="q"||t==="--quiet"||t==="--silent")T=!0;else{if(t.startsWith("--"))return Q("grep",t);if(t.length===1)return Q("grep",`-${t}`)}}else $===null?$=l:F.push(l)}if($===null)return{stdout:"",stderr:`grep: missing pattern
3
- `,exitCode:2};let R;I?R=$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):g||C?R=$:R=V($),m&&(R=`\\b${R}\\b`),p&&(R=`^${R}$`);let O;try{O=new RegExp(R,i?"gi":"g")}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${$}
4
- `,exitCode:2}}if(F.length===0&&e.stdin){let u=H(e.stdin,O,f,r,c,"",E,y,o,a);return T?{stdout:"",stderr:"",exitCode:u.matched?0:1}:{stdout:u.output,stderr:"",exitCode:u.matched?0:1}}if(F.length===0)return{stdout:"",stderr:`grep: no input files
5
- `,exitCode:2};let A="",S="",k=!1,q=!1,L=[];for(let u of F)if(u.includes("*")||u.includes("?")||u.includes("[")){let l=await X(u,e);if(h)for(let P of l){let v=await b(P,e,n,x,W);L.push(...v)}else L.push(...l)}else if(h){let l=await b(u,e,n,x,W);L.push(...l)}else L.push(u);let J=(L.length>1||h)&&!N;for(let u of L){let l=u.split("/").pop()||u;if(!(x.length>0&&!h&&x.some(P=>M(l,P,{stripQuotes:!0})))&&!(n.length>0&&!h&&!n.some(P=>M(l,P,{stripQuotes:!0}))))try{let P=e.fs.resolvePath(e.cwd,u);if((await e.fs.stat(P)).isDirectory){h||(S+=`grep: ${u}: Is a directory
6
- `);continue}let U=await e.fs.readFile(P),t=H(U,O,f,r,c,J?u:"",E,y,o,a);if(t.matched){if(k=!0,T)return{stdout:"",stderr:"",exitCode:0};w?A+=`${u}
7
- `:d||(A+=t.output)}else d?A+=`${u}
8
- `:c&&!w&&(A+=t.output)}catch{S+=`grep: ${u}: No such file or directory
9
- `,q=!0}}let B;return q?B=2:d?B=A.length>0?0:1:B=k?0:1,T?{stdout:"",stderr:"",exitCode:B}:{stdout:A,stderr:S,exitCode:B}}};function V(s){let e="",i=0;for(;i<s.length;){let r=s[i];if(r==="\\"&&i+1<s.length){let f=s[i+1];if(f==="|"||f==="("||f===")"){e+=f,i+=2;continue}else if(f==="{"||f==="}"){e+=`\\${f}`,i+=2;continue}}r==="+"||r==="?"||r==="|"||r==="("||r===")"||r==="{"||r==="}"?e+=`\\${r}`:e+=r,i++}return e}function H(s,e,i,r,f,c,w=!1,d=0,h=0,m=0){let p=s.split(`
10
- `),g=p.length,C=g>0&&p[g-1]===""?g-1:g;if(f){let a=0;for(let o=0;o<C;o++)e.lastIndex=0,e.test(p[o])!==i&&a++;return{output:`${c?`${c}:${a}`:String(a)}
11
- `,matched:a>0}}if(d===0&&h===0){let a=[],y=!1,o=0;for(let n=0;n<C&&!(m>0&&o>=m);n++){let x=p[n];if(e.lastIndex=0,e.test(x)!==i)if(y=!0,o++,w){e.lastIndex=0;for(let $=e.exec(x);$!==null;$=e.exec(x))a.push(c?`${c}:${$[0]}`:$[0]),$[0].length===0&&e.lastIndex++}else r?a.push(c?`${c}:${n+1}:${x}`:`${n+1}:${x}`):a.push(c?`${c}:${x}`:x)}return{output:a.length>0?`${a.join(`
12
- `)}
13
- `:"",matched:y}}let I=[],E=0,N=new Set,T=[];for(let a=0;a<C&&!(m>0&&E>=m);a++)e.lastIndex=0,e.test(p[a])!==i&&(T.push(a),E++);for(let a of T){for(let o=Math.max(0,a-d);o<a;o++)if(!N.has(o)){N.add(o);let n=p[o];r&&(n=`${o+1}-${n}`),c&&(n=`${c}-${n}`),I.push(n)}if(!N.has(a)){N.add(a);let o=p[a];if(w){e.lastIndex=0;for(let n=e.exec(o);n!==null;n=e.exec(o))I.push(c?`${c}:${n[0]}`:n[0]),n[0].length===0&&e.lastIndex++}else{let n=o;r&&(n=`${a+1}:${n}`),c&&(n=`${c}:${n}`),I.push(n)}}let y=Math.min(C-1,a+h);for(let o=a+1;o<=y;o++)if(!N.has(o)){N.add(o);let n=p[o];r&&(n=`${o+1}-${n}`),c&&(n=`${c}-${n}`),I.push(n)}}return{output:I.length>0?`${I.join(`
14
- `)}
15
- `:"",matched:E>0}}async function b(s,e,i=[],r=[],f=[]){let c=e.fs.resolvePath(e.cwd,s),w=[];try{if(!(await e.fs.stat(c)).isDirectory){let p=s.split("/").pop()||s;return r.length>0&&r.some(g=>M(p,g,{stripQuotes:!0}))?[]:i.length>0&&!i.some(g=>M(p,g,{stripQuotes:!0}))?[]:[s]}let h=s.split("/").pop()||s;if(f.length>0&&f.some(p=>M(h,p,{stripQuotes:!0})))return[];let m=await e.fs.readdir(c);for(let p of m){if(p.startsWith("."))continue;let g=s==="."?p:`${s}/${p}`,C=await b(g,e,i,r,f);w.push(...C)}}catch{}return w}async function X(s,e){let i=[],r=s.lastIndexOf("/"),f,c;if(r===-1?(f=e.cwd,c=s):(f=s.slice(0,r)||"/",c=s.slice(r+1)),s.includes("**")){let d=s.split("**"),h=d[0].replace(/\/$/,"")||".",m=d[1]||"";return await z(h,m,e,i),i}let w=e.fs.resolvePath(e.cwd,f);try{let d=await e.fs.readdir(w);for(let h of d)if(M(h,c,{stripQuotes:!0})){let m=r===-1?h:`${f}/${h}`;i.push(m)}}catch{}return i.sort()}async function z(s,e,i,r){let f=i.fs.resolvePath(i.cwd,s);try{if(!(await i.fs.stat(f)).isDirectory){let d=s.split("/").pop()||"";if(e){let h=e.replace(/^\//,"");M(d,h,{stripQuotes:!0})&&r.push(s)}return}let w=await i.fs.readdir(f);for(let d of w){let h=s==="."?d:`${s}/${d}`,m=i.fs.resolvePath(i.cwd,h);if((await i.fs.stat(m)).isDirectory)await z(h,e,i,r);else if(e){let g=e.replace(/^\//,"");M(d,g,{stripQuotes:!0})&&r.push(h)}}}catch{}}var _={name:"fgrep",async execute(s,e){return j.execute(["-F",...s],e)}},ee={name:"egrep",async execute(s,e){return j.execute(["-E",...s],e)}};export{ee as egrepCommand,_ as fgrepCommand,j as grepCommand};
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as y,b as x}from"./chunk-ACRTDIBO.js";import{i as q}from"./chunk-NWWB2XRE.js";import{a as w,b as N,c as O}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var E={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input","-j, --join-output don't print newlines after each output","-a, --ascii force ASCII output","-S, --sort-keys sort object keys","-C, --color colorize output (ignored)","-M, --monochrome monochrome output (ignored)"," --tab use tabs for indentation"," --help display this help and exit"]};function g(t,o,d,u,f,l=0){if(t===null||t===void 0)return"null";if(typeof t=="boolean")return String(t);if(typeof t=="number")return Number.isFinite(t)?String(t):"null";if(typeof t=="string")return d?t:JSON.stringify(t);let a=f?" ":" ";if(Array.isArray(t))return t.length===0?"[]":o?`[${t.map(p=>g(p,!0,!1,u,f)).join(",")}]`:`[
3
- ${t.map(p=>a.repeat(l+1)+g(p,!1,!1,u,f,l+1)).join(`,
4
- `)}
5
- ${a.repeat(l)}]`;if(typeof t=="object"){let n=Object.keys(t);return u&&(n=n.sort()),n.length===0?"{}":o?`{${n.map(c=>`${JSON.stringify(c)}:${g(t[c],!0,!1,u,f)}`).join(",")}}`:`{
6
- ${n.map(c=>{let S=g(t[c],!1,!1,u,f,l+1);return`${a.repeat(l+1)}${JSON.stringify(c)}: ${S}`}).join(`,
7
- `)}
8
- ${a.repeat(l)}}`}return String(t)}var A={name:"jq",async execute(t,o){if(N(t))return w(E);let d=!1,u=!1,f=!1,l=!1,a=!1,n=!1,p=!1,c=!1,S=".",C=!1,m=[];for(let s=0;s<t.length;s++){let e=t[s];if(e==="-r"||e==="--raw-output")d=!0;else if(e==="-c"||e==="--compact-output")u=!0;else if(e==="-e"||e==="--exit-status")f=!0;else if(e==="-s"||e==="--slurp")l=!0;else if(e==="-n"||e==="--null-input")a=!0;else if(e==="-j"||e==="--join-output")n=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")p=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")c=!0;else if(e==="-")m.push("-");else{if(e.startsWith("--"))return O("jq",e);if(e.startsWith("-")){for(let r of e.slice(1))if(r==="r")d=!0;else if(r==="c")u=!0;else if(r==="e")f=!0;else if(r==="s")l=!0;else if(r==="n")a=!0;else if(r==="j")n=!0;else if(r!=="a"){if(r==="S")p=!0;else if(r!=="C"){if(r!=="M")return O("jq",`-${r}`)}}}else C?m.push(e):(S=e,C=!0)}}}}let h;if(a)h="";else if(m.length===0||m.length===1&&m[0]==="-")h=o.stdin;else try{let s=o.fs.resolvePath(o.cwd,m[0]);h=await o.fs.readFile(s)}catch{return{stdout:"",stderr:`jq: ${m[0]}: No such file or directory
9
- `,exitCode:2}}try{let s=x(S),e,r={limits:o.limits?{maxIterations:o.limits.maxJqIterations}:void 0,env:o.env};if(a)e=y(null,s,r);else if(l){let i=[];for(let j of h.trim().split(`
10
- `))j.trim()&&i.push(JSON.parse(j));e=y(i,s,r)}else{let i=h.trim();if(i.startsWith("{")||i.startsWith("["))e=y(JSON.parse(i),s,r);else{e=[];for(let j of i.split(`
11
- `))j.trim()&&e.push(...y(JSON.parse(j),s,r))}}let I=e.map(i=>g(i,u,d,p,c)),J=n?"":`
12
- `,$=I.join(J),b=f&&(e.length===0||e.every(i=>i==null||i===!1))?1:0;return{stdout:$?n?$:`${$}
13
- `:"",stderr:"",exitCode:b}}catch(s){if(s instanceof q)return{stdout:"",stderr:`jq: ${s.message}
14
- `,exitCode:q.EXIT_CODE};let e=s.message;return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
15
- `,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
16
- `,exitCode:5}}}};export{A as jqCommand};
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as I}from"./chunk-TA7RUHGQ.js";import{a as F,b as H}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var L=(n,t,e)=>{let s=n instanceof RegExp?_(n,e):n,r=t instanceof RegExp?_(t,e):t,i=s!==null&&r!=null&&ut(s,r,e);return i&&{start:i[0],end:i[1],pre:e.slice(0,i[0]),body:e.slice(i[0]+s.length,i[1]),post:e.slice(i[1]+r.length)}},_=(n,t)=>{let e=t.match(n);return e?e[0]:null},ut=(n,t,e)=>{let s,r,i,o,l,h=e.indexOf(n),f=e.indexOf(t,h+1),u=h;if(h>=0&&f>0){if(n===t)return[h,f];for(s=[],i=e.length;u>=0&&!l;){if(u===h)s.push(u),h=e.indexOf(n,u+1);else if(s.length===1){let d=s.pop();d!==void 0&&(l=[d,f])}else r=s.pop(),r!==void 0&&r<i&&(i=r,o=f),f=e.indexOf(t,u+1);u=h<f&&h>=0?h:f}s.length&&o!==void 0&&(l=[i,o])}return l};var J="\0SLASH"+Math.random()+"\0",U="\0OPEN"+Math.random()+"\0",G="\0CLOSE"+Math.random()+"\0",Z="\0COMMA"+Math.random()+"\0",K="\0PERIOD"+Math.random()+"\0",ft=new RegExp(J,"g"),pt=new RegExp(U,"g"),dt=new RegExp(G,"g"),gt=new RegExp(Z,"g"),mt=new RegExp(K,"g"),yt=/\\\\/g,wt=/\\{/g,St=/\\}/g,xt=/\\,/g,$t=/\\./g;function k(n){return isNaN(n)?n.charCodeAt(0):parseInt(n,10)}function bt(n){return n.replace(yt,J).replace(wt,U).replace(St,G).replace(xt,Z).replace($t,K)}function Et(n){return n.replace(ft,"\\").replace(pt,"{").replace(dt,"}").replace(gt,",").replace(mt,".")}function V(n){if(!n)return[""];let t=[],e=L("{","}",n);if(!e)return n.split(",");let{pre:s,body:r,post:i}=e,o=s.split(",");o[o.length-1]+="{"+r+"}";let l=V(i);return i.length&&(o[o.length-1]+=l.shift(),o.push.apply(o,l)),t.push.apply(t,o),t}function X(n){return n?(n.slice(0,2)==="{}"&&(n="\\{\\}"+n.slice(2)),P(bt(n),!0).map(Et)):[]}function At(n){return"{"+n+"}"}function vt(n){return/^-?0\d/.test(n)}function Mt(n,t){return n<=t}function Nt(n,t){return n>=t}function P(n,t){let e=[],s=L("{","}",n);if(!s)return[n];let r=s.pre,i=s.post.length?P(s.post,!1):[""];if(/\$$/.test(s.pre))for(let o=0;o<i.length;o++){let l=r+"{"+s.body+"}"+i[o];e.push(l)}else{let o=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),l=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),h=o||l,f=s.body.indexOf(",")>=0;if(!h&&!f)return s.post.match(/,(?!,).*\}/)?(n=s.pre+"{"+s.body+G+s.post,P(n)):[n];let u;if(h)u=s.body.split(/\.\./);else if(u=V(s.body),u.length===1&&u[0]!==void 0&&(u=P(u[0],!1).map(At),u.length===1))return i.map(a=>s.pre+u[0]+a);let d;if(h&&u[0]!==void 0&&u[1]!==void 0){let a=k(u[0]),c=k(u[1]),g=Math.max(u[0].length,u[1].length),p=u.length===3&&u[2]!==void 0?Math.abs(k(u[2])):1,m=Mt;c<a&&(p*=-1,m=Nt);let w=u.some(vt);d=[];for(let S=a;m(S,c);S+=p){let x;if(l)x=String.fromCharCode(S),x==="\\"&&(x="");else if(x=String(S),w){let b=g-x.length;if(b>0){let v=new Array(b+1).join("0");S<0?x="-"+v+x.slice(1):x=v+x}}d.push(x)}}else{d=[];for(let a=0;a<u.length;a++)d.push.apply(d,P(u[a],!1))}for(let a=0;a<d.length;a++)for(let c=0;c<i.length;c++){let g=r+d[a]+i[c];(!t||h||g)&&e.push(g)}}return e}var O=n=>{if(typeof n!="string")throw new TypeError("invalid pattern");if(n.length>65536)throw new TypeError("pattern is too long")};var Tt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},z=n=>n.replace(/[[\]\\-]/g,"\\$&"),Pt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Y=n=>n.join(""),Q=(n,t)=>{let e=t;if(n.charAt(e)!=="[")throw new Error("not in a brace expression");let s=[],r=[],i=e+1,o=!1,l=!1,h=!1,f=!1,u=e,d="";t:for(;i<n.length;){let p=n.charAt(i);if((p==="!"||p==="^")&&i===e+1){f=!0,i++;continue}if(p==="]"&&o&&!h){u=i+1;break}if(o=!0,p==="\\"&&!h){h=!0,i++;continue}if(p==="["&&!h){for(let[m,[y,w,S]]of Object.entries(Tt))if(n.startsWith(m,i)){if(d)return["$.",!1,n.length-e,!0];i+=m.length,S?r.push(y):s.push(y),l=l||w;continue t}}if(h=!1,d){p>d?s.push(z(d)+"-"+z(p)):p===d&&s.push(z(p)),d="",i++;continue}if(n.startsWith("-]",i+1)){s.push(z(p+"-")),i+=2;continue}if(n.startsWith("-",i+1)){d=p,i+=2;continue}s.push(z(p)),i++}if(u<i)return["",!1,0,!1];if(!s.length&&!r.length)return["$.",!1,n.length-e,!0];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!f){let p=s[0].length===2?s[0].slice(-1):s[0];return[Pt(p),!1,u-e,!1]}let a="["+(f?"^":"")+Y(s)+"]",c="["+(f?"":"^")+Y(r)+"]";return[s.length&&r.length?"("+a+"|"+c+")":s.length?a:c,l,u-e,!0]};var M=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!0}={})=>e?t?n.replace(/\[([^\/\\])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?n.replace(/\[([^\/\\{}])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1");var Ot=new Set(["!","?","+","*","@"]),tt=n=>Ot.has(n),zt="(?!(?:^|/)\\.\\.?(?:$|/))",C="(?!\\.)",Ct=new Set(["[","."]),Rt=new Set(["..","."]),Dt=new Set("().*{}+?[]^$\\!"),Wt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),B="[^/]",et=B+"*?",st=B+"+?",N=class n{type;#s;#n;#r=!1;#t=[];#e;#o;#c;#a=!1;#i;#h;#u=!1;constructor(t,e,s={}){this.type=t,t&&(this.#n=!0),this.#e=e,this.#s=this.#e?this.#e.#s:this,this.#i=this.#s===this?s:this.#s.#i,this.#c=this.#s===this?[]:this.#s.#c,t==="!"&&!this.#s.#a&&this.#c.push(this),this.#o=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(let t of this.#t)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#h!==void 0?this.#h:this.type?this.#h=this.type+"("+this.#t.map(t=>String(t)).join("|")+")":this.#h=this.#t.map(t=>String(t)).join("")}#p(){if(this!==this.#s)throw new Error("should only call on root");if(this.#a)return this;this.toString(),this.#a=!0;let t;for(;t=this.#c.pop();){if(t.type!=="!")continue;let e=t,s=e.#e;for(;s;){for(let r=e.#o+1;!s.type&&r<s.#t.length;r++)for(let i of t.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(s.#t[r])}e=s,s=e.#e}}return this}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof n&&e.#e===this))throw new Error("invalid part: "+e);this.#t.push(e)}}toJSON(){let t=this.type===null?this.#t.slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...this.#t.map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#s||this.#s.#a&&this.#e?.type==="!")&&t.push({}),t}isStart(){if(this.#s===this)return!0;if(!this.#e?.isStart())return!1;if(this.#o===0)return!0;let t=this.#e;for(let e=0;e<this.#o;e++){let s=t.#t[e];if(!(s instanceof n&&s.type==="!"))return!1}return!0}isEnd(){if(this.#s===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();let t=this.#e?this.#e.#t.length:0;return this.#o===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let e=new n(this.type,t);for(let s of this.#t)e.copyIn(s);return e}static#l(t,e,s,r){let i=!1,o=!1,l=-1,h=!1;if(e.type===null){let c=s,g="";for(;c<t.length;){let p=t.charAt(c++);if(i||p==="\\"){i=!i,g+=p;continue}if(o){c===l+1?(p==="^"||p==="!")&&(h=!0):p==="]"&&!(c===l+2&&h)&&(o=!1),g+=p;continue}else if(p==="["){o=!0,l=c,h=!1,g+=p;continue}if(!r.noext&&tt(p)&&t.charAt(c)==="("){e.push(g),g="";let m=new n(p,e);c=n.#l(t,m,c,r),e.push(m);continue}g+=p}return e.push(g),c}let f=s+1,u=new n(null,e),d=[],a="";for(;f<t.length;){let c=t.charAt(f++);if(i||c==="\\"){i=!i,a+=c;continue}if(o){f===l+1?(c==="^"||c==="!")&&(h=!0):c==="]"&&!(f===l+2&&h)&&(o=!1),a+=c;continue}else if(c==="["){o=!0,l=f,h=!1,a+=c;continue}if(tt(c)&&t.charAt(f)==="("){u.push(a),a="";let g=new n(c,u);u.push(g),f=n.#l(t,g,f,r);continue}if(c==="|"){u.push(a),a="",d.push(u),u=new n(null,e);continue}if(c===")")return a===""&&e.#t.length===0&&(e.#u=!0),u.push(a),a="",e.push(...d,u),f;a+=c}return e.type=null,e.#n=void 0,e.#t=[t.substring(s-1)],f}static fromGlob(t,e={}){let s=new n(null,void 0,e);return n.#l(t,s,0,e),s}toMMPattern(){if(this!==this.#s)return this.#s.toMMPattern();let t=this.toString(),[e,s,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#i.nocase&&!this.#i.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return s;let l=(this.#i.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${e}$`,l),{_src:e,_glob:t})}get options(){return this.#i}toRegExpSource(t){let e=t??!!this.#i.dot;if(this.#s===this&&this.#p(),!this.type){let h=this.isStart()&&this.isEnd()&&!this.#t.some(c=>typeof c!="string"),f=this.#t.map(c=>{let[g,p,m,y]=typeof c=="string"?n.#d(c,this.#n,h):c.toRegExpSource(t);return this.#n=this.#n||m,this.#r=this.#r||y,g}).join(""),u="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&Rt.has(this.#t[0]))){let g=Ct,p=e&&g.has(f.charAt(0))||f.startsWith("\\.")&&g.has(f.charAt(2))||f.startsWith("\\.\\.")&&g.has(f.charAt(4)),m=!e&&!t&&g.has(f.charAt(0));u=p?zt:m?C:""}let d="";return this.isEnd()&&this.#s.#a&&this.#e?.type==="!"&&(d="(?:$|\\/)"),[u+f+d,M(f),this.#n=!!this.#n,this.#r]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",i=this.#f(e);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){let h=this.toString();return this.#t=[h],this.type=null,this.#n=void 0,[h,M(this.toString()),!1,!1]}let o=!s||t||e||!C?"":this.#f(!0);o===i&&(o=""),o&&(i=`(?:${i})(?:${o})*?`);let l="";if(this.type==="!"&&this.#u)l=(this.isStart()&&!e?C:"")+st;else{let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?C:"")+et+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;l=r+i+h}return[l,M(i),this.#n=!!this.#n,this.#r]}#f(t){return this.#t.map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[s,r,i,o]=e.toRegExpSource(t);return this.#r=this.#r||o,s}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")}static#d(t,e,s=!1){let r=!1,i="",o=!1;for(let l=0;l<t.length;l++){let h=t.charAt(l);if(r){r=!1,i+=(Dt.has(h)?"\\":"")+h;continue}if(h==="\\"){l===t.length-1?i+="\\\\":r=!0;continue}if(h==="["){let[f,u,d,a]=Q(t,l);if(d){i+=f,o=o||u,l+=d-1,e=e||a;continue}}if(h==="*"){i+=s&&t==="*"?st:et,e=!0;continue}if(h==="?"){i+=B,e=!0;continue}i+=Wt(h)}return[i,M(t),!!e,o]}};var q=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!1}={})=>e?t?n.replace(/[?*()[\]{}]/g,"[$&]"):n.replace(/[?*()[\]\\{}]/g,"\\$&"):t?n.replace(/[?*()[\]]/g,"[$&]"):n.replace(/[?*()[\]\\]/g,"\\$&");var $=(n,t,e={})=>(O(t),!e.nocomment&&t.charAt(0)==="#"?!1:new T(t,e).match(n)),jt=/^\*+([^+@!?\*\[\(]*)$/,Lt=n=>t=>!t.startsWith(".")&&t.endsWith(n),kt=n=>t=>t.endsWith(n),Gt=n=>(n=n.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(n)),Bt=n=>(n=n.toLowerCase(),t=>t.toLowerCase().endsWith(n)),qt=/^\*+\.\*+$/,Ft=n=>!n.startsWith(".")&&n.includes("."),Ht=n=>n!=="."&&n!==".."&&n.includes("."),It=/^\.\*+$/,_t=n=>n!=="."&&n!==".."&&n.startsWith("."),Jt=/^\*+$/,Ut=n=>n.length!==0&&!n.startsWith("."),Zt=n=>n.length!==0&&n!=="."&&n!=="..",Kt=/^\?+([^+@!?\*\[\(]*)?$/,Vt=([n,t=""])=>{let e=rt([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},Xt=([n,t=""])=>{let e=ot([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},Yt=([n,t=""])=>{let e=ot([n]);return t?s=>e(s)&&s.endsWith(t):e},Qt=([n,t=""])=>{let e=rt([n]);return t?s=>e(s)&&s.endsWith(t):e},rt=([n])=>{let t=n.length;return e=>e.length===t&&!e.startsWith(".")},ot=([n])=>{let t=n.length;return e=>e.length===t&&e!=="."&&e!==".."},at=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",nt={win32:{sep:"\\"},posix:{sep:"/"}},te=at==="win32"?nt.win32.sep:nt.posix.sep;$.sep=te;var A=Symbol("globstar **");$.GLOBSTAR=A;var ee="[^/]",se=ee+"*?",ne="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",ie="(?:(?!(?:\\/|^)\\.).)*?",re=(n,t={})=>e=>$(e,n,t);$.filter=re;var E=(n,t={})=>Object.assign({},n,t),oe=n=>{if(!n||typeof n!="object"||!Object.keys(n).length)return $;let t=$;return Object.assign((s,r,i={})=>t(s,r,E(n,i)),{Minimatch:class extends t.Minimatch{constructor(r,i={}){super(r,E(n,i))}static defaults(r){return t.defaults(E(n,r)).Minimatch}},AST:class extends t.AST{constructor(r,i,o={}){super(r,i,E(n,o))}static fromGlob(r,i={}){return t.AST.fromGlob(r,E(n,i))}},unescape:(s,r={})=>t.unescape(s,E(n,r)),escape:(s,r={})=>t.escape(s,E(n,r)),filter:(s,r={})=>t.filter(s,E(n,r)),defaults:s=>t.defaults(E(n,s)),makeRe:(s,r={})=>t.makeRe(s,E(n,r)),braceExpand:(s,r={})=>t.braceExpand(s,E(n,r)),match:(s,r,i={})=>t.match(s,r,E(n,i)),sep:t.sep,GLOBSTAR:A})};$.defaults=oe;var ct=(n,t={})=>(O(n),t.nobrace||!/\{(?:(?!\{).)*\}/.test(n)?[n]:X(n));$.braceExpand=ct;var ae=(n,t={})=>new T(n,t).makeRe();$.makeRe=ae;var ce=(n,t,e={})=>{let s=new T(t,e);return n=n.filter(r=>s.match(r)),s.options.nonull&&!n.length&&n.push(t),n};$.match=ce;var it=/[?*]|[+@!]\(.*?\)|\[|\]/,he=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),T=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(t,e={}){O(t),e=e||{},this.options=e,this.pattern=t,this.platform=e.platform||at,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!e.nonegate,this.comment=!1,this.empty=!1,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let e of t)if(typeof e!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,e=this.options;if(!e.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);let s=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(s),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,o,l)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=i[0]===""&&i[1]===""&&(i[2]==="?"||!it.test(i[2]))&&!it.test(i[3]),f=/^[a-z]:/i.test(i[0]);if(h)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(f)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(h=>this.parse(h))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){let o=this.set[i];o[0]===""&&o[1]===""&&this.globParts[i][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let s=0;s<t.length;s++)for(let r=0;r<t[s].length;r++)t[s][r]==="**"&&(t[s][r]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):e>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(e=>{let s=-1;for(;(s=e.indexOf("**",s+1))!==-1;){let r=s;for(;e[r+1]==="**";)r++;r!==s&&e.splice(s,r-s)}return e})}levelOneOptimize(t){return t.map(e=>(e=e.reduce((s,r)=>{let i=s[s.length-1];return r==="**"&&i==="**"?s:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(s.pop(),s):(s.push(r),s)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let e=!1;do{if(e=!1,!this.preserveMultipleSlashes){for(let r=1;r<t.length-1;r++){let i=t[r];r===1&&i===""&&t[0]===""||(i==="."||i==="")&&(e=!0,t.splice(r,1),r--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=!0,t.pop())}let s=0;for(;(s=t.indexOf("..",s+1))!==-1;){let r=t[s-1];r&&r!=="."&&r!==".."&&r!=="**"&&(e=!0,t.splice(s-1,2),s-=2)}}while(e);return t.length===0?[""]:t}firstPhasePreProcess(t){let e=!1;do{e=!1;for(let s of t){let r=-1;for(;(r=s.indexOf("**",r+1))!==-1;){let o=r;for(;s[o+1]==="**";)o++;o>r&&s.splice(r+1,o-r);let l=s[r+1],h=s[r+2],f=s[r+3];if(l!==".."||!h||h==="."||h===".."||!f||f==="."||f==="..")continue;e=!0,s.splice(r,1);let u=s.slice(0);u[r]="**",t.push(u),r--}if(!this.preserveMultipleSlashes){for(let o=1;o<s.length-1;o++){let l=s[o];o===1&&l===""&&s[0]===""||(l==="."||l==="")&&(e=!0,s.splice(o,1),o--)}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(e=!0,s.pop())}let i=0;for(;(i=s.indexOf("..",i+1))!==-1;){let o=s[i-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=!0;let h=i===1&&s[i+1]==="**"?["."]:[];s.splice(i-1,2,...h),s.length===0&&s.push(""),i-=2}}}}while(e);return t}secondPhasePreProcess(t){for(let e=0;e<t.length-1;e++)for(let s=e+1;s<t.length;s++){let r=this.partsMatch(t[e],t[s],!this.preserveMultipleSlashes);if(r){t[e]=[],t[s]=r;break}}return t.filter(e=>e.length)}partsMatch(t,e,s=!1){let r=0,i=0,o=[],l="";for(;r<t.length&&i<e.length;)if(t[r]===e[i])o.push(l==="b"?e[i]:t[r]),r++,i++;else if(s&&t[r]==="**"&&e[i]===t[r+1])o.push(t[r]),r++;else if(s&&e[i]==="**"&&t[r]===e[i+1])o.push(e[i]),i++;else if(t[r]==="*"&&e[i]&&(this.options.dot||!e[i].startsWith("."))&&e[i]!=="**"){if(l==="b")return!1;l="a",o.push(t[r]),r++,i++}else if(e[i]==="*"&&t[r]&&(this.options.dot||!t[r].startsWith("."))&&t[r]!=="**"){if(l==="a")return!1;l="b",o.push(e[i]),r++,i++}else return!1;return t.length===e.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,e=!1,s=0;for(let r=0;r<t.length&&t.charAt(r)==="!";r++)e=!e,s++;s&&(this.pattern=t.slice(s)),this.negate=e}matchOne(t,e,s=!1){let r=this.options;if(this.isWindows){let p=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),m=!p&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),y=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),w=!y&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),S=m?3:p?0:void 0,x=w?3:y?0:void 0;if(typeof S=="number"&&typeof x=="number"){let[b,v]=[t[S],e[x]];b.toLowerCase()===v.toLowerCase()&&(e[x]=b,x>S?e=e.slice(x):S>x&&(t=t.slice(S)))}}let{optimizationLevel:i=1}=this.options;i>=2&&(t=this.levelTwoFileOptimize(t)),this.debug("matchOne",this,{file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var o=0,l=0,h=t.length,f=e.length;o<h&&l<f;o++,l++){this.debug("matchOne loop");var u=e[l],d=t[o];if(this.debug(e,u,d),u===!1)return!1;if(u===A){this.debug("GLOBSTAR",[e,u,d]);var a=o,c=l+1;if(c===f){for(this.debug("** at the end");o<h;o++)if(t[o]==="."||t[o]===".."||!r.dot&&t[o].charAt(0)===".")return!1;return!0}for(;a<h;){var g=t[a];if(this.debug(`
3
- globstar while`,t,a,e,c,g),this.matchOne(t.slice(a),e.slice(c),s))return this.debug("globstar found match!",a,h,g),!0;if(g==="."||g===".."||!r.dot&&g.charAt(0)==="."){this.debug("dot detected!",t,a,e,c);break}this.debug("globstar swallow a segment, and continue"),a++}return!!(s&&(this.debug(`
4
- >>> no match, partial?`,t,a,e,c),a===h))}let p;if(typeof u=="string"?(p=d===u,this.debug("string match",u,d,p)):(p=u.test(d),this.debug("pattern match",u,d,p)),!p)return!1}if(o===h&&l===f)return!0;if(o===h)return s;if(l===f)return o===h-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return ct(this.pattern,this.options)}parse(t){O(t);let e=this.options;if(t==="**")return A;if(t==="")return"";let s,r=null;(s=t.match(Jt))?r=e.dot?Zt:Ut:(s=t.match(jt))?r=(e.nocase?e.dot?Bt:Gt:e.dot?kt:Lt)(s[1]):(s=t.match(Kt))?r=(e.nocase?e.dot?Xt:Vt:e.dot?Yt:Qt)(s):(s=t.match(qt))?r=e.dot?Ht:Ft:(s=t.match(It))&&(r=_t);let i=N.fromGlob(t,this.options).toMMPattern();return r&&typeof i=="object"&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let e=this.options,s=e.noglobstar?se:e.dot?ne:ie,r=new Set(e.nocase?["i"]:[]),i=t.map(h=>{let f=h.map(d=>{if(d instanceof RegExp)for(let a of d.flags.split(""))r.add(a);return typeof d=="string"?he(d):d===A?A:d._src});f.forEach((d,a)=>{let c=f[a+1],g=f[a-1];d!==A||g===A||(g===void 0?c!==void 0&&c!==A?f[a+1]="(?:\\/|"+s+"\\/)?"+c:f[a]=s:c===void 0?f[a-1]=g+"(?:\\/|\\/"+s+")?":c!==A&&(f[a-1]=g+"(?:\\/|\\/"+s+"\\/)"+c,f[a+1]=A))});let u=f.filter(d=>d!==A);if(this.partial&&u.length>=1){let d=[];for(let a=1;a<=u.length;a++)d.push(u.slice(0,a).join("/"));return"(?:"+d.join("|")+")"}return u.join("/")}).join("|"),[o,l]=t.length>1?["(?:",")"]:["",""];i="^"+o+i+l+"$",this.partial&&(i="^(?:\\/|"+o+i.slice(1,-1)+l+")$"),this.negate&&(i="^(?!"+i+").+$");try{this.regexp=new RegExp(i,[...r].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,e=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&e)return!0;let s=this.options;this.isWindows&&(t=t.split("\\").join("/"));let r=this.slashSplit(t);this.debug(this.pattern,"split",r);let i=this.set;this.debug(this.pattern,"set",i);let o=r[r.length-1];if(!o)for(let l=r.length-2;!o&&l>=0;l--)o=r[l];for(let l=0;l<i.length;l++){let h=i[l],f=r;if(s.matchBase&&h.length===1&&(f=[o]),this.matchOne(f,h,e))return s.flipNegate?!0:!this.negate}return s.flipNegate?!1:this.negate}static defaults(t){return $.defaults(t).Minimatch}};$.AST=N;$.Minimatch=T;$.escape=q;$.unescape=M;function R(n){if(n<1024)return String(n);if(n<1024*1024){let e=n/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(n<1024*1024*1024){let e=n/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=n/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function D(n){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=String(n.getDate()).padStart(2," "),r=new Date,i=new Date(r.getTime()-4320*60*60*1e3);if(n>i){let l=String(n.getHours()).padStart(2,"0"),h=String(n.getMinutes()).padStart(2,"0");return`${e} ${s} ${l}:${h}`}let o=n.getFullYear();return`${e} ${s} ${o}`}var le={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},ue={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},Le={name:"ls",async execute(n,t){if(H(n))return F(le);let e=I("ls",n,ue);if(!e.ok)return e.error;let s=e.result.flags.showAll,r=e.result.flags.showAlmostAll,i=e.result.flags.longFormat,o=e.result.flags.humanReadable,l=e.result.flags.recursive,h=e.result.flags.reverse,f=e.result.flags.sortBySize,u=e.result.flags.directoryOnly,d=e.result.flags.sortByTime;e.result.flags.onePerLine;let a=e.result.positional;a.length===0&&a.push(".");let c="",g="",p=0;for(let m=0;m<a.length;m++){let y=a[m];if(m>0&&c&&!c.endsWith(`
5
-
6
- `)&&(c+=`
7
- `),u){let w=t.fs.resolvePath(t.cwd,y);try{let S=await t.fs.stat(w);if(i){let x=S.isDirectory?"drwxr-xr-x":"-rw-r--r--",b=S.isDirectory?"/":"",v=S.size??0,W=o?R(v).padStart(5):String(v).padStart(5),j=S.mtime??new Date(0),lt=D(j);c+=`${x} 1 user user ${W} ${lt} ${y}${b}
8
- `}else c+=`${y}
9
- `}catch{g+=`ls: cannot access '${y}': No such file or directory
10
- `,p=2}continue}if(y.includes("*")||y.includes("?")||y.includes("[")){let w=await fe(y,t,s,r,i,h,o,f);c+=w.stdout,g+=w.stderr,w.exitCode!==0&&(p=w.exitCode)}else{let w=await ht(y,t,s,r,i,l,a.length>1,h,o,f);c+=w.stdout,g+=w.stderr,w.exitCode!==0&&(p=w.exitCode)}}return{stdout:c,stderr:g,exitCode:p}}};async function fe(n,t,e,s,r,i=!1,o=!1,l=!1){let h=e||s,f=t.fs.getAllPaths(),u=t.fs.resolvePath(t.cwd,"."),d=[];for(let a of f){let c=a.startsWith(u)&&a.slice(u.length+1)||a;if($(c,n)||$(a,n)){let g=c.split("/").pop()||c;if(!h&&g.startsWith("."))continue;d.push(c||a)}}if(d.length===0)return{stdout:"",stderr:`ls: ${n}: No such file or directory
11
- `,exitCode:2};if(l){let a=[];for(let c of d){let g=t.fs.resolvePath(t.cwd,c);try{let p=await t.fs.stat(g);a.push({path:c,size:p.size??0})}catch{a.push({path:c,size:0})}}a.sort((c,g)=>g.size-c.size),d.length=0,d.push(...a.map(c=>c.path))}else d.sort();if(i&&d.reverse(),r){let a=[];for(let c of d){let g=t.fs.resolvePath(t.cwd,c);try{let p=await t.fs.stat(g),m=p.isDirectory?"drwxr-xr-x":"-rw-r--r--",y=p.isDirectory?"/":"",w=p.size??0,S=o?R(w).padStart(5):String(w).padStart(5),x=p.mtime??new Date(0),b=D(x);a.push(`${m} 1 user user ${S} ${b} ${c}${y}`)}catch{a.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${c}`)}}return{stdout:`${a.join(`
12
- `)}
13
- `,stderr:"",exitCode:0}}return{stdout:`${d.join(`
14
- `)}
15
- `,stderr:"",exitCode:0}}async function ht(n,t,e,s,r,i,o,l=!1,h=!1,f=!1,u=!1){let d=e||s,a=t.fs.resolvePath(t.cwd,n);try{let c=await t.fs.stat(a);if(!c.isDirectory){if(r){let m=c.size??0,y=h?R(m).padStart(5):String(m).padStart(5),w=c.mtime??new Date(0),S=D(w);return{stdout:`-rw-r--r-- 1 user user ${y} ${S} ${n}
16
- `,stderr:"",exitCode:0}}return{stdout:`${n}
17
- `,stderr:"",exitCode:0}}let g=await t.fs.readdir(a);if(d||(g=g.filter(m=>!m.startsWith("."))),f){let m=[];for(let y of g){let w=a==="/"?`/${y}`:`${a}/${y}`;try{let S=await t.fs.stat(w);m.push({name:y,size:S.size??0})}catch{m.push({name:y,size:0})}}m.sort((y,w)=>w.size-y.size),g=m.map(y=>y.name)}else g.sort();e&&(g=[".","..",...g]),l&&g.reverse();let p="";if((i||o)&&(p+=`${n}:
18
- `),r){p+=`total ${g.length}
19
- `;for(let m of g){if(m==="."||m===".."){p+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${m}
20
- `;continue}let y=a==="/"?`/${m}`:`${a}/${m}`;try{let w=await t.fs.stat(y),S=w.isDirectory?"drwxr-xr-x":"-rw-r--r--",x=w.isDirectory?"/":"",b=w.size??0,v=h?R(b).padStart(5):String(b).padStart(5),W=w.mtime??new Date(0),j=D(W);p+=`${S} 1 user user ${v} ${j} ${m}${x}
21
- `}catch{p+=`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${m}
22
- `}}}else p+=g.join(`
23
- `)+(g.length?`
24
- `:"");if(i)for(let m of g){if(m==="."||m==="..")continue;let y=a==="/"?`/${m}`:`${a}/${m}`;try{if((await t.fs.stat(y)).isDirectory){p+=`
25
- `;let S=n==="."?`./${m}`:`${n}/${m}`,x=await ht(S,t,e,s,r,i,!1,l,h,f,!0);p+=x.stdout}}catch{}}return{stdout:p,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${n}: No such file or directory
26
- `,exitCode:2}}}export{Le as lsCommand};
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import{b as O}from"./chunk-J7MJV6WO.js";import{a as F,b as N,c as k}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var P={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},V={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12};function w(u){let r=u.trim(),e=r.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!e){let n=parseFloat(r);return Number.isNaN(n)?0:n}let l=parseFloat(e[1]),s=(e[2]||"").toLowerCase(),i=P[s]||1;return l*i}function L(u){let r=u.trim().toLowerCase().slice(0,3);return V[r]||0}function D(u,r){let e=u.split(/(\d+)/),l=r.split(/(\d+)/),s=Math.max(e.length,l.length);for(let i=0;i<s;i++){let n=e[i]||"",d=l[i]||"",o=/^\d+$/.test(n)?parseInt(n,10):null,c=/^\d+$/.test(d)?parseInt(d,10):null;if(o!==null&&c!==null){if(o!==c)return o-c}else if(n!==d)return n.localeCompare(d)}return 0}function x(u){return u.replace(/[^a-zA-Z0-9\s]/g,"")}function v(u,r,e){let l=e!==null?e:/\s+/,s=u.split(l),i=r.startField-1;if(i>=s.length)return"";if(r.endField===void 0){let o=s[i]||"";return r.startChar!==void 0&&(o=o.slice(r.startChar-1)),r.ignoreLeading&&(o=o.trimStart()),o}let n=Math.min(r.endField-1,s.length-1),d="";for(let o=i;o<=n&&o<s.length;o++){let c=s[o]||"";if(o===i&&r.startChar!==void 0&&(c=c.slice(r.startChar-1)),o===n&&r.endChar!==void 0){let t=o===i&&r.startChar!==void 0?r.endChar-r.startChar+1:r.endChar;c=c.slice(0,t)}o>i&&(d+=e||" "),d+=c}return r.ignoreLeading&&(d=d.trimStart()),d}function I(u,r,e){let l=u,s=r;if(e.dictionaryOrder&&(l=x(l),s=x(s)),e.ignoreCase&&(l=l.toLowerCase(),s=s.toLowerCase()),e.monthSort){let i=L(l),n=L(s);return i-n}if(e.humanNumeric){let i=w(l),n=w(s);return i-n}if(e.versionSort)return D(l,s);if(e.numeric){let i=parseFloat(l)||0,n=parseFloat(s)||0;return i-n}return l.localeCompare(s)}function M(u){let{keys:r,fieldDelimiter:e,numeric:l,ignoreCase:s,reverse:i,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c,ignoreLeadingBlanks:t,stable:a}=u;return(f,S)=>{let g=f,b=S;if(t&&(g=g.trimStart(),b=b.trimStart()),r.length===0){let h=I(g,b,{numeric:l,ignoreCase:s,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c});if(h!==0)return i?-h:h;if(!a){let p=f.localeCompare(S);return i?-p:p}return 0}for(let m of r){let h=v(g,m,e),p=v(b,m,e);m.ignoreLeading&&(h=h.trimStart(),p=p.trimStart());let B={numeric:m.numeric??l,ignoreCase:m.ignoreCase??s,humanNumeric:m.humanNumeric??n,versionSort:m.versionSort??d,dictionaryOrder:m.dictionaryOrder??o,monthSort:m.monthSort??c},A=m.reverse??i,y=I(h,p,B);if(y!==0)return A?-y:y}if(!a){let m=f.localeCompare(S);return i?-m:m}return 0}}function E(u,r){if(r.keys.length===0){if(r.ignoreCase){let s=new Set;return u.filter(i=>{let n=i.toLowerCase();return s.has(n)?!1:(s.add(n),!0)})}return[...new Set(u)]}let e=r.keys[0],l=new Set;return u.filter(s=>{let i=v(s,e,r.fieldDelimiter);return(e.ignoreCase??r.ignoreCase)&&(i=i.toLowerCase()),l.has(i)?!1:(l.add(i),!0)})}function C(u){let r={startField:1},e="",l=u,s=l.match(/([bdfhMnrV]+)$/);s&&(e=s[1],l=l.slice(0,-e.length)),e.includes("n")&&(r.numeric=!0),e.includes("r")&&(r.reverse=!0),e.includes("f")&&(r.ignoreCase=!0),e.includes("b")&&(r.ignoreLeading=!0),e.includes("h")&&(r.humanNumeric=!0),e.includes("V")&&(r.versionSort=!0),e.includes("d")&&(r.dictionaryOrder=!0),e.includes("M")&&(r.monthSort=!0);let i=l.split(",");if(i.length===0||i[0]==="")return null;let n=i[0].split("."),d=parseInt(n[0],10);if(Number.isNaN(d)||d<1)return null;if(r.startField=d,n.length>1&&n[1]){let o=parseInt(n[1],10);!Number.isNaN(o)&&o>=1&&(r.startChar=o)}if(i.length>1&&i[1]){let o=i[1],c=o.match(/([bdfhMnrV]+)$/);if(c){let a=c[1];a.includes("n")&&(r.numeric=!0),a.includes("r")&&(r.reverse=!0),a.includes("f")&&(r.ignoreCase=!0),a.includes("b")&&(r.ignoreLeading=!0),a.includes("h")&&(r.humanNumeric=!0),a.includes("V")&&(r.versionSort=!0),a.includes("d")&&(r.dictionaryOrder=!0),a.includes("M")&&(r.monthSort=!0),o=o.slice(0,-a.length)}let t=o.split(".");if(t[0]){let a=parseInt(t[0],10);if(!Number.isNaN(a)&&a>=1&&(r.endField=a),t.length>1&&t[1]){let f=parseInt(t[1],10);!Number.isNaN(f)&&f>=1&&(r.endChar=f)}}}return r}var q={name:"sort",summary:"sort lines of text files",usage:"sort [OPTION]... [FILE]...",options:["-b, --ignore-leading-blanks ignore leading blanks","-d, --dictionary-order consider only blanks and alphanumeric characters","-f, --ignore-case fold lower case to upper case characters","-h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)","-M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'","-n, --numeric-sort compare according to string numerical value","-r, --reverse reverse the result of comparisons","-V, --version-sort natural sort of (version) numbers within text","-c, --check check for sorted input; do not sort","-o, --output=FILE write result to FILE instead of stdout","-s, --stable stabilize sort by disabling last-resort comparison","-u, --unique output only unique lines","-k, --key=KEYDEF sort via a key; KEYDEF gives location and type","-t, --field-separator=SEP use SEP as field separator"," --help display this help and exit"],description:`KEYDEF is F[.C][OPTS][,F[.C][OPTS]]
3
- F is a field number (1-indexed)
4
- C is a character position within the field (1-indexed)
5
- OPTS can be: b d f h M n r V (per-key modifiers)
6
-
7
- Examples:
8
- -k1 sort by first field
9
- -k2,2 sort by second field only
10
- -k1.3 sort by first field starting at 3rd character
11
- -k1,2n sort by fields 1-2 numerically
12
- -k2 -k1 sort by field 2, then by field 1`},j={name:"sort",async execute(u,r){if(N(u))return F(q);let e={reverse:!1,numeric:!1,unique:!1,ignoreCase:!1,humanNumeric:!1,versionSort:!1,dictionaryOrder:!1,monthSort:!1,ignoreLeadingBlanks:!1,stable:!1,checkOnly:!1,outputFile:null,keys:[],fieldDelimiter:null},l=[];for(let c=0;c<u.length;c++){let t=u[c];if(t==="-r"||t==="--reverse")e.reverse=!0;else if(t==="-n"||t==="--numeric-sort")e.numeric=!0;else if(t==="-u"||t==="--unique")e.unique=!0;else if(t==="-f"||t==="--ignore-case")e.ignoreCase=!0;else if(t==="-h"||t==="--human-numeric-sort")e.humanNumeric=!0;else if(t==="-V"||t==="--version-sort")e.versionSort=!0;else if(t==="-d"||t==="--dictionary-order")e.dictionaryOrder=!0;else if(t==="-M"||t==="--month-sort")e.monthSort=!0;else if(t==="-b"||t==="--ignore-leading-blanks")e.ignoreLeadingBlanks=!0;else if(t==="-s"||t==="--stable")e.stable=!0;else if(t==="-c"||t==="--check")e.checkOnly=!0;else if(t==="-o"||t==="--output")e.outputFile=u[++c]||null;else if(t.startsWith("-o"))e.outputFile=t.slice(2)||null;else if(t.startsWith("--output="))e.outputFile=t.slice(9)||null;else if(t==="-t"||t==="--field-separator")e.fieldDelimiter=u[++c]||null;else if(t.startsWith("-t"))e.fieldDelimiter=t.slice(2)||null;else if(t.startsWith("--field-separator="))e.fieldDelimiter=t.slice(18)||null;else if(t==="-k"||t==="--key"){let a=u[++c];if(a){let f=C(a);f&&e.keys.push(f)}}else if(t.startsWith("-k")){let a=C(t.slice(2));a&&e.keys.push(a)}else if(t.startsWith("--key=")){let a=C(t.slice(6));a&&e.keys.push(a)}else{if(t.startsWith("--"))return k("sort",t);if(t.startsWith("-")&&!t.startsWith("--")){let a=!1;for(let f of t.slice(1))if(f==="r")e.reverse=!0;else if(f==="n")e.numeric=!0;else if(f==="u")e.unique=!0;else if(f==="f")e.ignoreCase=!0;else if(f==="h")e.humanNumeric=!0;else if(f==="V")e.versionSort=!0;else if(f==="d")e.dictionaryOrder=!0;else if(f==="M")e.monthSort=!0;else if(f==="b")e.ignoreLeadingBlanks=!0;else if(f==="s")e.stable=!0;else if(f==="c")e.checkOnly=!0;else{a=!0;break}if(a)return k("sort",t)}else l.push(t)}}let s=await O(r,l,{cmdName:"sort"});if(!s.ok)return s.error;let n=s.content.split(`
13
- `);n.length>0&&n[n.length-1]===""&&n.pop();let d=M(e);if(e.checkOnly){let c=l.length>0?l[0]:"-";for(let t=1;t<n.length;t++)if(d(n[t-1],n[t])>0)return{stdout:"",stderr:`sort: ${c}:${t+1}: disorder: ${n[t]}
14
- `,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}n.sort(d),e.unique&&(n=E(n,e));let o=n.length>0?`${n.join(`
15
- `)}
16
- `:"";if(e.outputFile){let c=r.fs.resolvePath(r.cwd,e.outputFile);return await r.fs.writeFile(c,o),{stdout:"",stderr:"",exitCode:0}}return{stdout:o,stderr:"",exitCode:0}}};export{j as sortCommand};
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as N,b as U}from"./chunk-GTNBSMZR.js";import{a as b,c as h,e as _e}from"./chunk-KGOUQS5A.js";var y=h(q=>{"use strict";q.getBooleanOption=(e,t)=>{let r=!1;if(t in e&&typeof(r=e[t])!="boolean")throw new TypeError(`Expected the "${t}" option to be a boolean`);return r};q.cppdb=Symbol();q.inspect=Symbol.for("nodejs.util.inspect.custom")});var D=h((It,W)=>{"use strict";var B={value:"SqliteError",writable:!0,enumerable:!1,configurable:!0};function T(e,t){if(new.target!==T)return new T(e,t);if(typeof t!="string")throw new TypeError("Expected second argument to be a string");Error.call(this,e),B.value=""+e,Object.defineProperty(this,"message",B),Error.captureStackTrace(this,T),this.code=t}Object.setPrototypeOf(T,Error);Object.setPrototypeOf(T.prototype,Error.prototype);Object.defineProperty(T.prototype,"name",B);W.exports=T});var Q=h((_t,z)=>{var I=b("path").sep||"/";z.exports=ve;function ve(e){if(typeof e!="string"||e.length<=7||e.substring(0,7)!="file://")throw new TypeError("must pass in a file:// URI to convert to a file path");var t=decodeURI(e.substring(7)),r=t.indexOf("/"),n=t.substring(0,r),i=t.substring(r+1);return n=="localhost"&&(n=""),n&&(n=I+I+n),i=i.replace(/^(.+)\|/,"$1:"),I=="\\"&&(i=i.replace(/\//g,"\\")),/^.+\:/.test(i)||(i=I+i),n+i}});var K=h((O,G)=>{var k=b("fs"),v=b("path"),Ce=Q(),_=v.join,Le=v.dirname,H=k.accessSync&&function(e){try{k.accessSync(e)}catch{return!1}return!0}||k.existsSync||v.existsSync,J={arrow:process.env.NODE_BINDINGS_ARROW||" \u2192 ",compiled:process.env.NODE_BINDINGS_COMPILED_DIR||"compiled",platform:process.platform,arch:process.arch,nodePreGyp:"node-v"+process.versions.modules+"-"+process.platform+"-"+process.arch,version:process.versions.node,bindings:"bindings.node",try:[["module_root","build","bindings"],["module_root","build","Debug","bindings"],["module_root","build","Release","bindings"],["module_root","out","Debug","bindings"],["module_root","Debug","bindings"],["module_root","out","Release","bindings"],["module_root","Release","bindings"],["module_root","build","default","bindings"],["module_root","compiled","version","platform","arch","bindings"],["module_root","addon-build","release","install-root","bindings"],["module_root","addon-build","debug","install-root","bindings"],["module_root","addon-build","default","install-root","bindings"],["module_root","lib","binding","nodePreGyp","bindings"]]};function Re(e){typeof e=="string"?e={bindings:e}:e||(e={}),Object.keys(J).map(function(l){l in e||(e[l]=J[l])}),e.module_root||(e.module_root=O.getRoot(O.getFileName())),v.extname(e.bindings)!=".node"&&(e.bindings+=".node");for(var t=typeof __webpack_require__=="function"?__non_webpack_require__:b,r=[],n=0,i=e.try.length,o,a,s;n<i;n++){o=_.apply(null,e.try[n].map(function(l){return e[l]||l})),r.push(o);try{return a=e.path?t.resolve(o):t(o),e.path||(a.path=o),a}catch(l){if(l.code!=="MODULE_NOT_FOUND"&&l.code!=="QUALIFIED_PATH_RESOLUTION_FAILED"&&!/not find/i.test(l.message))throw l}}throw s=new Error(`Could not locate the bindings file. Tried:
3
- `+r.map(function(l){return e.arrow+l}).join(`
4
- `)),s.tries=r,s}G.exports=O=Re;O.getFileName=function(t){var r=Error.prepareStackTrace,n=Error.stackTraceLimit,i={},o;Error.stackTraceLimit=10,Error.prepareStackTrace=function(s,l){for(var u=0,c=l.length;u<c;u++)if(o=l[u].getFileName(),o!==__filename)if(t){if(o!==t)return}else return},Error.captureStackTrace(i),i.stack,Error.prepareStackTrace=r,Error.stackTraceLimit=n;var a="file://";return o.indexOf(a)===0&&(o=Ce(o)),o};O.getRoot=function(t){for(var r=Le(t),n;;){if(r==="."&&(r=process.cwd()),H(_(r,"package.json"))||H(_(r,"node_modules")))return r;if(n===r)throw new Error('Could not find module root given file: "'+t+'". Do you have a `package.json` file? ');n=r,r=_(r,"..")}}});var X=h(E=>{"use strict";var{cppdb:w}=y();E.prepare=function(t){return this[w].prepare(t,this,!1)};E.exec=function(t){return this[w].exec(t),this};E.close=function(){return this[w].close(),this};E.loadExtension=function(...t){return this[w].loadExtension(...t),this};E.defaultSafeIntegers=function(...t){return this[w].defaultSafeIntegers(...t),this};E.unsafeMode=function(...t){return this[w].unsafeMode(...t),this};E.getters={name:{get:function(){return this[w].name},enumerable:!0},open:{get:function(){return this[w].open},enumerable:!0},inTransaction:{get:function(){return this[w].inTransaction},enumerable:!0},readonly:{get:function(){return this[w].readonly},enumerable:!0},memory:{get:function(){return this[w].memory},enumerable:!0}}});var ee=h((Lt,Z)=>{"use strict";var{cppdb:Ae}=y(),Y=new WeakMap;Z.exports=function(t){if(typeof t!="function")throw new TypeError("Expected first argument to be a function");let r=this[Ae],n=Ve(r,this),{apply:i}=Function.prototype,o={default:{value:C(i,t,r,n.default)},deferred:{value:C(i,t,r,n.deferred)},immediate:{value:C(i,t,r,n.immediate)},exclusive:{value:C(i,t,r,n.exclusive)},database:{value:this,enumerable:!0}};return Object.defineProperties(o.default.value,o),Object.defineProperties(o.deferred.value,o),Object.defineProperties(o.immediate.value,o),Object.defineProperties(o.exclusive.value,o),o.default.value};var Ve=(e,t)=>{let r=Y.get(e);if(!r){let n={commit:e.prepare("COMMIT",t,!1),rollback:e.prepare("ROLLBACK",t,!1),savepoint:e.prepare("SAVEPOINT ` _bs3. `",t,!1),release:e.prepare("RELEASE ` _bs3. `",t,!1),rollbackTo:e.prepare("ROLLBACK TO ` _bs3. `",t,!1)};Y.set(e,r={default:Object.assign({begin:e.prepare("BEGIN",t,!1)},n),deferred:Object.assign({begin:e.prepare("BEGIN DEFERRED",t,!1)},n),immediate:Object.assign({begin:e.prepare("BEGIN IMMEDIATE",t,!1)},n),exclusive:Object.assign({begin:e.prepare("BEGIN EXCLUSIVE",t,!1)},n)})}return r},C=(e,t,r,{begin:n,commit:i,rollback:o,savepoint:a,release:s,rollbackTo:l})=>function(){let c,p,j;r.inTransaction?(c=a,p=s,j=l):(c=n,p=i,j=o),c.run();try{let m=e.call(t,this,arguments);if(m&&typeof m.then=="function")throw new TypeError("Transaction function cannot return a promise");return p.run(),m}catch(m){throw r.inTransaction&&(j.run(),j!==o&&p.run()),m}}});var re=h((Rt,te)=>{"use strict";var{getBooleanOption:Be,cppdb:De}=y();te.exports=function(t,r){if(r==null&&(r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");let n=Be(r,"simple"),i=this[De].prepare(`PRAGMA ${t}`,this,!0);return n?i.pluck().get():i.all()}});var ie=h((At,oe)=>{"use strict";var ke=b("fs"),Pe=b("path"),{promisify:Me}=b("util"),{cppdb:Fe}=y(),ne=Me(ke.access);oe.exports=async function(t,r){if(r==null&&(r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");t=t.trim();let n="attached"in r?r.attached:"main",i="progress"in r?r.progress:null;if(!t)throw new TypeError("Backup filename cannot be an empty string");if(t===":memory:")throw new TypeError('Invalid backup filename ":memory:"');if(typeof n!="string")throw new TypeError('Expected the "attached" option to be a string');if(!n)throw new TypeError('The "attached" option cannot be an empty string');if(i!=null&&typeof i!="function")throw new TypeError('Expected the "progress" option to be a function');await ne(Pe.dirname(t)).catch(()=>{throw new TypeError("Cannot save backup because the directory does not exist")});let o=await ne(t).then(()=>!1,()=>!0);return Ne(this[Fe].backup(this,n,t,o),i||null)};var Ne=(e,t)=>{let r=0,n=!0;return new Promise((i,o)=>{setImmediate(function a(){try{let s=e.transfer(r);if(!s.remainingPages){e.close(),i(s);return}if(n&&(n=!1,r=100),t){let l=t(s);if(l!==void 0)if(typeof l=="number"&&l===l)r=Math.max(0,Math.min(2147483647,Math.round(l)));else throw new TypeError("Expected progress callback to return a number or undefined")}setImmediate(a)}catch(s){e.close(),o(s)}})})}});var ae=h((Vt,se)=>{"use strict";var{cppdb:Ue}=y();se.exports=function(t){if(t==null&&(t={}),typeof t!="object")throw new TypeError("Expected first argument to be an options object");let r="attached"in t?t.attached:"main";if(typeof r!="string")throw new TypeError('Expected the "attached" option to be a string');if(!r)throw new TypeError('The "attached" option cannot be an empty string');return this[Ue].serialize(r)}});var ue=h((Bt,le)=>{"use strict";var{getBooleanOption:L,cppdb:We}=y();le.exports=function(t,r,n){if(r==null&&(r={}),typeof r=="function"&&(n=r,r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof n!="function")throw new TypeError("Expected last argument to be a function");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");if(!t)throw new TypeError("User-defined function name cannot be an empty string");let i="safeIntegers"in r?+L(r,"safeIntegers"):2,o=L(r,"deterministic"),a=L(r,"directOnly"),s=L(r,"varargs"),l=-1;if(!s){if(l=n.length,!Number.isInteger(l)||l<0)throw new TypeError("Expected function.length to be a positive integer");if(l>100)throw new RangeError("User-defined functions cannot have more than 100 arguments")}return this[We].function(n,t,l,i,o,a),this}});var pe=h((Dt,fe)=>{"use strict";var{getBooleanOption:R,cppdb:ze}=y();fe.exports=function(t,r){if(typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object"||r===null)throw new TypeError("Expected second argument to be an options object");if(!t)throw new TypeError("User-defined function name cannot be an empty string");let n="start"in r?r.start:null,i=P(r,"step",!0),o=P(r,"inverse",!1),a=P(r,"result",!1),s="safeIntegers"in r?+R(r,"safeIntegers"):2,l=R(r,"deterministic"),u=R(r,"directOnly"),c=R(r,"varargs"),p=-1;if(!c&&(p=Math.max(ce(i),o?ce(o):0),p>0&&(p-=1),p>100))throw new RangeError("User-defined functions cannot have more than 100 arguments");return this[ze].aggregate(n,i,o,a,t,p,s,l,u),this};var P=(e,t,r)=>{let n=t in e?e[t]:null;if(typeof n=="function")return n;if(n!=null)throw new TypeError(`Expected the "${t}" option to be a function`);if(r)throw new TypeError(`Missing required option "${t}"`);return null},ce=({length:e})=>{if(Number.isInteger(e)&&e>=0)return e;throw new TypeError("Expected function.length to be a positive integer")}});var ge=h((kt,me)=>{"use strict";var{cppdb:Qe}=y();me.exports=function(t,r){if(typeof t!="string")throw new TypeError("Expected first argument to be a string");if(!t)throw new TypeError("Virtual table module name cannot be an empty string");let n=!1;if(typeof r=="object"&&r!==null)n=!0,r=et(he(r,"used",t));else{if(typeof r!="function")throw new TypeError("Expected second argument to be a function or a table definition object");r=He(r)}return this[Qe].table(r,t,n),this};function He(e){return function(r,n,i,...o){let a={module:r,database:n,table:i},s=Ye.call(e,a,o);if(typeof s!="object"||s===null)throw new TypeError(`Virtual table module "${r}" did not return a table definition object`);return he(s,"returned",r)}}function he(e,t,r){if(!S.call(e,"rows"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition without a "rows" property`);if(!S.call(e,"columns"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition without a "columns" property`);let n=e.rows;if(typeof n!="function"||Object.getPrototypeOf(n)!==Ze)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "rows" property (should be a generator function)`);let i=e.columns;if(!Array.isArray(i)||!(i=[...i]).every(u=>typeof u=="string"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "columns" property (should be an array of strings)`);if(i.length!==new Set(i).size)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with duplicate column names`);if(!i.length)throw new RangeError(`Virtual table module "${r}" ${t} a table definition with zero columns`);let o;if(S.call(e,"parameters")){if(o=e.parameters,!Array.isArray(o)||!(o=[...o]).every(u=>typeof u=="string"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "parameters" property (should be an array of strings)`)}else o=Xe(n);if(o.length!==new Set(o).size)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with duplicate parameter names`);if(o.length>32)throw new RangeError(`Virtual table module "${r}" ${t} a table definition with more than the maximum number of 32 parameters`);for(let u of o)if(i.includes(u))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with column "${u}" which was ambiguously defined as both a column and parameter`);let a=2;if(S.call(e,"safeIntegers")){let u=e.safeIntegers;if(typeof u!="boolean")throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "safeIntegers" property (should be a boolean)`);a=+u}let s=!1;if(S.call(e,"directOnly")&&(s=e.directOnly,typeof s!="boolean"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "directOnly" property (should be a boolean)`);return[`CREATE TABLE x(${[...o.map(de).map(u=>`${u} HIDDEN`),...i.map(de)].join(", ")});`,Je(n,new Map(i.map((u,c)=>[u,o.length+c])),r),o,a,s]}function Je(e,t,r){return function*(...i){let o=i.map(a=>Buffer.isBuffer(a)?Buffer.from(a):a);for(let a=0;a<t.size;++a)o.push(null);for(let a of e(...i))if(Array.isArray(a))Ge(a,o,t.size,r),yield o;else if(typeof a=="object"&&a!==null)Ke(a,o,t,r),yield o;else throw new TypeError(`Virtual table module "${r}" yielded something that isn't a valid row object`)}}function Ge(e,t,r,n){if(e.length!==r)throw new TypeError(`Virtual table module "${n}" yielded a row with an incorrect number of columns`);let i=t.length-r;for(let o=0;o<r;++o)t[o+i]=e[o]}function Ke(e,t,r,n){let i=0;for(let o of Object.keys(e)){let a=r.get(o);if(a===void 0)throw new TypeError(`Virtual table module "${n}" yielded a row with an undeclared column "${o}"`);t[a]=e[o],i+=1}if(i!==r.size)throw new TypeError(`Virtual table module "${n}" yielded a row with missing columns`)}function Xe({length:e}){if(!Number.isInteger(e)||e<0)throw new TypeError("Expected function.length to be a positive integer");let t=[];for(let r=0;r<e;++r)t.push(`$${r+1}`);return t}var{hasOwnProperty:S}=Object.prototype,{apply:Ye}=Function.prototype,Ze=Object.getPrototypeOf(function*(){}),de=e=>`"${e.replace(/"/g,'""')}"`,et=e=>()=>e});var we=h((Pt,be)=>{"use strict";var tt=function(){};be.exports=function(t,r){return Object.assign(new tt,this)}});var xe=h((Mt,Te)=>{"use strict";var rt=b("fs"),ye=b("path"),A=y(),nt=D(),Ee;function f(e,t){if(new.target==null)return new f(e,t);let r;if(Buffer.isBuffer(e)&&(r=e,e=":memory:"),e==null&&(e=""),t==null&&(t={}),typeof e!="string")throw new TypeError("Expected first argument to be a string");if(typeof t!="object")throw new TypeError("Expected second argument to be an options object");if("readOnly"in t)throw new TypeError('Misspelled option "readOnly" should be "readonly"');if("memory"in t)throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');let n=e.trim(),i=n===""||n===":memory:",o=A.getBooleanOption(t,"readonly"),a=A.getBooleanOption(t,"fileMustExist"),s="timeout"in t?t.timeout:5e3,l="verbose"in t?t.verbose:null,u="nativeBinding"in t?t.nativeBinding:null;if(o&&i&&!r)throw new TypeError("In-memory/temporary databases cannot be readonly");if(!Number.isInteger(s)||s<0)throw new TypeError('Expected the "timeout" option to be a positive integer');if(s>2147483647)throw new RangeError('Option "timeout" cannot be greater than 2147483647');if(l!=null&&typeof l!="function")throw new TypeError('Expected the "verbose" option to be a function');if(u!=null&&typeof u!="string"&&typeof u!="object")throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');let c;if(u==null?c=Ee||(Ee=K()("better_sqlite3.node")):typeof u=="string"?c=(typeof __non_webpack_require__=="function"?__non_webpack_require__:b)(ye.resolve(u).replace(/(\.node)?$/,".node")):c=u,c.isInitialized||(c.setErrorConstructor(nt),c.isInitialized=!0),!i&&!rt.existsSync(ye.dirname(n)))throw new TypeError("Cannot open database because the directory does not exist");Object.defineProperties(this,{[A.cppdb]:{value:new c.Database(n,e,i,o,a,s,l||null,r||null)},...x.getters})}var x=X();f.prototype.prepare=x.prepare;f.prototype.transaction=ee();f.prototype.pragma=re();f.prototype.backup=ie();f.prototype.serialize=ae();f.prototype.function=ue();f.prototype.aggregate=pe();f.prototype.table=ge();f.prototype.loadExtension=x.loadExtension;f.prototype.exec=x.exec;f.prototype.close=x.close;f.prototype.defaultSafeIntegers=x.defaultSafeIntegers;f.prototype.unsafeMode=x.unsafeMode;f.prototype[A.inspect]=we();Te.exports=f});var je=h((Nt,M)=>{"use strict";M.exports=xe();M.exports.SqliteError=D()});var V=_e(je(),1);import{fileURLToPath as bt}from"node:url";import{Worker as wt}from"node:worker_threads";function Se(e,t,r){switch(r.mode){case"list":return ot(e,t,r);case"csv":return it(e,t,r);case"json":return at(e,t);case"line":return lt(e,t,r);case"column":return ut(e,t,r);case"table":return ct(e,t,r);case"markdown":return ft(e,t,r);case"tabs":return pt(e,t,r);case"box":return dt(e,t,r);case"quote":return ht(e,t,r);case"html":return mt(e,t,r);case"ascii":return gt(e,t,r)}}function g(e,t){return e==null?t:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function ot(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(r.separator));for(let i of t)n.push(i.map(o=>g(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function it(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map($e).join(","));for(let i of t)n.push(i.map(o=>$e(g(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
5
- `)}
6
- `:""}function $e(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
7
- `)?`"${e.replace(/"/g,'""')}"`:e}function qe(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function st(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):qe(e):JSON.stringify(e)}function at(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,a)=>`${JSON.stringify(o)}:${st(n[a])}`).join(",")}}`).join(`,
8
- `)}]
9
- `}function lt(e,t,r){if(e.length===0||t.length===0)return"";let n=Math.max(5,...e.map(o=>o.length)),i=[];for(let o of t)for(let a=0;a<e.length;a++){let s=e[a].padStart(n);i.push(`${s} = ${g(o[a],r.nullValue)}`)}return`${i.join(`
10
- `)}
11
- `}function ut(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let a=0;a<o.length;a++){let s=g(o[a],r.nullValue).length;s>n[a]&&(n[a]=s)}let i=[];r.header&&(i.push(e.map((o,a)=>o.padEnd(n[a])).join(" ")),i.push(n.map(o=>"-".repeat(o)).join(" ")));for(let o of t)i.push(o.map((a,s)=>g(a,r.nullValue).padEnd(n[s])).join(" "));return i.length>0?`${i.join(`
12
- `)}
13
- `:""}function ct(e,t,r){if(e.length===0)return"";let n=e.map(a=>a.length);for(let a of t)for(let s=0;s<a.length;s++){let l=g(a[s],r.nullValue).length;l>n[s]&&(n[s]=l)}let i=[],o=`+${n.map(a=>"-".repeat(a+2)).join("+")}+`;i.push(o),r.header&&(i.push(`| ${e.map((a,s)=>a.padEnd(n[s])).join(" | ")} |`),i.push(o));for(let a of t)i.push(`| ${a.map((s,l)=>g(s,r.nullValue).padEnd(n[l])).join(" | ")} |`);return i.push(o),`${i.join(`
14
- `)}
15
- `}function ft(e,t,r){if(e.length===0)return"";let n=[];r.header&&(n.push(`| ${e.join(" | ")} |`),n.push(`|${e.map(()=>"---").join("|")}|`));for(let i of t)n.push(`| ${i.map(o=>g(o,r.nullValue)).join(" | ")} |`);return n.length>0?`${n.join(`
16
- `)}
17
- `:""}function pt(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(" "));for(let i of t)n.push(i.map(o=>g(o,r.nullValue)).join(" "));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function dt(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let a=0;a<o.length;a++){let s=g(o[a],r.nullValue).length;s>n[a]&&(n[a]=s)}let i=[];i.push(`\u250C${n.map(o=>"\u2500".repeat(o+2)).join("\u252C")}\u2510`),i.push(`\u2502 ${e.map((o,a)=>o.padEnd(n[a])).join(" \u2502 ")} \u2502`),i.push(`\u251C${n.map(o=>"\u2500".repeat(o+2)).join("\u253C")}\u2524`);for(let o of t)i.push(`\u2502 ${o.map((a,s)=>g(a,r.nullValue).padEnd(n[s])).join(" \u2502 ")} \u2502`);return i.push(`\u2514${n.map(o=>"\u2500".repeat(o+2)).join("\u2534")}\u2518`),`${i.join(`
18
- `)}
19
- `}function ht(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(i=>`'${i}'`).join(","));for(let i of t)n.push(i.map(o=>o==null?"NULL":typeof o=="number"?Number.isInteger(o)?String(o):qe(o):`'${String(o)}'`).join(","));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function mt(e,t,r){let n=[];r.header&&e.length>0&&(n.push(`<TR>${e.map(i=>`<TH>${Oe(i)}</TH>`).join("")}`),n.push("</TR>"));for(let i of t)n.push(`<TR>${i.map(o=>`<TD>${Oe(g(o,r.nullValue))}</TD>`).join("")}`),n.push("</TR>");return n.length>0?`${n.join(`
20
- `)}
21
- `:""}function Oe(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function gt(e,t,r){let o=[];r.header&&e.length>0&&o.push(e.join(""));for(let a of t)o.push(a.map(s=>g(s,r.nullValue)).join(""));return o.length>0?o.join("")+"":""}var yt=5e3,Et={name:"sqlite3",summary:"SQLite database CLI",usage:"sqlite3 [OPTIONS] DATABASE [SQL]",options:["-list output in list mode (default)","-csv output in CSV mode","-json output in JSON mode","-line output in line mode","-column output in column mode","-table output as ASCII table","-markdown output as markdown table","-tabs output in tab-separated mode","-box output in Unicode box mode","-quote output in SQL quote mode","-html output as HTML table","-ascii output in ASCII mode (control chars)","-header show column headers","-noheader hide column headers","-separator SEP field separator for list mode (default: |)","-newline SEP row separator (default: \\n)","-nullvalue TEXT text for NULL values (default: empty)","-readonly open database read-only (no writeback)","-bail stop on first error","-echo print SQL before execution","-cmd COMMAND run SQL command before main SQL","-version show SQLite version","-- end of options","--help show this help"],examples:['sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"','sqlite3 -json data.db "SELECT * FROM users"','sqlite3 -csv -header data.db "SELECT id, name FROM products"','sqlite3 -box data.db "SELECT * FROM users"']};function Tt(e){let t={mode:"list",header:!1,separator:"|",newline:`
22
- `,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},r=null,n=null,i=!1,o=!1;for(let a=0;a<e.length;a++){let s=e[a];if(o){r===null?r=s:n===null&&(n=s);continue}if(s==="--")o=!0;else if(s==="-version")i=!0;else if(s==="-list")t.mode="list";else if(s==="-csv")t.mode="csv";else if(s==="-json")t.mode="json";else if(s==="-line")t.mode="line";else if(s==="-column")t.mode="column";else if(s==="-table")t.mode="table";else if(s==="-markdown")t.mode="markdown";else if(s==="-tabs")t.mode="tabs";else if(s==="-box")t.mode="box";else if(s==="-quote")t.mode="quote";else if(s==="-html")t.mode="html";else if(s==="-ascii")t.mode="ascii";else if(s==="-header")t.header=!0;else if(s==="-noheader")t.header=!1;else if(s==="-readonly")t.readonly=!0;else if(s==="-bail")t.bail=!0;else if(s==="-echo")t.echo=!0;else if(s==="-separator"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
23
- `,exitCode:1};t.separator=e[++a]}else if(s==="-newline"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
24
- `,exitCode:1};t.newline=e[++a]}else if(s==="-nullvalue"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
25
- `,exitCode:1};t.nullValue=e[++a]}else if(s==="-cmd"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
26
- `,exitCode:1};t.cmd=e[++a]}else{if(s.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${s.startsWith("--")?s.slice(1):s}
27
- Use -help for a list of options.
28
- `,exitCode:1};r===null?r=s:n===null&&(n=s)}}return{options:t,database:r,sql:n,showVersion:i}}function xt(){let e=new V.default(":memory:");try{return e.prepare("SELECT sqlite_version()").get()["sqlite_version()"]}finally{e.close()}}function jt(e){let t;try{e.dbBuffer?t=new V.default(Buffer.from(e.dbBuffer)):t=new V.default(":memory:")}catch(i){return{success:!1,error:i.message}}let r=[],n=!1;try{let i=Ot(e.sql);for(let a of i)try{if($t(a))t.exec(a),n=!0,r.push({type:"data",columns:[],rows:[]});else{let s=t.prepare(a),u=s.columns().map(p=>p.name),c=s.raw(!0).all();r.push({type:"data",columns:u,rows:c})}}catch(s){let l=s.message;if(r.push({type:"error",error:l}),e.options.bail)break}let o=null;return n&&(o=t.serialize()),t.close(),{success:!0,results:r,hasModifications:n,dbBuffer:o}}catch(i){return t.close(),{success:!1,error:i.message}}}function $t(e){let t=e.trim().toUpperCase();return t.startsWith("INSERT")||t.startsWith("UPDATE")||t.startsWith("DELETE")||t.startsWith("CREATE")||t.startsWith("DROP")||t.startsWith("ALTER")||t.startsWith("REPLACE")}function Ot(e){let t=[],r="",n=!1,i="";for(let a=0;a<e.length;a++){let s=e[a];if(n)r+=s,s===i&&(e[a+1]===i?r+=e[++a]:n=!1);else if(s==="'"||s==='"')r+=s,n=!0,i=s;else if(s===";"){let l=r.trim();l&&t.push(l),r=""}else r+=s}let o=r.trim();return o&&t.push(o),t}async function St(e,t){try{let r=bt(new URL("./worker.js",import.meta.url));return await new Promise((n,i)=>{let o=new wt(r,{workerData:e}),a=setTimeout(()=>{o.terminate(),n({success:!1,error:`Query timeout: execution exceeded ${t}ms limit`})},t);o.on("message",s=>{clearTimeout(a),n(s)}),o.on("error",s=>{clearTimeout(a),i(s)}),o.on("exit",s=>{clearTimeout(a),s!==0&&n({success:!1,error:`Worker exited with code ${s}`})})})}catch{return jt(e)}}var Jt={name:"sqlite3",async execute(e,t){if(U(e)||e.includes("-help"))return N(Et);let r=Tt(e);if("exitCode"in r)return r;let{options:n,database:i,sql:o,showVersion:a}=r;if(a)return{stdout:`${xt()}
29
- `,stderr:"",exitCode:0};if(!i)return{stdout:"",stderr:`sqlite3: missing database argument
30
- `,exitCode:1};let s=o||t.stdin.trim();if(n.cmd&&(s=n.cmd+(s?`; ${s}`:"")),!s)return{stdout:"",stderr:`sqlite3: no SQL provided
31
- `,exitCode:1};let l=i===":memory:",u="",c=null;try{l||(u=t.fs.resolvePath(t.cwd,i),await t.fs.exists(u)&&(c=await t.fs.readFileBuffer(u)))}catch(d){return{stdout:"",stderr:`sqlite3: unable to open database "${i}": ${d.message}
32
- `,exitCode:1}}let p=t.limits?.maxSqliteTimeoutMs??yt,j={dbBuffer:c,sql:s,options:{bail:n.bail,echo:n.echo}},m;try{m=await St(j,p)}catch(d){return{stdout:"",stderr:`sqlite3: worker error: ${d.message}
33
- `,exitCode:1}}if(!m.success)return{stdout:"",stderr:`sqlite3: ${m.error}
34
- `,exitCode:1};let Ie={mode:n.mode,header:n.header,separator:n.separator,newline:n.newline,nullValue:n.nullValue},$="";n.echo&&($+=`${s}
35
- `);let F=!1;for(let d of m.results)if(d.type==="error"){if(n.bail)return{stdout:$,stderr:`Error: ${d.error}
36
- `,exitCode:1};$+=`Error: ${d.error}
37
- `,F=!0}else d.columns&&d.rows&&(d.rows.length>0||n.header)&&($+=Se(d.columns,d.rows,Ie));if(m.hasModifications&&!n.readonly&&!l&&u&&m.dbBuffer)try{await t.fs.writeFile(u,m.dbBuffer)}catch(d){return{stdout:$,stderr:`sqlite3: failed to write database: ${d.message}
38
- `,exitCode:1}}return{stdout:$,stderr:"",exitCode:F&&n.bail?1:0}}};export{Jt as sqlite3Command};