From aec56431d7d9b6fcb141bbfe25d26f4931f54f80 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Mon, 29 Jun 2026 06:40:53 -0500 Subject: [PATCH 1/9] fix(interpreter): avoid lazy import in assignment path that trips defense-in-depth (#273) (#277) Any non-export variable assignment (bare SECRET=s, prefixed SECRET=s cmd, or before a custom command) failed under defense-in-depth with 'dynamic import of Node.js builtin node:module is blocked during script execution'. The assignment path resolved isArray via await import(./expansion.js), whose bundled chunk imports node:module via the createRequire banner; the defense ESM resolve hook blocked it. expansion.js is already statically imported, so isArray now comes from that static import and both lazy imports are removed. --- .changeset/assignment-lazy-import.md | 19 ++++++++ .../interpreter/simple-command-assignments.ts | 3 +- .../temp-env-prefix-defense.test.ts | 46 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .changeset/assignment-lazy-import.md create mode 100644 packages/just-bash/src/interpreter/temp-env-prefix-defense.test.ts diff --git a/.changeset/assignment-lazy-import.md b/.changeset/assignment-lazy-import.md new file mode 100644 index 00000000..575bbd2d --- /dev/null +++ b/.changeset/assignment-lazy-import.md @@ -0,0 +1,19 @@ +--- +"just-bash": patch +--- + +interpreter: avoid lazy import in variable assignment path that trips defense-in-depth (fixes #273) + +Any non-`export` variable assignment (bare `SECRET=s`, prefixed `SECRET=s cmd`, +or before a custom command) failed with a defense-in-depth security violation +(`dynamic import of Node.js builtin 'node:module' is blocked during script +execution`), while plain commands and `export`-ed assignments passed. + +`processScalarAssignment()` resolved `isArray` via `await import("./expansion.js")` +in two spots. In the bundled `dist`, that dynamic `import()` marks `expansion.js` +as a lazily-linked chunk whose `createRequire` banner imports `node:module`; the +defense layer's ESM `resolve` hook blocks that builtin import when the sandbox is +active and untrusted, so it blocked just-bash's own chunk load. The file already +statically imports from `./expansion.js`, so `isArray` is now pulled from that +static import and the two lazy imports are removed — no lazy `node:module`-bearing +chunk is linked at runtime. No public API change. diff --git a/packages/just-bash/src/interpreter/simple-command-assignments.ts b/packages/just-bash/src/interpreter/simple-command-assignments.ts index 358d755c..9a9192e8 100644 --- a/packages/just-bash/src/interpreter/simple-command-assignments.ts +++ b/packages/just-bash/src/interpreter/simple-command-assignments.ts @@ -22,6 +22,7 @@ import { expandWord, expandWordWithGlob, getArrayElements, + isArray, } from "./expansion.js"; import { parseKeyedElementFromWord, @@ -785,7 +786,6 @@ async function processScalarAssignment( finalValue = "0"; } } else { - const { isArray } = await import("./expansion.js"); const appendKey = isArray(ctx, targetName) ? `${targetName}_0` : targetName; finalValue = append ? (ctx.state.env.get(appendKey) || "") + value : value; } @@ -799,7 +799,6 @@ async function processScalarAssignment( if (namerefArrayRef) { actualEnvKey = await computeNamerefArrayEnvKey(ctx, namerefArrayRef); } else { - const { isArray } = await import("./expansion.js"); if (isArray(ctx, targetName)) { actualEnvKey = `${targetName}_0`; } diff --git a/packages/just-bash/src/interpreter/temp-env-prefix-defense.test.ts b/packages/just-bash/src/interpreter/temp-env-prefix-defense.test.ts new file mode 100644 index 00000000..a167dd4d --- /dev/null +++ b/packages/just-bash/src/interpreter/temp-env-prefix-defense.test.ts @@ -0,0 +1,46 @@ +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { afterEach, describe, expect, it } from "vitest"; +import { Bash } from "../Bash.js"; +import { DefenseInDepthBox } from "../security/defense-in-depth-box.js"; + +describe("temp env prefix under defense-in-depth", () => { + afterEach(() => { + DefenseInDepthBox.resetInstance(); + }); + + it("runs a command with a leading env assignment", async () => { + const bash = new Bash({ defenseInDepth: true }); + const result = await bash.exec("FOO=bar true"); + + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(0); + }); + + it("passes the temp binding through to the command", async () => { + const bash = new Bash({ defenseInDepth: true }); + const result = await bash.exec("FOO=bar echo hi"); + + expect(result.stdout).toBe("hi\n"); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(0); + }); + + // Regression guard for the bundled-dist failure where a leading env + // assignment (`FOO=bar cmd`) threw "security violation: dynamic import of + // Node.js builtin 'node:module' is blocked during script execution". The + // assignment path used `await import("./expansion.js")`, which in the dist + // bundle links a lazy chunk whose static graph pulls in `node:module`; the + // defense-in-depth ESM resolve hook then blocked it. expansion.js is already + // statically imported here, so the lazy import must not be reintroduced. + it("does not lazily import sibling interpreter modules", () => { + const source = readFileSync( + fileURLToPath( + new URL("./simple-command-assignments.ts", import.meta.url), + ), + "utf8", + ); + expect(source).not.toMatch(/await\s+import\(/); + }); +}); From 1ec5eec0aefd099d23ac9f056df1e6612c81d49b Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Mon, 29 Jun 2026 15:09:10 -0500 Subject: [PATCH 2/9] fix(interpreter): preserve leading whitespace in multi-line quoted strings (#259) (#276) normalizeScript() trimStart()s leading indentation from script lines so indented template literals parse, but it ran line-by-line and also stripped leading whitespace inside multi-line single/double-quoted strings (e.g. python3 -c with an indented body -> IndentationError). Make it quote-aware, mirroring the earlier heredoc-aware fix: track open quote state across lines and only strip indentation from lines that begin outside any quote; lines that begin inside an unterminated quote are preserved verbatim. Un-skips four sed spec tests whose indented stdin was being corrupted. --- .changeset/multiline-quoted-whitespace.md | 18 +++++ packages/just-bash/src/Bash.ts | 69 +++++++++++++++++-- .../just-bash/src/spec-tests/sed/skips.ts | 16 ----- .../quoted-multiline-whitespace.test.ts | 56 +++++++++++++++ 4 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 .changeset/multiline-quoted-whitespace.md create mode 100644 packages/just-bash/src/syntax/quoted-multiline-whitespace.test.ts diff --git a/.changeset/multiline-quoted-whitespace.md b/.changeset/multiline-quoted-whitespace.md new file mode 100644 index 00000000..fb7c722c --- /dev/null +++ b/.changeset/multiline-quoted-whitespace.md @@ -0,0 +1,18 @@ +--- +"just-bash": patch +--- + +interpreter: preserve leading whitespace in multi-line quoted strings (fixes #259) + +`exec()` runs each script through `normalizeScript()`, which `trimStart()`s +leading indentation from lines so indented template-literal scripts parse. It +was applied line-by-line and stripped the leading whitespace inside multi-line +single- and double-quoted strings too. The visible symptom was `python3 -c +'...'` (and `node -e`, `awk`, etc.) with an indented body failing with +`IndentationError`, while the same code via heredoc or pipe worked. + +`normalizeScript()` is now quote-aware (mirroring the earlier heredoc-aware +fix): it only strips indentation from lines that begin outside any quote, and +preserves lines that begin inside an unterminated single- or double-quoted +string verbatim. This also un-skips four sed spec tests whose indented stdin +was previously being corrupted. diff --git a/packages/just-bash/src/Bash.ts b/packages/just-bash/src/Bash.ts index 171b79bc..f8100799 100644 --- a/packages/just-bash/src/Bash.ts +++ b/packages/just-bash/src/Bash.ts @@ -861,9 +861,51 @@ export class Bash { } } +type QuoteScanState = "none" | "single" | "double"; + +/** + * Track open single/double-quote state across one physical line, starting from + * `start` (the state carried over from the previous line). Used by + * normalizeScript to know whether a line begins inside a multi-line quoted + * string, where leading whitespace is literal and must not be trimmed. + * + * Only single and double quotes matter: those are the contexts where leading + * whitespace is significant. Backslash escapes and `#` comments are honored so + * a quote inside a comment (e.g. `# don't`) doesn't desync the state. + */ +function scanLineQuoteState( + line: string, + start: QuoteScanState, +): QuoteScanState { + let state = start; + for (let i = 0; i < line.length; i++) { + const ch = line[i]; + if (state === "single") { + // Inside single quotes only a closing quote is special (no escapes). + if (ch === "'") state = "none"; + } else if (state === "double") { + if (ch === "\\") { + i++; // backslash escapes the next char inside double quotes + } else if (ch === '"') { + state = "none"; + } + } else if (ch === "'") { + state = "single"; + } else if (ch === '"') { + state = "double"; + } else if (ch === "\\") { + i++; // backslash escapes the next char (e.g. \" or \') + } else if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) { + break; // start of a comment: the rest of the line is not shell-significant + } + } + return state; +} + /** - * Normalize a script by stripping leading whitespace from lines, - * while preserving whitespace inside heredoc content. + * Normalize a script by stripping leading whitespace from lines, while + * preserving whitespace inside heredoc content and inside multi-line quoted + * strings. * * This allows writing indented bash scripts in template literals: * ``` @@ -874,6 +916,11 @@ export class Bash { * `); * ``` * + * Leading whitespace is only stripped from lines that begin outside any quote. + * A line that begins inside an unterminated single- or double-quoted string is + * literal quoted content (e.g. the body of `python3 -c "..."`), so it is kept + * verbatim. + * * Heredocs are detected by looking for << or <<- operators and their delimiters. */ function normalizeScript(script: string): string { @@ -883,6 +930,10 @@ function normalizeScript(script: string): string { // Stack of pending heredoc delimiters (for nested heredocs) const pendingDelimiters: { delimiter: string; stripTabs: boolean }[] = []; + // Open single/double-quote state carried across lines. When a line begins + // inside an open quote, its leading whitespace is literal and preserved. + let quoteState: QuoteScanState = "none"; + for (let i = 0; i < lines.length; i++) { const line = lines[i]; @@ -903,9 +954,19 @@ function normalizeScript(script: string): string { continue; } - // Not inside a heredoc - normalize the line and check for heredoc starts - const normalizedLine = line.trimStart(); + // Not inside a heredoc. Lines that begin inside an open quote are literal + // quoted content (leading whitespace is significant), so preserve them + // verbatim; otherwise strip leading indentation. + const startState = quoteState; + const normalizedLine = startState === "none" ? line.trimStart() : line; result.push(normalizedLine); + quoteState = scanLineQuoteState(line, startState); + + // Only detect heredoc operators on lines that begin outside any quote; + // a `< = new Map([ // ============================================================ // PythonSed chang.suite - complex N/D/P scripts // ============================================================ - [ - "pythonsed-chang.suite:Delete two consecutive lines if the first one contains PAT1 and the second one contains PAT2.", - "N/P/D commands", - ], - [ - "pythonsed-chang.suite:Get the line following a line containing PAT - Case 1 - 1.", - "N/D commands", - ], [ "pythonsed-chang.suite:Remove comments (/* ... */, maybe multi-line) of a C program. - 1", "N command behavior", @@ -171,10 +163,6 @@ const SKIP_TESTS: Map = new Map([ "pythonsed-chang.suite:Join every N lines to one - 1.", "complex N/D branching", ], - [ - 'pythonsed-chang.suite:Extract "Received:" header(s) from a mailbox.', - "complex N/D branching", - ], [ "pythonsed-chang.suite:Extract every IMG elements from an HTML file.", "complex branching", @@ -183,10 +171,6 @@ const SKIP_TESTS: Map = new Map([ "pythonsed-chang.suite:Find failed instances without latter successful ones.", "complex N/D branching", ], - [ - "pythonsed-chang.suite:Change the first quote of every single-quoted string to backquote(`). - 1", - "complex pattern manipulation", - ], ["pythonsed-chang.suite:1 cat chicken", "test name parsing issue"], [ "pythonsed-chang.suite:First number 1111 Second <2222>", diff --git a/packages/just-bash/src/syntax/quoted-multiline-whitespace.test.ts b/packages/just-bash/src/syntax/quoted-multiline-whitespace.test.ts new file mode 100644 index 00000000..d2ed1cf5 --- /dev/null +++ b/packages/just-bash/src/syntax/quoted-multiline-whitespace.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it } from "vitest"; +import { Bash } from "../Bash.js"; + +// Regression tests: script normalization (which strips leading indentation so +// indented template literals parse) must NOT trim lines that begin inside a +// multi-line single- or double-quoted string. There the leading whitespace is +// literal (POSIX) and must be preserved verbatim, e.g. the body of +// `python3 -c '...'`. +describe("multi-line quoted string whitespace", () => { + it("preserves leading indentation inside a single-quoted string", async () => { + const env = new Bash(); + const result = await env.exec( + "printf '%s' 'import sys\nfor p in [1]:\n print(p)\n'", + ); + expect(result.stdout).toBe("import sys\nfor p in [1]:\n print(p)\n"); + expect(result.exitCode).toBe(0); + }); + + it("preserves leading indentation inside a double-quoted string", async () => { + const env = new Bash(); + const result = await env.exec( + 'printf "%s" "first\n second\n third\n"', + ); + expect(result.stdout).toBe("first\n second\n third\n"); + expect(result.exitCode).toBe(0); + }); + + it("preserves indentation through a variable assignment and expansion", async () => { + const env = new Bash(); + const result = await env.exec( + "v='a\n b\n c'\nprintf '%s' \"$v\"", + ); + expect(result.stdout).toBe("a\n b\n c"); + expect(result.exitCode).toBe(0); + }); + + it("still strips indentation from the surrounding (unquoted) script", async () => { + const env = new Bash(); + const result = await env.exec( + " if true; then\n printf '%s' ' keep'\n fi", + ); + expect(result.stdout).toBe(" keep"); + expect(result.exitCode).toBe(0); + }); + + it("is not confused by an apostrophe inside a comment", async () => { + const env = new Bash(); + // The `'` in the comment must not open a quote that swallows the next + // line's indentation handling. + const result = await env.exec( + "echo start # don't trip on this\n printf '%s' 'x\n y'", + ); + expect(result.stdout).toBe("start\nx\n y"); + expect(result.exitCode).toBe(0); + }); +}); From cb2b583b3f46e6bb4e6982c4bfe19903ec811a87 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 2 Jul 2026 22:40:10 +0900 Subject: [PATCH 3/9] fix(interpreter): deliver redirected output to each fd's final target (#286) --- .changeset/redirect-dup-routing.md | 28 ++ .../redirections.dup-routing.test.ts | 190 ++++++++++ .../just-bash/src/interpreter/redirections.ts | 339 +++++++++--------- 3 files changed, 384 insertions(+), 173 deletions(-) create mode 100644 .changeset/redirect-dup-routing.md create mode 100644 packages/just-bash/src/interpreter/redirections.dup-routing.test.ts diff --git a/.changeset/redirect-dup-routing.md b/.changeset/redirect-dup-routing.md new file mode 100644 index 00000000..291be793 --- /dev/null +++ b/.changeset/redirect-dup-routing.md @@ -0,0 +1,28 @@ +--- +"just-bash": patch +--- + +interpreter: deliver redirected output to each fd's final target (fixes `cmd > file 2>&1` leaking stderr to stdout) + +`applyRedirections()` processed a command's redirection list sequentially over +the result's stdout/stderr strings, moving content at each step. The +duplication operators (`2>&1`, `1>&2`) merged into the live stream regardless +of where the source fd pointed, so the canonical `cmd > file 2>&1` wrote +stdout to the file but leaked stderr onto the caller's stdout — including +"command not found" errors and custom-command stderr. Any wrapper protocol +that parses the enclosing script's stdout (e.g. a runner emitting a JSON +payload after `eval "$CMD" > "$OUT" 2>&1`) saw the leaked stderr corrupt its +stream. Ordering variants were wrong in other ways: `cmd 2>&1 > file` put +stderr in the file instead of on stdout, and `cmd > a > b` wrote content to +`a` instead of `b`. + +The pass now mirrors how bash sets up fds before running the command: each +output redirection only opens/truncates its target and re-points the fd's +sink (file, /dev/null, or a snapshot of the caller-visible stream), and +duplication operators copy the source fd's current sink. Stream content is +delivered once, after the whole list is processed, to each fd's final sink. +This makes `cmd > file 2>&1` send stderr to the file, `cmd 2>&1 > file` keep +stderr on the caller's stdout, `cmd > all 2>&1 2> err` let the later `2> err` +reclaim stderr, and `cmd > a > b` truncate `a` while writing content to `b`. +The `/dev/null`-as-regular-VFS-file behavior for stdout redirects is +preserved. diff --git a/packages/just-bash/src/interpreter/redirections.dup-routing.test.ts b/packages/just-bash/src/interpreter/redirections.dup-routing.test.ts new file mode 100644 index 00000000..6249ef0f --- /dev/null +++ b/packages/just-bash/src/interpreter/redirections.dup-routing.test.ts @@ -0,0 +1,190 @@ +import { describe, expect, it } from "vitest"; +import { Bash } from "../Bash.js"; +import { defineCommand } from "../custom-commands.js"; + +/** + * `applyRedirections` processes a command's redirection list sequentially, so a + * duplication operator must deliver to wherever its source fd points at that + * moment in the list — not unconditionally to the live stream. + * + * The canonical failure this guards against: `cmd > file 2>&1` wrote stdout to + * the file but leaked stderr onto the caller's stdout, because `2>&1` ignored + * that fd 1 had already been redirected. Any wrapper protocol that parses the + * enclosing script's stdout (e.g. a runner emitting a JSON payload after + * `eval "$CMD" > "$OUT" 2>&1`) sees the leaked stderr corrupt its stream. + */ +describe("fd duplication after redirection (> file 2>&1)", () => { + it("sends command-not-found stderr to the file, not the caller's stdout", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd > /tmp/f 2>&1"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(127); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe("bash: nosuchcmd: command not found\n"); + }); + + it("sends a custom command's stderr to the file", async () => { + const fail403 = defineCommand("vercel", async () => ({ + stdout: "", + stderr: "Error! Forbidden (403)\n", + exitCode: 1, + })); + const env = new Bash({ customCommands: [fail403] }); + const result = await env.exec("vercel flags > /tmp/f 2>&1"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(1); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe("Error! Forbidden (403)\n"); + }); + + it("keeps a wrapper script's stdout clean (runner-payload shape)", async () => { + const fail = defineCommand("failing-tool", async () => ({ + stdout: "", + stderr: "tool error\n", + exitCode: 1, + })); + const env = new Bash({ customCommands: [fail] }); + const result = await env.exec( + 'CMD="failing-tool"; eval "$CMD" > /tmp/out 2>&1; echo \'{"ok":true}\'', + ); + expect(result.stdout).toBe('{"ok":true}\n'); + expect(result.stderr).toBe(""); + const f = await env.exec("cat /tmp/out"); + expect(f.stdout).toBe("tool error\n"); + }); + + it("interleaves group stdout and stderr into the file", async () => { + const env = new Bash(); + const result = await env.exec("{ echo o; nosuchcmd; } > /tmp/f 2>&1"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe("o\nbash: nosuchcmd: command not found\n"); + }); + + it("appends stderr after >> file 2>&1", async () => { + const env = new Bash({ files: { "/tmp/f": "x\n" } }); + const result = await env.exec("nosuchcmd >> /tmp/f 2>&1"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe("x\nbash: nosuchcmd: command not found\n"); + }); + + it("routes stdout to fd 2's file for cmd 2> file 1>&2", async () => { + const env = new Bash(); + const result = await env.exec("echo hi 2> /tmp/e 1>&2"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const e = await env.exec("cat /tmp/e"); + expect(e.stdout).toBe("hi\n"); + }); + + it("discards stderr for > /dev/null 2>&1", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd > /dev/null 2>&1"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(127); + }); + + it("lets a later 2> file reclaim stderr after > all 2>&1", async () => { + const env = new Bash(); + const result = await env.exec( + "{ echo out; nosuchcmd; } > /tmp/all 2>&1 2> /tmp/err", + ); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const all = await env.exec("cat /tmp/all"); + expect(all.stdout).toBe("out\n"); + const err = await env.exec("cat /tmp/err"); + expect(err.stdout).toBe("bash: nosuchcmd: command not found\n"); + }); + + it("keeps stderr on the caller's stdout for 2>&1 > file (dup before redirect)", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd 2>&1 > /tmp/f"); + expect(result.stdout).toBe("bash: nosuchcmd: command not found\n"); + expect(result.stderr).toBe(""); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe(""); + }); + + it("only truncates intermediate redirect targets (1>&2 > leak > /dev/null)", async () => { + const env = new Bash(); + const result = await env.exec( + "echo hi 1>&2 > /tmp/leak > /dev/null 2> /dev/null", + ); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const leak = await env.exec("cat /tmp/leak"); + expect(leak.stdout).toBe(""); + expect(leak.exitCode).toBe(0); // file exists (was opened), just empty + }); + + it("writes content to the last target for cmd > a > b", async () => { + const env = new Bash(); + await env.exec("echo hi > /tmp/a > /tmp/b"); + const a = await env.exec("cat /tmp/a"); + expect(a.stdout).toBe(""); + expect(a.exitCode).toBe(0); // truncated but created + const b = await env.exec("cat /tmp/b"); + expect(b.stdout).toBe("hi\n"); + }); + + it("keeps content in the file for > file > /dev/stdout (self-dup no-op)", async () => { + const env = new Bash(); + const result = await env.exec("echo hi > /tmp/a > /dev/stdout"); + expect(result.stdout).toBe(""); + const a = await env.exec("cat /tmp/a"); + expect(a.stdout).toBe("hi\n"); + }); + + it("routes stderr to fd 1's file for 2> /dev/stdout after > file", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd > /tmp/f 2> /dev/stdout"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const f = await env.exec("cat /tmp/f"); + expect(f.stdout).toBe("bash: nosuchcmd: command not found\n"); + }); + + it("treats > f 2> f as independent descriptors, not a shared cursor", async () => { + const env = new Bash(); + await env.exec("{ echo out; nosuchcmd; } > /tmp/f 2> /tmp/f"); + const f = await env.exec("cat /tmp/f"); + // Each redirect writes from its own start position; the later non-empty + // write clobbers the earlier one (bash's independent-open behavior). + expect(f.stdout).toBe("bash: nosuchcmd: command not found\n"); + const env2 = new Bash(); + await env2.exec("echo hi > /tmp/f 2> /tmp/f"); + const f2 = await env2.exec("cat /tmp/f"); + expect(f2.stdout).toBe("hi\n"); + }); + + it("keeps the ENOSPC diagnostic visible for 2> /dev/full", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd 2> /dev/full"); + expect(result.stderr).toContain("No space left on device"); + expect(result.exitCode).toBe(1); + }); + + it("still merges to live stdout for a bare 2>&1", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd 2>&1"); + expect(result.stdout).toBe("bash: nosuchcmd: command not found\n"); + expect(result.stderr).toBe(""); + expect(result.exitCode).toBe(127); + }); + + it("still routes plain 2> file without a dup", async () => { + const env = new Bash(); + const result = await env.exec("nosuchcmd 2> /tmp/e"); + expect(result.stdout).toBe(""); + expect(result.stderr).toBe(""); + const e = await env.exec("cat /tmp/e"); + expect(e.stdout).toBe("bash: nosuchcmd: command not found\n"); + }); +}); diff --git a/packages/just-bash/src/interpreter/redirections.ts b/packages/just-bash/src/interpreter/redirections.ts index 96c50454..a341f62e 100644 --- a/packages/just-bash/src/interpreter/redirections.ts +++ b/packages/just-bash/src/interpreter/redirections.ts @@ -427,6 +427,22 @@ export async function applyRedirections( const getStdoutEncoding = (_content: string): "binary" | "utf8" => stdoutFileEncoding; + // Where fds 1 and 2 currently point as the redirection list is processed + // left to right. File redirections write their stream eagerly and update + // the fd's sink; duplication operators (`2>&1`, `1>&2`) only re-point the + // fd to a snapshot of the source fd's current sink. Content still held in + // a stream when the list ends is delivered to that fd's final sink below — + // so `cmd > file 2>&1` sends stderr to `file`, `cmd 2>&1 > file` sends + // stderr to the caller's stdout, and `cmd > all 2>&1 2> err` lets the + // later `2> err` reclaim stderr. + type RedirectSink = + | { kind: "live-stdout" } + | { kind: "live-stderr" } + | { kind: "file"; path: string; append: boolean } + | { kind: "discard" }; + let fd1Sink: RedirectSink = { kind: "live-stdout" }; + let fd2Sink: RedirectSink = { kind: "live-stderr" }; + for (let i = 0; i < redirections.length; i++) { const redir = redirections[i]; if (redir.target.type === "HereDoc") { @@ -483,152 +499,75 @@ export async function applyRedirections( switch (redir.operator) { case ">": - case ">|": { + case ">|": + case ">>": { const fd = redir.fd ?? 1; + if (fd !== 1 && fd !== 2) { + break; + } + const isAppend = redir.operator === ">>"; const isClobber = redir.operator === ">|"; - if (fd === 1) { - // /dev/stdout is a no-op for stdout - output stays on stdout - if (target === "/dev/stdout") { - break; + // Opening /dev/stdout or /dev/stderr duplicates the CURRENT target + // of fd 1 / fd 2, like `N>&1` / `N>&2`: `> /dev/stderr` re-points + // fd 1 to wherever fd 2 points right now, and the self-referential + // forms (`> /dev/stdout`, `2> /dev/stderr`) are no-ops — after + // `> a > /dev/stdout` content still goes to `a`. + if (target === "/dev/stdout") { + if (fd === 2) { + fd2Sink = fd1Sink; } - // /dev/stderr redirects stdout to stderr - if (target === "/dev/stderr") { - stderr += stdout; - stdout = ""; - break; + break; + } + if (target === "/dev/stderr") { + if (fd === 1) { + fd1Sink = fd2Sink; } - // /dev/full always returns ENOSPC when written to - if (target === "/dev/full") { - stderr += `bash: echo: write error: No space left on device\n`; - exitCode = 1; + break; + } + // /dev/full always returns ENOSPC when written to. The diagnostic + // stays on live stderr and the fd's sink is left unchanged. + if (target === "/dev/full") { + stderr += `bash: echo: write error: No space left on device\n`; + exitCode = 1; + if (fd === 1) { stdout = ""; - break; } - const filePath = ctx.fs.resolvePath(ctx.state.cwd, target); - const error = await checkOutputRedirectTarget(ctx, filePath, target, { - checkNoclobber: true, - isClobber, - }); - if (error) { - stderr += error; - exitCode = 1; + break; + } + // /dev/null on fd 2 drops stderr without touching the VFS node. + // /dev/null on fd 1 intentionally falls through to the generic file + // path: in this VFS it is a regular file, not a true discard device + // (see overlay-fs.security.test.ts "/dev file overwrite behavior"). + if (target === "/dev/null" && fd === 2) { + fd2Sink = { kind: "discard" }; + break; + } + const filePath = ctx.fs.resolvePath(ctx.state.cwd, target); + const error = await checkOutputRedirectTarget(ctx, filePath, target, { + ...(isAppend ? {} : { checkNoclobber: true, isClobber }), + }); + if (error) { + stderr += error; + exitCode = 1; + if (fd === 1) { stdout = ""; - break; - } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - await ctx.fs.writeFile(filePath, stdout, getStdoutEncoding(stdout)); - stdout = ""; - } else if (fd === 2) { - // /dev/stderr is a no-op for stderr - output stays on stderr - if (target === "/dev/stderr") { - break; - } - // /dev/stdout redirects stderr to stdout - if (target === "/dev/stdout") { - stdout += stderr; - stderr = ""; - break; - } - // /dev/full always returns ENOSPC when written to - if (target === "/dev/full") { - stderr += `bash: echo: write error: No space left on device\n`; - exitCode = 1; - break; - } - if (target === "/dev/null") { - stderr = ""; - } else { - const filePath = ctx.fs.resolvePath(ctx.state.cwd, target); - const error = await checkOutputRedirectTarget( - ctx, - filePath, - target, - { - checkNoclobber: true, - isClobber, - }, - ); - if (error) { - stderr += error; - exitCode = 1; - break; - } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - await ctx.fs.writeFile(filePath, stderr, getFileEncoding(stderr)); - stderr = ""; } + break; + } + // Opening the target is a side effect of processing the redirection + // list even when the fd is re-pointed again later: `>` truncates and + // `>>` creates the file if missing. Content is delivered to each + // fd's FINAL sink after the list is processed, so `cmd > a > b` + // truncates `a` but writes to `b`. + if (isAppend) { + await ctx.fs.appendFile(filePath, "", "binary"); + } else { + await ctx.fs.writeFile(filePath, "", "binary"); } - break; - } - - case ">>": { - const fd = redir.fd ?? 1; if (fd === 1) { - // /dev/stdout is a no-op for stdout - output stays on stdout - if (target === "/dev/stdout") { - break; - } - // /dev/stderr redirects stdout to stderr - if (target === "/dev/stderr") { - stderr += stdout; - stdout = ""; - break; - } - // /dev/full always returns ENOSPC when written to - if (target === "/dev/full") { - stderr += `bash: echo: write error: No space left on device\n`; - exitCode = 1; - stdout = ""; - break; - } - const filePath = ctx.fs.resolvePath(ctx.state.cwd, target); - const error = await checkOutputRedirectTarget( - ctx, - filePath, - target, - {}, - ); - if (error) { - stderr += error; - exitCode = 1; - stdout = ""; - break; - } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - await ctx.fs.appendFile(filePath, stdout, getStdoutEncoding(stdout)); - stdout = ""; - } else if (fd === 2) { - // /dev/stderr is a no-op for stderr - output stays on stderr - if (target === "/dev/stderr") { - break; - } - // /dev/stdout redirects stderr to stdout - if (target === "/dev/stdout") { - stdout += stderr; - stderr = ""; - break; - } - // /dev/full always returns ENOSPC when written to - if (target === "/dev/full") { - stderr += `bash: echo: write error: No space left on device\n`; - exitCode = 1; - break; - } - const filePath2 = ctx.fs.resolvePath(ctx.state.cwd, target); - const error2 = await checkOutputRedirectTarget( - ctx, - filePath2, - target, - {}, - ); - if (error2) { - stderr += error2; - exitCode = 1; - break; - } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - await ctx.fs.appendFile(filePath2, stderr, getFileEncoding(stderr)); - stderr = ""; + fd1Sink = { kind: "file", path: filePath, append: isAppend }; + } else { + fd2Sink = { kind: "file", path: filePath, append: isAppend }; } break; } @@ -686,18 +625,19 @@ export async function applyRedirections( } break; } - // >&2, 1>&2, 1<&2: redirect stdout to stderr + // >&2, 1>&2, 1<&2: duplicate fd 1 from fd 2 — fd 1 now points to a + // snapshot of wherever fd 2 points at this spot in the list. Content + // is not moved here: a later redirection may still repoint fd 1, so + // remaining stdout is delivered once the whole list is processed. if (target === "2" || target === "&2") { if (fd === 1) { - stderr += stdout; - stdout = ""; + fd1Sink = fd2Sink; } } - // 2>&1, 2<&1: redirect stderr to stdout + // 2>&1, 2<&1: duplicate fd 2 from fd 1 — same deferred delivery. else if (target === "1" || target === "&1") { if (fd === 2) { - stdout += stderr; - stderr = ""; + fd2Sink = fd1Sink; } else { // 1>&1 is a no-op, but other fds redirect to stdout stdout += stderr; @@ -817,28 +757,19 @@ export async function applyRedirections( stdout = ""; break; } + // Truncate now; content is delivered to the final sinks after + // the whole redirection list is processed. + await ctx.fs.writeFile(filePath, "", "binary"); if (redir.fd == null) { - // >&word (no explicit fd) - write both stdout and stderr to the file - const combined = stdout + stderr; - await ctx.fs.writeFile( - filePath, - combined, - getStdoutEncoding(combined), - ); - stdout = ""; - stderr = ""; + // >&word (no explicit fd) - both stdout and stderr to the file + fd1Sink = { kind: "file", path: filePath, append: false }; + fd2Sink = fd1Sink; } else if (fd === 1) { // 1>&word - redirect stdout to file - await ctx.fs.writeFile( - filePath, - stdout, - getStdoutEncoding(stdout), - ); - stdout = ""; + fd1Sink = { kind: "file", path: filePath, append: false }; } else if (fd === 2) { // 2>&word - redirect stderr to file - await ctx.fs.writeFile(filePath, stderr, getFileEncoding(stderr)); - stderr = ""; + fd2Sink = { kind: "file", path: filePath, append: false }; } } } @@ -863,11 +794,11 @@ export async function applyRedirections( stdout = ""; break; } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - const combined = stdout + stderr; - await ctx.fs.writeFile(filePath, combined, getStdoutEncoding(combined)); - stdout = ""; - stderr = ""; + // Truncate now; content is delivered to the final sinks after the + // whole redirection list is processed. + await ctx.fs.writeFile(filePath, "", "binary"); + fd1Sink = { kind: "file", path: filePath, append: false }; + fd2Sink = fd1Sink; break; } @@ -892,20 +823,82 @@ export async function applyRedirections( stdout = ""; break; } - // Smart encoding: binary for byte data, UTF-8 for Unicode text - const combined = stdout + stderr; - await ctx.fs.appendFile( - filePath, - combined, - getStdoutEncoding(combined), - ); - stdout = ""; - stderr = ""; + // Create if missing; content is delivered to the final sinks after + // the whole redirection list is processed. + await ctx.fs.appendFile(filePath, "", "binary"); + fd1Sink = { kind: "file", path: filePath, append: true }; + fd2Sink = fd1Sink; break; } } } + // Deliver content still held in the streams to each fd's final sink. + // "live-stdout" / "live-stderr" mean the caller's own streams as they were + // before any redirection — a dup snapshot of a live fd keeps pointing + // there even if a later redirection sends the source fd elsewhere. + // + // A duplication (`2>&1`) shares the source fd's sink OBJECT — one open + // descriptor, so both streams go through it in order. Two independent + // redirects that happen to name the same path (`> f 2> f`) are separate + // descriptors, each writing from its own start position, so the later + // non-empty write clobbers the earlier one — matching bash's + // independent-open behavior. + if (stdout !== "" || stderr !== "") { + const pendingStdout = stdout; + const pendingStderr = stderr; + stdout = ""; + stderr = ""; + const deliverToFile = async ( + sink: { path: string; append: boolean }, + content: string, + encoding: "binary" | "utf8", + ) => { + if (sink.append) { + await ctx.fs.appendFile(sink.path, content, encoding); + } else { + await ctx.fs.writeFile(sink.path, content, encoding); + } + }; + if (fd1Sink === fd2Sink && fd1Sink.kind === "file") { + // stdout-then-stderr order, not the command's temporal write order: + // ExecResult accumulates the two streams separately, so interleaving + // is not recorded anywhere in the interpreter. This matches the + // convention of the live-stream merge (`stdout += stderr`) used for a + // bare `2>&1`. + const combined = pendingStdout + pendingStderr; + if (combined !== "") { + await deliverToFile(fd1Sink, combined, getStdoutEncoding(combined)); + } + } else { + for (const [content, sink, isStdout] of [ + [pendingStdout, fd1Sink, true], + [pendingStderr, fd2Sink, false], + ] as const) { + if (content === "") { + continue; + } + switch (sink.kind) { + case "live-stdout": + stdout += content; + break; + case "live-stderr": + stderr += content; + break; + case "file": + await deliverToFile( + sink, + content, + isStdout ? getStdoutEncoding(content) : getFileEncoding(content), + ); + break; + case "discard": + break; + } + } + } + } + // Apply persistent FD redirections (from exec) // Check if fd 1 (stdout) is redirected to fd 2 (stderr) via exec 1>&2 const fd1Info = ctx.state.fileDescriptors?.get(1); From 729fe8f7fc3d43a97f77cf9dda7ca1aa14d5ed08 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Jul 2026 18:24:30 +0200 Subject: [PATCH 4/9] chore: release (#287) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/assignment-lazy-import.md | 19 ------- .changeset/multiline-quoted-whitespace.md | 18 ------- .changeset/redirect-dup-routing.md | 28 ----------- examples/executor-tools/CHANGELOG.md | 8 +++ examples/executor-tools/package.json | 2 +- packages/just-bash-executor/CHANGELOG.md | 7 +++ packages/just-bash-executor/package.json | 2 +- packages/just-bash/CHANGELOG.md | 60 +++++++++++++++++++++++ packages/just-bash/package.json | 2 +- 9 files changed, 78 insertions(+), 68 deletions(-) delete mode 100644 .changeset/assignment-lazy-import.md delete mode 100644 .changeset/multiline-quoted-whitespace.md delete mode 100644 .changeset/redirect-dup-routing.md diff --git a/.changeset/assignment-lazy-import.md b/.changeset/assignment-lazy-import.md deleted file mode 100644 index 575bbd2d..00000000 --- a/.changeset/assignment-lazy-import.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -"just-bash": patch ---- - -interpreter: avoid lazy import in variable assignment path that trips defense-in-depth (fixes #273) - -Any non-`export` variable assignment (bare `SECRET=s`, prefixed `SECRET=s cmd`, -or before a custom command) failed with a defense-in-depth security violation -(`dynamic import of Node.js builtin 'node:module' is blocked during script -execution`), while plain commands and `export`-ed assignments passed. - -`processScalarAssignment()` resolved `isArray` via `await import("./expansion.js")` -in two spots. In the bundled `dist`, that dynamic `import()` marks `expansion.js` -as a lazily-linked chunk whose `createRequire` banner imports `node:module`; the -defense layer's ESM `resolve` hook blocks that builtin import when the sandbox is -active and untrusted, so it blocked just-bash's own chunk load. The file already -statically imports from `./expansion.js`, so `isArray` is now pulled from that -static import and the two lazy imports are removed — no lazy `node:module`-bearing -chunk is linked at runtime. No public API change. diff --git a/.changeset/multiline-quoted-whitespace.md b/.changeset/multiline-quoted-whitespace.md deleted file mode 100644 index fb7c722c..00000000 --- a/.changeset/multiline-quoted-whitespace.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -"just-bash": patch ---- - -interpreter: preserve leading whitespace in multi-line quoted strings (fixes #259) - -`exec()` runs each script through `normalizeScript()`, which `trimStart()`s -leading indentation from lines so indented template-literal scripts parse. It -was applied line-by-line and stripped the leading whitespace inside multi-line -single- and double-quoted strings too. The visible symptom was `python3 -c -'...'` (and `node -e`, `awk`, etc.) with an indented body failing with -`IndentationError`, while the same code via heredoc or pipe worked. - -`normalizeScript()` is now quote-aware (mirroring the earlier heredoc-aware -fix): it only strips indentation from lines that begin outside any quote, and -preserves lines that begin inside an unterminated single- or double-quoted -string verbatim. This also un-skips four sed spec tests whose indented stdin -was previously being corrupted. diff --git a/.changeset/redirect-dup-routing.md b/.changeset/redirect-dup-routing.md deleted file mode 100644 index 291be793..00000000 --- a/.changeset/redirect-dup-routing.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -"just-bash": patch ---- - -interpreter: deliver redirected output to each fd's final target (fixes `cmd > file 2>&1` leaking stderr to stdout) - -`applyRedirections()` processed a command's redirection list sequentially over -the result's stdout/stderr strings, moving content at each step. The -duplication operators (`2>&1`, `1>&2`) merged into the live stream regardless -of where the source fd pointed, so the canonical `cmd > file 2>&1` wrote -stdout to the file but leaked stderr onto the caller's stdout — including -"command not found" errors and custom-command stderr. Any wrapper protocol -that parses the enclosing script's stdout (e.g. a runner emitting a JSON -payload after `eval "$CMD" > "$OUT" 2>&1`) saw the leaked stderr corrupt its -stream. Ordering variants were wrong in other ways: `cmd 2>&1 > file` put -stderr in the file instead of on stdout, and `cmd > a > b` wrote content to -`a` instead of `b`. - -The pass now mirrors how bash sets up fds before running the command: each -output redirection only opens/truncates its target and re-points the fd's -sink (file, /dev/null, or a snapshot of the caller-visible stream), and -duplication operators copy the source fd's current sink. Stream content is -delivered once, after the whole list is processed, to each fd's final sink. -This makes `cmd > file 2>&1` send stderr to the file, `cmd 2>&1 > file` keep -stderr on the caller's stdout, `cmd > all 2>&1 2> err` let the later `2> err` -reclaim stderr, and `cmd > a > b` truncate `a` while writing content to `b`. -The `/dev/null`-as-regular-VFS-file behavior for stdout redirects is -preserved. diff --git a/examples/executor-tools/CHANGELOG.md b/examples/executor-tools/CHANGELOG.md index 0931deb7..80575de8 100644 --- a/examples/executor-tools/CHANGELOG.md +++ b/examples/executor-tools/CHANGELOG.md @@ -1,5 +1,13 @@ # executor-tools-example +## 1.0.5 + +### Patch Changes + +- Updated dependencies [[`aec5643`](https://github.com/vercel-labs/just-bash/commit/aec56431d7d9b6fcb141bbfe25d26f4931f54f80), [`1ec5eec`](https://github.com/vercel-labs/just-bash/commit/1ec5eec0aefd099d23ac9f056df1e6612c81d49b), [`cb2b583`](https://github.com/vercel-labs/just-bash/commit/cb2b583b3f46e6bb4e6982c4bfe19903ec811a87)]: + - just-bash@3.0.3 + - @just-bash/executor@1.0.4 + ## 1.0.4 ### Patch Changes diff --git a/examples/executor-tools/package.json b/examples/executor-tools/package.json index 7a2ab661..9e206d9f 100644 --- a/examples/executor-tools/package.json +++ b/examples/executor-tools/package.json @@ -1,6 +1,6 @@ { "name": "executor-tools-example", - "version": "1.0.4", + "version": "1.0.5", "description": "Example of @just-bash/executor — inline tools + GraphQL/OpenAPI/MCP discovery", "type": "module", "scripts": { diff --git a/packages/just-bash-executor/CHANGELOG.md b/packages/just-bash-executor/CHANGELOG.md index cef460ff..7977284e 100644 --- a/packages/just-bash-executor/CHANGELOG.md +++ b/packages/just-bash-executor/CHANGELOG.md @@ -1,5 +1,12 @@ # @just-bash/executor +## 1.0.4 + +### Patch Changes + +- Updated dependencies [[`aec5643`](https://github.com/vercel-labs/just-bash/commit/aec56431d7d9b6fcb141bbfe25d26f4931f54f80), [`1ec5eec`](https://github.com/vercel-labs/just-bash/commit/1ec5eec0aefd099d23ac9f056df1e6612c81d49b), [`cb2b583`](https://github.com/vercel-labs/just-bash/commit/cb2b583b3f46e6bb4e6982c4bfe19903ec811a87)]: + - just-bash@3.0.3 + ## 1.0.3 ### Patch Changes diff --git a/packages/just-bash-executor/package.json b/packages/just-bash-executor/package.json index 54fda70c..68221a60 100644 --- a/packages/just-bash-executor/package.json +++ b/packages/just-bash-executor/package.json @@ -1,6 +1,6 @@ { "name": "@just-bash/executor", - "version": "1.0.3", + "version": "1.0.4", "description": "Experimental tool-invocation companion for just-bash. Wires @executor-js/sdk into js-exec via the invokeTool hook.", "repository": { "type": "git", diff --git a/packages/just-bash/CHANGELOG.md b/packages/just-bash/CHANGELOG.md index 96e9a049..17378a6a 100644 --- a/packages/just-bash/CHANGELOG.md +++ b/packages/just-bash/CHANGELOG.md @@ -1,5 +1,65 @@ # just-bash +## 3.0.3 + +### Patch Changes + +- [#277](https://github.com/vercel-labs/just-bash/pull/277) [`aec5643`](https://github.com/vercel-labs/just-bash/commit/aec56431d7d9b6fcb141bbfe25d26f4931f54f80) Thanks [@mutewinter](https://github.com/mutewinter)! - interpreter: avoid lazy import in variable assignment path that trips defense-in-depth (fixes [#273](https://github.com/vercel-labs/just-bash/issues/273)) + + Any non-`export` variable assignment (bare `SECRET=s`, prefixed `SECRET=s cmd`, + or before a custom command) failed with a defense-in-depth security violation + (`dynamic import of Node.js builtin 'node:module' is blocked during script +execution`), while plain commands and `export`-ed assignments passed. + + `processScalarAssignment()` resolved `isArray` via `await import("./expansion.js")` + in two spots. In the bundled `dist`, that dynamic `import()` marks `expansion.js` + as a lazily-linked chunk whose `createRequire` banner imports `node:module`; the + defense layer's ESM `resolve` hook blocks that builtin import when the sandbox is + active and untrusted, so it blocked just-bash's own chunk load. The file already + statically imports from `./expansion.js`, so `isArray` is now pulled from that + static import and the two lazy imports are removed — no lazy `node:module`-bearing + chunk is linked at runtime. No public API change. + +- [#276](https://github.com/vercel-labs/just-bash/pull/276) [`1ec5eec`](https://github.com/vercel-labs/just-bash/commit/1ec5eec0aefd099d23ac9f056df1e6612c81d49b) Thanks [@mutewinter](https://github.com/mutewinter)! - interpreter: preserve leading whitespace in multi-line quoted strings (fixes [#259](https://github.com/vercel-labs/just-bash/issues/259)) + + `exec()` runs each script through `normalizeScript()`, which `trimStart()`s + leading indentation from lines so indented template-literal scripts parse. It + was applied line-by-line and stripped the leading whitespace inside multi-line + single- and double-quoted strings too. The visible symptom was `python3 -c +'...'` (and `node -e`, `awk`, etc.) with an indented body failing with + `IndentationError`, while the same code via heredoc or pipe worked. + + `normalizeScript()` is now quote-aware (mirroring the earlier heredoc-aware + fix): it only strips indentation from lines that begin outside any quote, and + preserves lines that begin inside an unterminated single- or double-quoted + string verbatim. This also un-skips four sed spec tests whose indented stdin + was previously being corrupted. + +- [#286](https://github.com/vercel-labs/just-bash/pull/286) [`cb2b583`](https://github.com/vercel-labs/just-bash/commit/cb2b583b3f46e6bb4e6982c4bfe19903ec811a87) Thanks [@privatenumber](https://github.com/privatenumber)! - interpreter: deliver redirected output to each fd's final target (fixes `cmd > file 2>&1` leaking stderr to stdout) + + `applyRedirections()` processed a command's redirection list sequentially over + the result's stdout/stderr strings, moving content at each step. The + duplication operators (`2>&1`, `1>&2`) merged into the live stream regardless + of where the source fd pointed, so the canonical `cmd > file 2>&1` wrote + stdout to the file but leaked stderr onto the caller's stdout — including + "command not found" errors and custom-command stderr. Any wrapper protocol + that parses the enclosing script's stdout (e.g. a runner emitting a JSON + payload after `eval "$CMD" > "$OUT" 2>&1`) saw the leaked stderr corrupt its + stream. Ordering variants were wrong in other ways: `cmd 2>&1 > file` put + stderr in the file instead of on stdout, and `cmd > a > b` wrote content to + `a` instead of `b`. + + The pass now mirrors how bash sets up fds before running the command: each + output redirection only opens/truncates its target and re-points the fd's + sink (file, /dev/null, or a snapshot of the caller-visible stream), and + duplication operators copy the source fd's current sink. Stream content is + delivered once, after the whole list is processed, to each fd's final sink. + This makes `cmd > file 2>&1` send stderr to the file, `cmd 2>&1 > file` keep + stderr on the caller's stdout, `cmd > all 2>&1 2> err` let the later `2> err` + reclaim stderr, and `cmd > a > b` truncate `a` while writing content to `b`. + The `/dev/null`-as-regular-VFS-file behavior for stdout redirects is + preserved. + ## 3.0.2 ### Patch Changes diff --git a/packages/just-bash/package.json b/packages/just-bash/package.json index 3d59627a..7e671142 100644 --- a/packages/just-bash/package.json +++ b/packages/just-bash/package.json @@ -1,6 +1,6 @@ { "name": "just-bash", - "version": "3.0.2", + "version": "3.0.3", "description": "A simulated bash environment with virtual filesystem", "repository": { "type": "git", From 7a5a0b9ae3bf0524722653cbf4b45e6bc176cf22 Mon Sep 17 00:00:00 2001 From: Lars Trieloff Date: Wed, 8 Jul 2026 16:22:07 +0200 Subject: [PATCH 5/9] fix(jq): handle nested double-quoted strings in \(...) interpolation (#268) * test(jq): add tests for string interpolation with nested double-quoted s Agent-Id: agent-12c8b5b5-e758-422a-bee6-ab6b2e25517d Linked-Note-Id: 8fe42115-4710-4194-aed6-c1449d679579 * fix(jq): handle nested string literals in \(...) interpolation expressio Agent-Id: agent-9bd6017d-ea22-4bd6-8190-b306d67d0cbc Linked-Note-Id: edb667b3-8f39-4a48-b003-3ec0b657dcda * chore: add changeset for jq nested string interpolation fix Agent-Id: agent-4db0ce47-132c-4959-81a1-0f363ca00c71 Linked-Note-Id: c350e3c0-9d82-4715-b108-f7bc79a4e1a5 * test: unskip jq nested interpolation spec Signed-off-by: Lars Trieloff --------- Signed-off-by: Lars Trieloff --- .changeset/jq-nested-interp.md | 9 ++ .../jq/jq.string-interp-nested-quotes.test.ts | 114 ++++++++++++++++++ .../src/commands/query-engine/parser.ts | 65 ++++++++-- packages/just-bash/src/spec-tests/jq/skips.ts | 5 - 4 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 .changeset/jq-nested-interp.md create mode 100644 packages/just-bash/src/commands/jq/jq.string-interp-nested-quotes.test.ts diff --git a/.changeset/jq-nested-interp.md b/.changeset/jq-nested-interp.md new file mode 100644 index 00000000..83918d34 --- /dev/null +++ b/.changeset/jq-nested-interp.md @@ -0,0 +1,9 @@ +--- +"just-bash": patch +--- + +jq: allow nested double-quoted strings inside `"\(...)"` string interpolation + +jq string interpolation of the form `"\(...)"` that contained a nested double-quoted string — for example `"\(sub("T.*";""))"` or `"\(ltrimstr("ab"))"` — previously failed with a parse error. The tokenizer terminated the outer string at the first `"` it saw inside the interpolation expression, so the rest of the expression became orphaned tokens. + +The lexer now tracks `\(...)` depth while consuming a string literal and treats nested `"..."` pairs as opaque content while inside an interpolation, restoring them verbatim into the captured interpolation source. `parseStringInterpolation` similarly skips over nested strings when balancing parentheses, so the interpolation expression is captured as a whole and handed to the expression parser intact. diff --git a/packages/just-bash/src/commands/jq/jq.string-interp-nested-quotes.test.ts b/packages/just-bash/src/commands/jq/jq.string-interp-nested-quotes.test.ts new file mode 100644 index 00000000..b6591c0c --- /dev/null +++ b/packages/just-bash/src/commands/jq/jq.string-interp-nested-quotes.test.ts @@ -0,0 +1,114 @@ +import { describe, expect, it } from "vitest"; +import { Bash } from "../../Bash.js"; + +// Real jq's string interpolation `"\(...)"` correctly handles nested +// double-quoted strings inside the interpolation (e.g. sub("T.*"; ""), +// ltrimstr("ab")). Our tokenizer currently terminates the outer string at +// the first inner `"`, producing parse errors. These tests pin the +// real-jq behavior so the fix can be validated. +describe("jq string interpolation with nested double-quoted strings", () => { + it("evaluates sub() with two string literals inside interpolation", async () => { + const env = new Bash({ + files: { "/payload.json": '{"m":"2026-06-05T10:00:00Z"}\n' }, + }); + + const result = await env.exec( + `jq -r '"\\(.m | sub("T.*"; ""))"' /payload.json`, + ); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("2026-06-05\n"); + expect(result.exitCode).toBe(0); + }); + + it("evaluates string concatenation with nested string literal", async () => { + const env = new Bash({ + files: { "/payload.json": '{"m":"hi"}\n' }, + }); + + const result = await env.exec(`jq -r '"\\(.m + "!")"' /payload.json`); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("hi!\n"); + expect(result.exitCode).toBe(0); + }); + + it("evaluates ltrimstr() with a nested string literal", async () => { + const env = new Bash({ + files: { "/payload.json": '{"m":"abcd"}\n' }, + }); + + const result = await env.exec( + `jq -r '"\\(.m | ltrimstr("ab"))"' /payload.json`, + ); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("cd\n"); + expect(result.exitCode).toBe(0); + }); + + it("evaluates the full transcript filter over an array", async () => { + const env = new Bash({ + files: { + "/payload.json": + '[{"m":"2026-06-05T10:00:00Z","n":1,"u":"alice","t":"hello"},' + + '{"m":"2026-06-06T11:00:00Z","n":2,"u":"bob","t":"world"}]\n', + }, + }); + + const result = await env.exec( + `jq -r '.[] | "\\(.m | sub("T.*"; "")) #\\(.n) @\\(.u): \\(.t)"' /payload.json`, + ); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe( + "2026-06-05 #1 @alice: hello\n2026-06-06 #2 @bob: world\n", + ); + expect(result.exitCode).toBe(0); + }); + + it("balances parens correctly when nested string contains a paren", async () => { + const env = new Bash({ + files: { "/payload.json": '{"m":"(hello)"}\n' }, + }); + + const result = await env.exec( + `jq -r '"\\(.m | sub("[(]"; "X"))"' /payload.json`, + ); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("Xhello)\n"); + expect(result.exitCode).toBe(0); + }); + + // Control cases: these already pass and should continue to pass after the + // fix. They document the boundary of the bug (no nested string literal + // inside the interpolation parens). + it("control: arithmetic inside interpolation (no nested strings)", async () => { + const env = new Bash({ + files: { "/payload.json": '{"n":5}\n' }, + }); + + const result = await env.exec(`jq -r '"\\(.n + 1)"' /payload.json`); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("6\n"); + expect(result.exitCode).toBe(0); + }); + + it("control: @tsv format string works on array rows", async () => { + const env = new Bash({ + files: { + "/payload.json": '[{"a":1,"b":2},{"a":3,"b":4}]\n', + }, + }); + + const result = await env.exec( + `jq -r '.[] | [.a, .b] | @tsv' /payload.json`, + ); + + expect(result.stderr).toBe(""); + expect(result.stdout).toBe("1\t2\n3\t4\n"); + expect(result.exitCode).toBe(0); + }); +}); diff --git a/packages/just-bash/src/commands/query-engine/parser.ts b/packages/just-bash/src/commands/query-engine/parser.ts index 8a71bc51..0d36057c 100644 --- a/packages/just-bash/src/commands/query-engine/parser.ts +++ b/packages/just-bash/src/commands/query-engine/parser.ts @@ -283,8 +283,13 @@ function tokenize(input: string): Token[] { // Strings if (c === '"') { let str = ""; - while (!isEof() && peek() !== '"') { - if (peek() === "\\") { + // Track \( ... ) interpolation depth so an inner `"` (nested string + // literal) inside the interpolation doesn't terminate the outer string. + let interpDepth = 0; + while (!isEof()) { + const ch = peek(); + if (interpDepth === 0 && ch === '"') break; + if (interpDepth === 0 && ch === "\\") { advance(); if (isEof()) break; const escaped = advance(); @@ -306,13 +311,37 @@ function tokenize(input: string): Token[] { break; case "(": str += "\\("; + interpDepth = 1; break; // Keep for string interpolation default: str += escaped; } - } else { + continue; + } + if (interpDepth > 0) { + // Inside \( ... ): preserve raw characters so the interpolation + // parser can re-tokenize them. Skip over nested string literals + // verbatim and track paren depth. + if (ch === '"') { + str += advance(); // opening quote + while (!isEof()) { + const nc = peek(); + if (nc === "\\") { + str += advance(); // backslash + if (!isEof()) str += advance(); // escaped char + continue; + } + str += advance(); + if (nc === '"') break; + } + continue; + } + if (ch === "(") interpDepth++; + else if (ch === ")") interpDepth--; str += advance(); + continue; } + str += advance(); } if (!isEof()) advance(); // closing quote tokens.push({ type: "STRING", value: str, pos: start }); @@ -1091,13 +1120,35 @@ class Parser { current = ""; } i += 2; - // Find matching paren + // Find matching paren, skipping over nested string literals so + // parens inside them don't affect depth counting. let depth = 1; let exprStr = ""; while (i < str.length && depth > 0) { - if (str[i] === "(") depth++; - else if (str[i] === ")") depth--; - if (depth > 0) exprStr += str[i]; + const ch = str[i]; + if (ch === '"') { + exprStr += ch; + i++; + while (i < str.length) { + const nc = str[i]; + if (nc === "\\") { + exprStr += nc; + i++; + if (i < str.length) { + exprStr += str[i]; + i++; + } + continue; + } + exprStr += nc; + i++; + if (nc === '"') break; + } + continue; + } + if (ch === "(") depth++; + else if (ch === ")") depth--; + if (depth > 0) exprStr += ch; i++; } const tokens = tokenize(exprStr); diff --git a/packages/just-bash/src/spec-tests/jq/skips.ts b/packages/just-bash/src/spec-tests/jq/skips.ts index 2f337b04..c86839b4 100644 --- a/packages/just-bash/src/spec-tests/jq/skips.ts +++ b/packages/just-bash/src/spec-tests/jq/skips.ts @@ -153,10 +153,6 @@ const SKIP_TESTS: Map = new Map([ // ============================================================ // String interpolation edge cases // ============================================================ - [ - 'jq.test:"inter\\("pol" + "ation")"', - "String interpolation with complex expression", - ], ['jq.test:@html "\\(.)"', "String interpolation in @html"], ['jq.test:{"a",b,"a$\\(1+1)"}', "String interpolation in object key"], @@ -474,7 +470,6 @@ const SKIP_PATTERNS: Array<{ pattern: RegExp; reason: string }> = [ { pattern: /contains\("b\\u0000/, reason: "contains with NUL char" }, // String interpolation edge cases - { pattern: /inter\\\(/, reason: "String interpolation with backslash" }, { pattern: /\{"[^"]*",\w+,"[^"]*\$\\/, reason: "Object shorthand with interpolation", From ca1cf25c695ffe754bcdf7ab4bde0476073fe41a Mon Sep 17 00:00:00 2001 From: Mohan Raghu Garimella Date: Wed, 8 Jul 2026 07:27:51 -0700 Subject: [PATCH 6/9] fix(rg): search piped stdin when no paths are given (#281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When rg receives piped stdin with no explicit path arguments, it now searches stdin instead of defaulting to the current directory. This matches real ripgrep behavior and is consistent with how grep already handles stdin in just-bash. The fix checks for non-empty stdin before defaulting to ".". When stdin has content and no paths are given, searchContent is called directly on the stdin text with all applicable options (invert, count, context, etc). Also fixes the existing rg.utf8-stdin test which was previously passing by accident — it tested piped stdin but rg was actually searching the filesystem. Fixes #280 --- .../just-bash/src/commands/rg/rg-search.ts | 67 +++++++++++++++- .../src/commands/rg/rg.stdin.test.ts | 79 +++++++++++++++++++ .../src/commands/rg/rg.utf8-stdin.test.ts | 5 +- 3 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 packages/just-bash/src/commands/rg/rg.stdin.test.ts diff --git a/packages/just-bash/src/commands/rg/rg-search.ts b/packages/just-bash/src/commands/rg/rg-search.ts index a16f77a9..4679e185 100644 --- a/packages/just-bash/src/commands/rg/rg-search.ts +++ b/packages/just-bash/src/commands/rg/rg-search.ts @@ -116,9 +116,6 @@ export async function executeSearch( }; } - // Default to current directory - const paths = inputPaths.length === 0 ? ["."] : inputPaths; - // Determine case sensitivity const effectiveIgnoreCase = determineIgnoreCase(options, patterns); @@ -141,6 +138,70 @@ export async function executeSearch( }; } + // If no paths given and stdin has content, search stdin (like real rg). + // In a pipeline, the previous command's stdout becomes this command's + // stdin — search that text instead of defaulting to the current directory. + // Skip when `-f -` already consumed stdin for patterns to avoid + // double-consuming it as both pattern source and search input. + const stdinConsumedByPatternFile = options.patternFiles.includes("-"); + const stdinText = decodeBytesToUtf8(ctx.stdin); + if ( + inputPaths.length === 0 && + stdinText.length > 0 && + !stdinConsumedByPatternFile + ) { + const content = stdinText; + const result = searchContent(content, regex, { + invertMatch: options.invertMatch, + showLineNumbers: options.lineNumber, + countOnly: options.count, + countMatches: options.countMatches, + filename: "", + onlyMatching: options.onlyMatching, + beforeContext: options.beforeContext, + afterContext: options.afterContext, + maxCount: options.maxCount, + contextSeparator: options.contextSeparator, + showColumn: options.column, + vimgrep: options.vimgrep, + showByteOffset: options.byteOffset, + replace: + options.replace !== null ? convertReplacement(options.replace) : null, + passthru: options.passthru, + multiline: options.multiline, + kResetGroup, + }); + + if (options.quiet) { + return { stdout: "", stderr: "", exitCode: result.matched ? 0 : 1 }; + } + + if (options.filesWithMatches) { + return { + stdout: result.matched ? "(standard input)\n" : "", + stderr: "", + exitCode: result.matched ? 0 : 1, + }; + } + + if (options.filesWithoutMatch) { + return { + stdout: result.matched ? "" : "(standard input)\n", + stderr: "", + exitCode: result.matched ? 1 : 0, + }; + } + + return { + stdout: result.output, + stderr: "", + exitCode: result.matched ? 0 : 1, + }; + } + + // Default to current directory + const paths = inputPaths.length === 0 ? ["."] : inputPaths; + // Load gitignore files let gitignore: GitignoreManager | null = null; if (!options.noIgnore) { diff --git a/packages/just-bash/src/commands/rg/rg.stdin.test.ts b/packages/just-bash/src/commands/rg/rg.stdin.test.ts new file mode 100644 index 00000000..0fea5054 --- /dev/null +++ b/packages/just-bash/src/commands/rg/rg.stdin.test.ts @@ -0,0 +1,79 @@ +import { describe, expect, it } from "vitest"; +import { Bash } from "../../Bash.js"; + +describe("rg searches stdin when no paths are given", () => { + it("searches piped stdin instead of cwd", async () => { + const env = new Bash({ + files: { + // File exists but should NOT be searched — only stdin should be + "/decoy.txt": "decoy line\n", + }, + }); + const result = await env.exec( + 'printf "hello world\\ngoodbye\\n" | rg "hello"', + ); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("hello world"); + expect(result.stdout).not.toContain("decoy"); + }); + + it("returns exit code 1 when stdin has no match", async () => { + const env = new Bash({ files: {} }); + const result = await env.exec('echo "hello" | rg "xyz"'); + expect(result.exitCode).toBe(1); + expect(result.stdout).toBe(""); + }); + + it("supports case-insensitive search on stdin", async () => { + const env = new Bash({ files: {} }); + const result = await env.exec('printf "Hello World\\n" | rg -i "hello"'); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("Hello World"); + }); + + it("supports inverted match on stdin", async () => { + const env = new Bash({ files: {} }); + const result = await env.exec('printf "aaa\\nbbb\\nccc\\n" | rg -v "bbb"'); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("aaa"); + expect(result.stdout).toContain("ccc"); + expect(result.stdout).not.toContain("bbb"); + }); + + it("supports count mode on stdin", async () => { + const env = new Bash({ files: {} }); + const result = await env.exec('printf "foo\\nbar\\nfoo\\n" | rg -c "foo"'); + expect(result.exitCode).toBe(0); + expect(result.stdout.trim()).toBe("2"); + }); + + it("searches files when explicit path is given (not stdin)", async () => { + const env = new Bash({ + files: { "/data.txt": "target line\n" }, + }); + const result = await env.exec( + 'echo "stdin content" | rg "target" /data.txt', + ); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("target line"); + }); + + it("does not double-consume stdin when -f - is used", async () => { + const env = new Bash({ + files: { "/data.txt": "hello world\ngoodbye\n" }, + }); + // -f - reads patterns from stdin; rg should then search the explicit + // path, not try to also search stdin as content + const result = await env.exec('echo "hello" | rg -f - /data.txt'); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("hello world"); + }); + + it("supports multibyte UTF-8 patterns from piped stdin", async () => { + const env = new Bash({ files: {} }); + const result = await env.exec("printf '한글 found\\nmiss\\n' | rg '한글'"); + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain("한글 found"); + expect(result.stdout).not.toContain("miss"); + }); +}); diff --git a/packages/just-bash/src/commands/rg/rg.utf8-stdin.test.ts b/packages/just-bash/src/commands/rg/rg.utf8-stdin.test.ts index fc888924..5cdd4a88 100644 --- a/packages/just-bash/src/commands/rg/rg.utf8-stdin.test.ts +++ b/packages/just-bash/src/commands/rg/rg.utf8-stdin.test.ts @@ -8,9 +8,6 @@ describe("rg reads UTF-8 from stdin", () => { }); const result = await env.exec("cat /in.txt | rg '한글'"); expect(result.exitCode).toBe(0); - // rg prefixes matches from stdin with a `::` source - // identifier; the bytes after the last `:` are the matched line. - const matched = result.stdout.split(":").slice(2).join(":"); - expect(matched.trim()).toBe("한글 found"); + expect(result.stdout).toContain("한글 found"); }); }); From af2e0f4cdeb5417ea59e25140038c239dd8fd92d Mon Sep 17 00:00:00 2001 From: Ari <37885347+arimxyer@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:31:22 -0400 Subject: [PATCH 7/9] feat(sandbox): forward capability options through Sandbox.create (#284) Add the optional BashOptions capability flags (python, javascript, commands, customCommands, fetch) to SandboxOptions and forward them into the internal new Bash({...}) that Sandbox.create builds. They were previously dropped, so a host driving just-bash via the Sandbox API could not enable python3, js-exec, a restricted command set, custom commands, or a custom fetch even though the runtimes ship in the package. Behavior is unchanged when the fields are omitted (each falls back to its existing BashOptions default). Adds forwarding tests in the unit suite (customCommands + restricted commands) and a python3 end-to-end test in the WASM suite, plus a changeset. Signed-off-by: Ari Mayer Co-authored-by: Claude Opus 4.8 --- .../sandbox-forward-capability-options.md | 17 +++++++ .../commands/python3/python3.sandbox.test.ts | 25 +++++++++++ .../just-bash/src/sandbox/Sandbox.test.ts | 21 +++++++++ packages/just-bash/src/sandbox/Sandbox.ts | 44 ++++++++++++++++++- 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .changeset/sandbox-forward-capability-options.md create mode 100644 packages/just-bash/src/commands/python3/python3.sandbox.test.ts diff --git a/.changeset/sandbox-forward-capability-options.md b/.changeset/sandbox-forward-capability-options.md new file mode 100644 index 00000000..51ddda1b --- /dev/null +++ b/.changeset/sandbox-forward-capability-options.md @@ -0,0 +1,17 @@ +--- +"just-bash": minor +--- + +sandbox: forward capability flags from `SandboxOptions` into the underlying `Bash` + +`Sandbox.create(opts)` previously constructed its internal `Bash` with only a subset +of `BashOptions`, silently dropping the optional capability flags (`python`, +`javascript`, `commands`, `customCommands`, `fetch`). A host that drives just-bash +through the `Sandbox` API (rather than `new Bash(...)`) therefore could not enable +python3, js-exec, a restricted command set, custom commands, or a custom fetch — even +though the runtimes ship in the package. + +`SandboxOptions` now exposes those fields and `Sandbox.create` forwards them into the +`Bash` it builds. Behavior is unchanged when a caller omits them (each falls back to +its existing `BashOptions` default — Python/js-exec stay off, the full command set +stays available). Fixes the root cause behind vercel/eve#431. diff --git a/packages/just-bash/src/commands/python3/python3.sandbox.test.ts b/packages/just-bash/src/commands/python3/python3.sandbox.test.ts new file mode 100644 index 00000000..9118cf83 --- /dev/null +++ b/packages/just-bash/src/commands/python3/python3.sandbox.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from "vitest"; +import { Sandbox } from "../../sandbox/Sandbox.js"; + +// End-to-end proof that the `python` capability flag forwarded through +// `SandboxOptions` reaches the underlying `Bash` and actually registers the +// python3 command. Without forwarding, python3 stays unavailable even though +// the CPython runtime ships in the package (see vercel/eve#431). +describe("Sandbox.create({ python: true })", () => { + it( + "registers python3 when the capability is enabled", + { timeout: 60000 }, + async () => { + const sandbox = await Sandbox.create({ python: true }); + const cmd = await sandbox.runCommand("python3 --version"); + expect(await cmd.stdout()).toContain("Python 3."); + }, + ); + + it("leaves python3 unavailable by default", async () => { + const sandbox = await Sandbox.create(); + const cmd = await sandbox.runCommand("python3 --version"); + // Either "not found" or "not available" depending on the bundle context. + expect(await cmd.stderr()).toMatch(/command not (found|available)/); + }); +}); diff --git a/packages/just-bash/src/sandbox/Sandbox.test.ts b/packages/just-bash/src/sandbox/Sandbox.test.ts index d1d9d2b0..8941b8a9 100644 --- a/packages/just-bash/src/sandbox/Sandbox.test.ts +++ b/packages/just-bash/src/sandbox/Sandbox.test.ts @@ -1,5 +1,6 @@ import { PassThrough } from "node:stream"; import { describe, expect, it } from "vitest"; +import { defineCommand } from "../custom-commands.js"; import { Command, type OutputMessage, Sandbox } from "./Sandbox.js"; describe("Sandbox API", () => { @@ -32,6 +33,26 @@ describe("Sandbox API", () => { const stderr = await cmd.stderr(); expect(stderr).toContain("maximum recursion depth"); }); + + it("forwards customCommands through to the underlying Bash", async () => { + const greet = defineCommand("greet", async (args) => ({ + stdout: `hello ${args[0] ?? "world"}\n`, + stderr: "", + exitCode: 0, + })); + const sandbox = await Sandbox.create({ customCommands: [greet] }); + const cmd = await sandbox.runCommand("greet sandbox"); + expect((await cmd.stdout()).trim()).toBe("hello sandbox"); + }); + + it("forwards a restricted commands allow-list through to the underlying Bash", async () => { + const sandbox = await Sandbox.create({ commands: ["echo"] }); + const allowed = await sandbox.runCommand("echo ok"); + expect((await allowed.stdout()).trim()).toBe("ok"); + // A built-in outside the allow-list is not registered. + const denied = await sandbox.runCommand("grep foo"); + expect(await denied.stderr()).toContain("command not found"); + }); }); describe("sandbox.runCommand()", () => { diff --git a/packages/just-bash/src/sandbox/Sandbox.ts b/packages/just-bash/src/sandbox/Sandbox.ts index 1b6c6cb2..c1fa5d0c 100644 --- a/packages/just-bash/src/sandbox/Sandbox.ts +++ b/packages/just-bash/src/sandbox/Sandbox.ts @@ -1,9 +1,11 @@ import type { Writable } from "node:stream"; -import { Bash } from "../Bash.js"; +import { Bash, type JavaScriptConfig } from "../Bash.js"; +import type { CommandName } from "../commands/registry.js"; +import type { CustomCommand } from "../custom-commands.js"; import type { IFileSystem } from "../fs/interface.js"; import { OverlayFs } from "../fs/overlay-fs/index.js"; import { shellJoinArgs } from "../helpers/shell-quote.js"; -import type { NetworkConfig } from "../network/index.js"; +import type { NetworkConfig, SecureFetch } from "../network/index.js"; import type { DefenseInDepthConfig } from "../security/types.js"; import type { CommandFinished } from "./Command.js"; import { Command } from "./Command.js"; @@ -37,6 +39,35 @@ export interface SandboxOptions { * Monkey-patches dangerous JavaScript globals during bash execution. */ defenseInDepth?: DefenseInDepthConfig | boolean; + /** + * Enable the python3/python commands. Disabled by default: Python adds + * security surface (arbitrary code execution via CPython). Forwarded to + * the underlying `Bash`. + */ + python?: boolean; + /** + * Enable the js-exec command (sandboxed JavaScript via QuickJS). Accepts a + * boolean or a {@link JavaScriptConfig} (bootstrap code / `invokeTool` + * hook). Disabled by default. Forwarded to the underlying `Bash`. + */ + javascript?: boolean | JavaScriptConfig; + /** + * Restrict the registered command set. When omitted, all built-in commands + * are available; pass a list to allow only those. Forwarded to the + * underlying `Bash`. + */ + commands?: CommandName[]; + /** + * Custom commands registered alongside the built-ins (these take precedence + * over built-ins with the same name). Forwarded to the underlying `Bash`. + */ + customCommands?: CustomCommand[]; + /** + * Custom secure fetch implementation used instead of one derived from + * `network`. Providing either `fetch` or `network` registers the network + * commands (curl, wget). Forwarded to the underlying `Bash`. + */ + fetch?: SecureFetch; } export interface RunCommandParams { @@ -88,6 +119,15 @@ export class Sandbox { maxLoopIterations: opts?.maxLoopIterations, network: opts?.network, defenseInDepth: opts?.defenseInDepth, + // Capability flags: forwarded so a sandbox created via Sandbox.create + // can opt into the same optional features as `new Bash(...)`. Each is + // `undefined` when the caller omits it, falling back to the BashOptions + // default, so existing behavior is unchanged. + python: opts?.python, + javascript: opts?.javascript, + commands: opts?.commands, + customCommands: opts?.customCommands, + fetch: opts?.fetch, }); return new Sandbox(bashEnv, opts?.timeoutMs); } From bb9a20b851846cc9d96421ca983dd216b9bd4881 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 07:43:37 -0700 Subject: [PATCH 8/9] chore: release (#290) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/jq-nested-interp.md | 9 ------- .../sandbox-forward-capability-options.md | 17 ------------ examples/executor-tools/CHANGELOG.md | 8 ++++++ examples/executor-tools/package.json | 2 +- packages/just-bash-executor/CHANGELOG.md | 7 +++++ packages/just-bash-executor/package.json | 2 +- packages/just-bash/CHANGELOG.md | 26 +++++++++++++++++++ packages/just-bash/package.json | 2 +- 8 files changed, 44 insertions(+), 29 deletions(-) delete mode 100644 .changeset/jq-nested-interp.md delete mode 100644 .changeset/sandbox-forward-capability-options.md diff --git a/.changeset/jq-nested-interp.md b/.changeset/jq-nested-interp.md deleted file mode 100644 index 83918d34..00000000 --- a/.changeset/jq-nested-interp.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -"just-bash": patch ---- - -jq: allow nested double-quoted strings inside `"\(...)"` string interpolation - -jq string interpolation of the form `"\(...)"` that contained a nested double-quoted string — for example `"\(sub("T.*";""))"` or `"\(ltrimstr("ab"))"` — previously failed with a parse error. The tokenizer terminated the outer string at the first `"` it saw inside the interpolation expression, so the rest of the expression became orphaned tokens. - -The lexer now tracks `\(...)` depth while consuming a string literal and treats nested `"..."` pairs as opaque content while inside an interpolation, restoring them verbatim into the captured interpolation source. `parseStringInterpolation` similarly skips over nested strings when balancing parentheses, so the interpolation expression is captured as a whole and handed to the expression parser intact. diff --git a/.changeset/sandbox-forward-capability-options.md b/.changeset/sandbox-forward-capability-options.md deleted file mode 100644 index 51ddda1b..00000000 --- a/.changeset/sandbox-forward-capability-options.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -"just-bash": minor ---- - -sandbox: forward capability flags from `SandboxOptions` into the underlying `Bash` - -`Sandbox.create(opts)` previously constructed its internal `Bash` with only a subset -of `BashOptions`, silently dropping the optional capability flags (`python`, -`javascript`, `commands`, `customCommands`, `fetch`). A host that drives just-bash -through the `Sandbox` API (rather than `new Bash(...)`) therefore could not enable -python3, js-exec, a restricted command set, custom commands, or a custom fetch — even -though the runtimes ship in the package. - -`SandboxOptions` now exposes those fields and `Sandbox.create` forwards them into the -`Bash` it builds. Behavior is unchanged when a caller omits them (each falls back to -its existing `BashOptions` default — Python/js-exec stay off, the full command set -stays available). Fixes the root cause behind vercel/eve#431. diff --git a/examples/executor-tools/CHANGELOG.md b/examples/executor-tools/CHANGELOG.md index 80575de8..ec279b83 100644 --- a/examples/executor-tools/CHANGELOG.md +++ b/examples/executor-tools/CHANGELOG.md @@ -1,5 +1,13 @@ # executor-tools-example +## 1.0.6 + +### Patch Changes + +- Updated dependencies [[`7a5a0b9`](https://github.com/vercel-labs/just-bash/commit/7a5a0b9ae3bf0524722653cbf4b45e6bc176cf22), [`af2e0f4`](https://github.com/vercel-labs/just-bash/commit/af2e0f4cdeb5417ea59e25140038c239dd8fd92d)]: + - just-bash@3.1.0 + - @just-bash/executor@2.0.0 + ## 1.0.5 ### Patch Changes diff --git a/examples/executor-tools/package.json b/examples/executor-tools/package.json index 9e206d9f..d806ef2b 100644 --- a/examples/executor-tools/package.json +++ b/examples/executor-tools/package.json @@ -1,6 +1,6 @@ { "name": "executor-tools-example", - "version": "1.0.5", + "version": "1.0.6", "description": "Example of @just-bash/executor — inline tools + GraphQL/OpenAPI/MCP discovery", "type": "module", "scripts": { diff --git a/packages/just-bash-executor/CHANGELOG.md b/packages/just-bash-executor/CHANGELOG.md index 7977284e..3d21e98f 100644 --- a/packages/just-bash-executor/CHANGELOG.md +++ b/packages/just-bash-executor/CHANGELOG.md @@ -1,5 +1,12 @@ # @just-bash/executor +## 2.0.0 + +### Patch Changes + +- Updated dependencies [[`7a5a0b9`](https://github.com/vercel-labs/just-bash/commit/7a5a0b9ae3bf0524722653cbf4b45e6bc176cf22), [`af2e0f4`](https://github.com/vercel-labs/just-bash/commit/af2e0f4cdeb5417ea59e25140038c239dd8fd92d)]: + - just-bash@3.1.0 + ## 1.0.4 ### Patch Changes diff --git a/packages/just-bash-executor/package.json b/packages/just-bash-executor/package.json index 68221a60..c768ec2a 100644 --- a/packages/just-bash-executor/package.json +++ b/packages/just-bash-executor/package.json @@ -1,6 +1,6 @@ { "name": "@just-bash/executor", - "version": "1.0.4", + "version": "2.0.0", "description": "Experimental tool-invocation companion for just-bash. Wires @executor-js/sdk into js-exec via the invokeTool hook.", "repository": { "type": "git", diff --git a/packages/just-bash/CHANGELOG.md b/packages/just-bash/CHANGELOG.md index 17378a6a..d2085553 100644 --- a/packages/just-bash/CHANGELOG.md +++ b/packages/just-bash/CHANGELOG.md @@ -1,5 +1,31 @@ # just-bash +## 3.1.0 + +### Minor Changes + +- [#284](https://github.com/vercel-labs/just-bash/pull/284) [`af2e0f4`](https://github.com/vercel-labs/just-bash/commit/af2e0f4cdeb5417ea59e25140038c239dd8fd92d) Thanks [@arimxyer](https://github.com/arimxyer)! - sandbox: forward capability flags from `SandboxOptions` into the underlying `Bash` + + `Sandbox.create(opts)` previously constructed its internal `Bash` with only a subset + of `BashOptions`, silently dropping the optional capability flags (`python`, + `javascript`, `commands`, `customCommands`, `fetch`). A host that drives just-bash + through the `Sandbox` API (rather than `new Bash(...)`) therefore could not enable + python3, js-exec, a restricted command set, custom commands, or a custom fetch — even + though the runtimes ship in the package. + + `SandboxOptions` now exposes those fields and `Sandbox.create` forwards them into the + `Bash` it builds. Behavior is unchanged when a caller omits them (each falls back to + its existing `BashOptions` default — Python/js-exec stay off, the full command set + stays available). Fixes the root cause behind vercel/eve#431. + +### Patch Changes + +- [#268](https://github.com/vercel-labs/just-bash/pull/268) [`7a5a0b9`](https://github.com/vercel-labs/just-bash/commit/7a5a0b9ae3bf0524722653cbf4b45e6bc176cf22) Thanks [@trieloff](https://github.com/trieloff)! - jq: allow nested double-quoted strings inside `"\(...)"` string interpolation + + jq string interpolation of the form `"\(...)"` that contained a nested double-quoted string — for example `"\(sub("T.*";""))"` or `"\(ltrimstr("ab"))"` — previously failed with a parse error. The tokenizer terminated the outer string at the first `"` it saw inside the interpolation expression, so the rest of the expression became orphaned tokens. + + The lexer now tracks `\(...)` depth while consuming a string literal and treats nested `"..."` pairs as opaque content while inside an interpolation, restoring them verbatim into the captured interpolation source. `parseStringInterpolation` similarly skips over nested strings when balancing parentheses, so the interpolation expression is captured as a whole and handed to the expression parser intact. + ## 3.0.3 ### Patch Changes diff --git a/packages/just-bash/package.json b/packages/just-bash/package.json index 7e671142..ab9ff9b3 100644 --- a/packages/just-bash/package.json +++ b/packages/just-bash/package.json @@ -1,6 +1,6 @@ { "name": "just-bash", - "version": "3.0.3", + "version": "3.1.0", "description": "A simulated bash environment with virtual filesystem", "repository": { "type": "git", From cced8279beaf58428c53f2e231641ddbb92602eb Mon Sep 17 00:00:00 2001 From: "flowglad-sync[bot]" Date: Wed, 8 Jul 2026 15:02:12 +0000 Subject: [PATCH 9/9] build: dist for upstream sync @just-bash/executor@2.0.0 --- packages/just-bash/dist/Bash.js | 68 +- .../{chunk-4J4UC7OD.js => chunk-63LSI3D6.js} | 2 +- .../dist/bin/chunks/chunk-BKQLXMS6.js | 36 + .../dist/bin/chunks/chunk-GXX3QUMM.js | 34 - .../chunk-HZR3FOJM.js} | 2 +- .../dist/bin/chunks/chunk-ISLENKSH.js | 7 + .../dist/bin/chunks/chunk-LMA4D2KK.js | 7 - .../dist/bin/chunks/chunk-PDS5TEMS.js | 80 - .../{chunk-FJABJBIW.js => chunk-RO3XCUVQ.js} | 2 +- .../dist/bin/chunks/expansion-PCODPDNZ.js | 3 - ...-DFXMJJWX.js => flag-coverage-K737BGC5.js} | 2 +- .../chunks/{jq-33GJJXTL.js => jq-3V5HDGLJ.js} | 2 +- .../rg-2YWJS6TE.js => chunks/rg-DZKA632H.js} | 2 +- .../xan-TCTFON2Q.js} | 2 +- .../chunks/{yq-KU5YTNAK.js => yq-OB6PB5GY.js} | 2 +- packages/just-bash/dist/bin/just-bash.js | 672 +++---- .../{chunk-4J4UC7OD.js => chunk-63LSI3D6.js} | 2 +- .../dist/bin/shell/chunks/chunk-BKQLXMS6.js | 36 + .../dist/bin/shell/chunks/chunk-GXX3QUMM.js | 34 - .../chunks/chunk-HZR3FOJM.js} | 2 +- .../dist/bin/shell/chunks/chunk-ISLENKSH.js | 7 + .../dist/bin/shell/chunks/chunk-LMA4D2KK.js | 7 - .../dist/bin/shell/chunks/chunk-PDS5TEMS.js | 80 - .../{chunk-FJABJBIW.js => chunk-RO3XCUVQ.js} | 2 +- .../bin/shell/chunks/expansion-PCODPDNZ.js | 3 - ...-DFXMJJWX.js => flag-coverage-K737BGC5.js} | 2 +- .../chunks/{jq-33GJJXTL.js => jq-3V5HDGLJ.js} | 2 +- .../chunks/rg-DZKA632H.js} | 2 +- .../chunks/xan-TCTFON2Q.js} | 2 +- .../chunks/{yq-KU5YTNAK.js => yq-OB6PB5GY.js} | 2 +- packages/just-bash/dist/bin/shell/shell.js | 682 ++++---- packages/just-bash/dist/bundle/browser.js | 1161 ++++++------ .../{chunk-DJ7QC6LC.js => chunk-6Y4TGEZL.js} | 2 +- .../dist/bundle/chunks/chunk-J3LJZWL2.js | 6 + .../{chunk-AFQAPVZ3.js => chunk-JA7M2FXG.js} | 2 +- .../dist/bundle/chunks/chunk-JNYYVLEL.js | 35 + .../dist/bundle/chunks/chunk-LZUPLYFM.js | 6 - .../{chunk-EUCNMMRD.js => chunk-QM4DZQWX.js} | 2 +- .../dist/bundle/chunks/chunk-STFC2ZJT.js | 79 - .../dist/bundle/chunks/chunk-Z3KJQD7F.js | 33 - .../dist/bundle/chunks/expansion-CDGKP4VC.js | 2 - ...-QDZ2CB3R.js => flag-coverage-G6V6CBZ6.js} | 2 +- .../chunks/{jq-3FAAQVR6.js => jq-OPEF5OPR.js} | 2 +- .../chunks/{rg-N5WLPMSA.js => rg-EBMD72T4.js} | 2 +- .../{xan-U6654PZR.js => xan-LKYWG2QQ.js} | 2 +- .../chunks/{yq-ZBXLBSXV.js => yq-TVZ7R3O7.js} | 2 +- packages/just-bash/dist/bundle/index.cjs | 1553 ++++++++--------- packages/just-bash/dist/bundle/index.js | 690 ++++---- .../dist/commands/query-engine/parser.js | 70 +- .../just-bash/dist/commands/rg/rg-search.js | 57 +- .../dist/interpreter/redirections.js | 291 ++- .../interpreter/simple-command-assignments.js | 4 +- packages/just-bash/dist/sandbox/Sandbox.d.ts | 35 +- packages/just-bash/dist/sandbox/Sandbox.js | 9 + .../just-bash/dist/spec-tests/jq/skips.js | 5 - .../just-bash/dist/spec-tests/sed/skips.js | 16 - 56 files changed, 3010 insertions(+), 2846 deletions(-) rename packages/just-bash/dist/bin/chunks/{chunk-4J4UC7OD.js => chunk-63LSI3D6.js} (98%) create mode 100644 packages/just-bash/dist/bin/chunks/chunk-BKQLXMS6.js delete mode 100644 packages/just-bash/dist/bin/chunks/chunk-GXX3QUMM.js rename packages/just-bash/dist/bin/{shell/chunks/chunk-J7XTZ47D.js => chunks/chunk-HZR3FOJM.js} (99%) create mode 100644 packages/just-bash/dist/bin/chunks/chunk-ISLENKSH.js delete mode 100644 packages/just-bash/dist/bin/chunks/chunk-LMA4D2KK.js delete mode 100644 packages/just-bash/dist/bin/chunks/chunk-PDS5TEMS.js rename packages/just-bash/dist/bin/chunks/{chunk-FJABJBIW.js => chunk-RO3XCUVQ.js} (99%) delete mode 100644 packages/just-bash/dist/bin/chunks/expansion-PCODPDNZ.js rename packages/just-bash/dist/bin/chunks/{flag-coverage-DFXMJJWX.js => flag-coverage-K737BGC5.js} (94%) rename packages/just-bash/dist/bin/chunks/{jq-33GJJXTL.js => jq-3V5HDGLJ.js} (88%) rename packages/just-bash/dist/bin/{shell/chunks/rg-2YWJS6TE.js => chunks/rg-DZKA632H.js} (83%) rename packages/just-bash/dist/bin/{shell/chunks/xan-TSDTZVY3.js => chunks/xan-TCTFON2Q.js} (77%) rename packages/just-bash/dist/bin/chunks/{yq-KU5YTNAK.js => yq-OB6PB5GY.js} (75%) rename packages/just-bash/dist/bin/shell/chunks/{chunk-4J4UC7OD.js => chunk-63LSI3D6.js} (98%) create mode 100644 packages/just-bash/dist/bin/shell/chunks/chunk-BKQLXMS6.js delete mode 100644 packages/just-bash/dist/bin/shell/chunks/chunk-GXX3QUMM.js rename packages/just-bash/dist/bin/{chunks/chunk-J7XTZ47D.js => shell/chunks/chunk-HZR3FOJM.js} (99%) create mode 100644 packages/just-bash/dist/bin/shell/chunks/chunk-ISLENKSH.js delete mode 100644 packages/just-bash/dist/bin/shell/chunks/chunk-LMA4D2KK.js delete mode 100644 packages/just-bash/dist/bin/shell/chunks/chunk-PDS5TEMS.js rename packages/just-bash/dist/bin/shell/chunks/{chunk-FJABJBIW.js => chunk-RO3XCUVQ.js} (99%) delete mode 100644 packages/just-bash/dist/bin/shell/chunks/expansion-PCODPDNZ.js rename packages/just-bash/dist/bin/shell/chunks/{flag-coverage-DFXMJJWX.js => flag-coverage-K737BGC5.js} (94%) rename packages/just-bash/dist/bin/shell/chunks/{jq-33GJJXTL.js => jq-3V5HDGLJ.js} (88%) rename packages/just-bash/dist/bin/{chunks/rg-2YWJS6TE.js => shell/chunks/rg-DZKA632H.js} (83%) rename packages/just-bash/dist/bin/{chunks/xan-TSDTZVY3.js => shell/chunks/xan-TCTFON2Q.js} (77%) rename packages/just-bash/dist/bin/shell/chunks/{yq-KU5YTNAK.js => yq-OB6PB5GY.js} (75%) rename packages/just-bash/dist/bundle/chunks/{chunk-DJ7QC6LC.js => chunk-6Y4TGEZL.js} (99%) create mode 100644 packages/just-bash/dist/bundle/chunks/chunk-J3LJZWL2.js rename packages/just-bash/dist/bundle/chunks/{chunk-AFQAPVZ3.js => chunk-JA7M2FXG.js} (98%) create mode 100644 packages/just-bash/dist/bundle/chunks/chunk-JNYYVLEL.js delete mode 100644 packages/just-bash/dist/bundle/chunks/chunk-LZUPLYFM.js rename packages/just-bash/dist/bundle/chunks/{chunk-EUCNMMRD.js => chunk-QM4DZQWX.js} (99%) delete mode 100644 packages/just-bash/dist/bundle/chunks/chunk-STFC2ZJT.js delete mode 100644 packages/just-bash/dist/bundle/chunks/chunk-Z3KJQD7F.js delete mode 100644 packages/just-bash/dist/bundle/chunks/expansion-CDGKP4VC.js rename packages/just-bash/dist/bundle/chunks/{flag-coverage-QDZ2CB3R.js => flag-coverage-G6V6CBZ6.js} (94%) rename packages/just-bash/dist/bundle/chunks/{jq-3FAAQVR6.js => jq-OPEF5OPR.js} (87%) rename packages/just-bash/dist/bundle/chunks/{rg-N5WLPMSA.js => rg-EBMD72T4.js} (82%) rename packages/just-bash/dist/bundle/chunks/{xan-U6654PZR.js => xan-LKYWG2QQ.js} (77%) rename packages/just-bash/dist/bundle/chunks/{yq-ZBXLBSXV.js => yq-TVZ7R3O7.js} (74%) diff --git a/packages/just-bash/dist/Bash.js b/packages/just-bash/dist/Bash.js index 17985ff2..612248f1 100644 --- a/packages/just-bash/dist/Bash.js +++ b/packages/just-bash/dist/Bash.js @@ -549,8 +549,51 @@ export class Bash { } } /** - * Normalize a script by stripping leading whitespace from lines, - * while preserving whitespace inside heredoc content. + * Track open single/double-quote state across one physical line, starting from + * `start` (the state carried over from the previous line). Used by + * normalizeScript to know whether a line begins inside a multi-line quoted + * string, where leading whitespace is literal and must not be trimmed. + * + * Only single and double quotes matter: those are the contexts where leading + * whitespace is significant. Backslash escapes and `#` comments are honored so + * a quote inside a comment (e.g. `# don't`) doesn't desync the state. + */ +function scanLineQuoteState(line, start) { + let state = start; + for (let i = 0; i < line.length; i++) { + const ch = line[i]; + if (state === "single") { + // Inside single quotes only a closing quote is special (no escapes). + if (ch === "'") + state = "none"; + } + else if (state === "double") { + if (ch === "\\") { + i++; // backslash escapes the next char inside double quotes + } + else if (ch === '"') { + state = "none"; + } + } + else if (ch === "'") { + state = "single"; + } + else if (ch === '"') { + state = "double"; + } + else if (ch === "\\") { + i++; // backslash escapes the next char (e.g. \" or \') + } + else if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) { + break; // start of a comment: the rest of the line is not shell-significant + } + } + return state; +} +/** + * Normalize a script by stripping leading whitespace from lines, while + * preserving whitespace inside heredoc content and inside multi-line quoted + * strings. * * This allows writing indented bash scripts in template literals: * ``` @@ -561,6 +604,11 @@ export class Bash { * `); * ``` * + * Leading whitespace is only stripped from lines that begin outside any quote. + * A line that begins inside an unterminated single- or double-quoted string is + * literal quoted content (e.g. the body of `python3 -c "..."`), so it is kept + * verbatim. + * * Heredocs are detected by looking for << or <<- operators and their delimiters. */ function normalizeScript(script) { @@ -568,6 +616,9 @@ function normalizeScript(script) { const result = []; // Stack of pending heredoc delimiters (for nested heredocs) const pendingDelimiters = []; + // Open single/double-quote state carried across lines. When a line begins + // inside an open quote, its leading whitespace is literal and preserved. + let quoteState = "none"; for (let i = 0; i < lines.length; i++) { const line = lines[i]; // If we're inside a heredoc, check if this line ends it @@ -586,9 +637,18 @@ function normalizeScript(script) { result.push(line); continue; } - // Not inside a heredoc - normalize the line and check for heredoc starts - const normalizedLine = line.trimStart(); + // Not inside a heredoc. Lines that begin inside an open quote are literal + // quoted content (leading whitespace is significant), so preserve them + // verbatim; otherwise strip leading indentation. + const startState = quoteState; + const normalizedLine = startState === "none" ? line.trimStart() : line; result.push(normalizedLine); + quoteState = scanLineQuoteState(line, startState); + // Only detect heredoc operators on lines that begin outside any quote; + // a `<=i)break;let a=s,r=t[s];if(r==="{"||r==="["){let f=r,c=r==="{"?"}":"]",p=1,m=!1,d=!1;for(s++;s0;){let j=t[s];d?d=!1:j==="\\"?d=!0:j==='"'?m=!m:m||(j===f?p++:j===c&&p--),s++}if(p!==0)throw new Error(`Unexpected end of JSON input at position ${s} (unclosed ${f})`);n.push(E(k(t,a,s)))}else if(r==='"'){let f=!1;for(s++;s="0"&&r<="9"){for(;sC(p,!0,!1,i,a)).join(",")}]`:`[ ${t.map(p=>f.repeat(r+1)+C(p,!1,!1,i,a,r+1)).join(`, `)} diff --git a/packages/just-bash/dist/bin/chunks/chunk-BKQLXMS6.js b/packages/just-bash/dist/bin/chunks/chunk-BKQLXMS6.js new file mode 100644 index 00000000..9a3d2b41 --- /dev/null +++ b/packages/just-bash/dist/bin/chunks/chunk-BKQLXMS6.js @@ -0,0 +1,36 @@ +#!/usr/bin/env node +import{createRequire} from"node:module";const require=createRequire(import.meta.url); +import{f as G}from"./chunk-MLUOPG3W.js";import{a as q}from"./chunk-3MRB66F4.js";import{a as B,b as U,c as A}from"./chunk-UI7CV277.js";import{a as M}from"./chunk-52FZYTIX.js";import{a as D}from"./chunk-DHIKZU63.js";import{a as z,b as E,c as O}from"./chunk-MUFNRCMY.js";var H=G({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),$=class{types;constructor(){this.types=new Map(Object.entries(H).map(([t,s])=>[t,{extensions:[...s.extensions],globs:[...s.globs]}]))}addType(t){let s=t.indexOf(":");if(s===-1)return;let n=t.slice(0,s),r=t.slice(s+1);if(r.startsWith("include:")){let l=r.slice(8),i=this.types.get(l);if(i){let o=this.types.get(n)||{extensions:[],globs:[]};o.extensions.push(...i.extensions),o.globs.push(...i.globs),this.types.set(n,o)}}else{let l=this.types.get(n)||{extensions:[],globs:[]};if(r.startsWith("*.")&&!r.slice(2).includes("*")){let i=r.slice(1);l.extensions.includes(i)||l.extensions.push(i)}else l.globs.includes(r)||l.globs.push(r);this.types.set(n,l)}}clearType(t){let s=this.types.get(t);s&&(s.extensions=[],s.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,s){let n=t.toLowerCase();for(let r of s){if(r==="all"){if(this.matchesAnyType(t))return!0;continue}let l=this.types.get(r);if(l){for(let i of l.extensions)if(n.endsWith(i))return!0;for(let i of l.globs)if(i.includes("*")){let o=i.replace(/\./g,"\\.").replace(/\*/g,".*");if(M(`^${o}$`,"i").test(t))return!0}else if(n===i.toLowerCase())return!0}}return!1}matchesAnyType(t){let s=t.toLowerCase();for(let n of this.types.values()){for(let r of n.extensions)if(s.endsWith(r))return!0;for(let r of n.globs)if(r.includes("*")){let l=r.replace(/\./g,"\\.").replace(/\*/g,".*");if(M(`^${l}$`,"i").test(t))return!0}else if(s===r.toLowerCase())return!0}return!1}};function V(){let e=[];for(let[t,s]of Object.entries(H).sort()){let n=[];for(let r of s.extensions)n.push(`*${r}`);for(let r of s.globs)n.push(r);e.push(`${t}: ${n.join(", ")}`)}return`${e.join(` +`)} +`}function Z(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}function se(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let s=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return s*1024;case"M":return s*1024*1024;case"G":return s*1024*1024*1024;default:return s}}function ne(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} +`,exitCode:1}}function J(e){return null}var Y=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:J},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:J},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:se,validate:ne},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],re=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),ie=new Set(["n","--line-number"]);function le(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function oe(e,t,s){let n=e[t];for(let r of Y){if(n.startsWith(`--${r.long}=`)){let l=n.slice(`--${r.long}=`.length),i=P(s,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&n.startsWith(`-${r.short}`)&&n.length>2){let l=n.slice(2),i=P(s,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&n===`-${r.short}`||n===`--${r.long}`){if(t+1>=e.length)return null;let l=e[t+1],i=P(s,r,l);return i?{newIndex:t+1,error:i}:{newIndex:t+1}}}return null}function ae(e){return Y.find(t=>t.short===e)}function P(e,t,s){if(t.validate){let r=t.validate(s);if(r)return r}if(t.ignored||!t.target)return;let n=t.parse?t.parse(s):s;t.multi?e[t.target].push(n):e[t.target]=n}function ce(e,t){let s=e[t];if(s==="--sort"&&t+1=e.length)return{success:!1,error:O("rg",`-${u}`)};let f=P(t,g,e[c+1]);if(f)return{success:!1,error:f};c++,m=!0;continue}}let w=re.get(u);if(w){w(t);continue}if(u.startsWith("--"))return{success:!1,error:O("rg",u)};if(u.length===1)return{success:!1,error:O("rg",`-${u}`)}}}else s===null&&t.patterns.length===0&&t.patternFiles.length===0?s=a:n.push(a)}return(r>=0||i>=0)&&(t.afterContext=Math.max(r>=0?r:0,i>=0?i:0)),(l>=0||i>=0)&&(t.beforeContext=Math.max(l>=0?l:0,i>=0?i:0)),s!==null&&t.patterns.push(s),(t.column||t.vimgrep)&&(o=!0),{success:!0,options:t,paths:n,explicitLineNumbers:o}}import{gunzipSync as he}from"node:zlib";var T=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let s=t.split(` +`);for(let n of s){let r=n.replace(/\s+$/,"");if(!r||r.startsWith("#"))continue;let l=!1;r.startsWith("!")&&(l=!0,r=r.slice(1));let i=!1;r.endsWith("/")&&(i=!0,r=r.slice(0,-1));let o=!1;r.startsWith("/")?(o=!0,r=r.slice(1)):r.includes("/")&&!r.startsWith("**/")&&(o=!0);let c=this.patternToRegex(r,o);this.patterns.push({pattern:n,regex:c,negated:l,directoryOnly:i,rooted:o})}}patternToRegex(t,s){let n="";s?n="^":n="(?:^|/)";let r=0;for(;r=t.length,n+=".*",r+=2):(n+="[^/]*",r++);else if(l==="?")n+="[^/]",r++;else if(l==="["){let i=r+1;for(i=2&&e[0]===31&&e[1]===139}function pe(e){let t=!1;for(let s=0;sv.length>0);l.push(...d)}catch{return{stdout:"",stderr:`rg: ${g}: No such file or directory +`,exitCode:2}}if(l.length===0)return s.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given +`,exitCode:2};let i=de(s,l),o,c;try{let g=me(l,s,i);o=g.regex,c=g.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${l.join(", ")} +`,exitCode:2}}let a=s.patternFiles.includes("-"),h=D(t.stdin);if(n.length===0&&h.length>0&&!a){let f=B(h,o,{invertMatch:s.invertMatch,showLineNumbers:s.lineNumber,countOnly:s.count,countMatches:s.countMatches,filename:"",onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace!==null?A(s.replace):null,passthru:s.passthru,multiline:s.multiline,kResetGroup:c});return s.quiet?{stdout:"",stderr:"",exitCode:f.matched?0:1}:s.filesWithMatches?{stdout:f.matched?`(standard input) +`:"",stderr:"",exitCode:f.matched?0:1}:s.filesWithoutMatch?{stdout:f.matched?"":`(standard input) +`,stderr:"",exitCode:f.matched?1:0}:{stdout:f.output,stderr:"",exitCode:f.matched?0:1}}let y=n.length===0?["."]:n,x=null;s.noIgnore||(x=await R(t.fs,t.cwd,s.noIgnoreDot,s.noIgnoreVcs,s.ignoreFiles));let p=new $;for(let g of s.typeClear)p.clearType(g);for(let g of s.typeAdd)p.addType(g);let{files:b,singleExplicitFile:m}=await Q(t,y,s,x,p);if(b.length===0)return{stdout:"",stderr:"",exitCode:1};let u=!s.noFilename&&(s.withFilename||!m||b.length>1),w=s.lineNumber;return r||(m&&b.length===1&&(w=!1),s.onlyMatching&&(w=!1)),we(t,b,o,s,u,w,c)}function de(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(s=>/[A-Z]/.test(s)):!1}function me(e,t,s){let n;return e.length===1?n=e[0]:n=e.map(r=>t.fixedStrings?r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${r})`).join("|"),U(n,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:s,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function Q(e,t,s,n,r){let l=[],i=0,o=0;for(let a of t){let h=e.fs.resolvePath(e.cwd,a);try{let y=await e.fs.stat(h);if(y.isFile){if(i++,s.maxFilesize>0&&y.size>s.maxFilesize)continue;te(a,s,n,h,r)&&l.push(a)}else y.isDirectory&&(o++,await ee(e,a,h,0,s,n,r,l))}catch{}}return{files:s.sort==="path"?l.sort():l,singleExplicitFile:i===1&&o===0}}async function ee(e,t,s,n,r,l,i,o){if(!(n>=r.maxDepth)){l&&await l.loadForDirectory(s);try{let c=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(s):(await e.fs.readdir(s)).map(a=>({name:a,isFile:void 0}));for(let a of c){let h=a.name;if(!r.noIgnore&&N.isCommonIgnored(h))continue;let y=h.startsWith("."),x=t==="."?h:t==="./"?`./${h}`:t.endsWith("/")?`${t}${h}`:`${t}/${h}`,p=e.fs.resolvePath(s,h),b,m,u=!1;if(a.isFile!==void 0&&"isDirectory"in a){let f=a;if(u=f.isSymbolicLink===!0,u&&!r.followSymlinks)continue;if(u&&r.followSymlinks)try{let d=await e.fs.stat(p);b=d.isFile,m=d.isDirectory}catch{continue}else b=f.isFile,m=f.isDirectory}else try{let f=e.fs.lstat?await e.fs.lstat(p):await e.fs.stat(p);if(u=f.isSymbolicLink===!0,u&&!r.followSymlinks)continue;let d=u&&r.followSymlinks?await e.fs.stat(p):f;b=d.isFile,m=d.isDirectory}catch{continue}if(!l?.matches(p,m)&&!(y&&!r.hidden&&!l?.isWhitelisted(p,m))){if(m)await ee(e,x,p,n+1,r,l,i,o);else if(b){if(r.maxFilesize>0)try{if((await e.fs.stat(p)).size>r.maxFilesize)continue}catch{continue}te(x,r,l,p,i)&&o.push(x)}}}}catch{}}}function te(e,t,s,n,r){let l=e.split("/").pop()||e;if(s?.matches(n,!1)||t.types.length>0&&!r.matchesType(l,t.types)||t.typesNot.length>0&&r.matchesType(l,t.typesNot))return!1;if(t.globs.length>0){let i=t.globCaseInsensitive,o=t.globs.filter(a=>!a.startsWith("!")),c=t.globs.filter(a=>a.startsWith("!")).map(a=>a.slice(1));if(o.length>0){let a=!1;for(let h of o)if(C(l,h,i)||C(e,h,i)){a=!0;break}if(!a)return!1}for(let a of c)if(a.startsWith("/")){let h=a.slice(1);if(C(e,h,i))return!1}else if(C(l,a,i)||C(e,a,i))return!1}if(t.iglobs.length>0){let i=t.iglobs.filter(c=>!c.startsWith("!")),o=t.iglobs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(i.length>0){let c=!1;for(let a of i)if(C(l,a,!0)||C(e,a,!0)){c=!0;break}if(!c)return!1}for(let c of o)if(c.startsWith("/")){let a=c.slice(1);if(C(e,a,!0))return!1}else if(C(l,c,!0)||C(e,c,!0))return!1}return!0}function C(e,t,s=!1){let n="^";for(let r=0;ra+o).join(""),stderr:"",exitCode:0}}function ye(e,t){if(t.length===0)return!0;for(let s of t)if(C(e,s,!1))return!0;return!1}async function be(e,t,s,n){try{if(n.preprocessor&&e.exec){let i=s.split("/").pop()||s;if(ye(i,n.preprocessorGlobs)){let o=await e.exec(q([n.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(o.exitCode===0&&o.stdout){let c=D(o.stdout),a=c.slice(0,8192);return{content:c,isBinary:a.includes("\0")}}}}if(n.searchZip&&s.endsWith(".gz")){let i=await e.fs.readFileBuffer(t);if(ge(i))try{let o=he(i),c=new TextDecoder().decode(o),a=c.slice(0,8192);return{content:c,isBinary:a.includes("\0")}}catch{return null}}let r=await e.fs.readFile(t),l=r.slice(0,8192);return{content:r,isBinary:l.includes("\0")}}catch{return null}}async function we(e,t,s,n,r,l,i){let o="",c=!1,a=[],h=0,y=0,x=0,p=50;e:for(let u=0;u{let d=e.fs.resolvePath(e.cwd,f),v=await be(e,d,f,n);if(!v)return null;let{content:F,isBinary:W}=v;if(x+=F.length,W&&!n.searchBinary)return null;let k=r&&!n.heading?f:"",I=B(F,s,{invertMatch:n.invertMatch,showLineNumbers:l,countOnly:n.count,countMatches:n.countMatches,filename:k,onlyMatching:n.onlyMatching,beforeContext:n.beforeContext,afterContext:n.afterContext,maxCount:n.maxCount,contextSeparator:n.contextSeparator,showColumn:n.column,vimgrep:n.vimgrep,showByteOffset:n.byteOffset,replace:n.replace!==null?A(n.replace):null,passthru:n.passthru,multiline:n.multiline,kResetGroup:i});return n.json&&I.matched?{file:f,result:I,content:F,isBinary:!1}:{file:f,result:I}}));for(let f of g){if(!f)continue;let{file:d,result:v}=f;if(v.matched){if(c=!0,y++,h+=v.matchCount,n.quiet&&!n.json)break e;if(n.json&&!n.quiet){let F=f.content||"";a.push(JSON.stringify({type:"begin",data:{path:{text:d}}}));let W=F.split(` +`);s.lastIndex=0;let k=0;for(let I=0;I0){let S={type:"match",data:{path:{text:d},lines:{text:`${j} +`},line_number:I+1,absolute_offset:k,submatches:L}};a.push(JSON.stringify(S))}k+=j.length+1}a.push(JSON.stringify({type:"end",data:{path:{text:d},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:F.length,bytes_printed:0,matched_lines:v.matchCount,matches:v.matchCount}}}))}else if(n.filesWithMatches){let F=n.nullSeparator?"\0":` +`;o+=`${d}${F}`}else n.filesWithoutMatch||(n.heading&&!n.noFilename&&(o+=`${d} +`),o+=v.output)}else if(n.filesWithoutMatch){let F=n.nullSeparator?"\0":` +`;o+=`${d}${F}`}else n.includeZero&&(n.count||n.countMatches)&&(o+=v.output)}}n.json&&(a.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:y,bytes_searched:x,bytes_printed:0,matched_lines:h,matches:h}}})),o=`${a.join(` +`)} +`);let b=n.quiet&&!n.json?"":o;if(n.stats&&!n.json){let u=["",`${h} matches`,`${h} matched lines`,`${y} files contained matches`,`${t.length} files searched`,`${x} bytes searched`].join(` +`);b+=`${u} +`}let m;return n.filesWithoutMatch?m=o.length>0?0:1:m=c?0:1,{stdout:b,stderr:"",exitCode:m}}var ve={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. +Unlike grep, rg is recursive by default and respects .gitignore files. + +EXAMPLES: + rg foo Search for 'foo' in current directory + rg foo src/ Search in src/ directory + rg -i foo Case-insensitive search + rg -w foo Match whole words only + rg -t js foo Search only JavaScript files + rg -g '*.ts' foo Search files matching glob + rg --hidden foo Include hidden files + rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ge={name:"rg",async execute(e,t){if(E(e))return z(ve);if(e.includes("--type-list"))return{stdout:V(),stderr:"",exitCode:0};let s=K(e);return s.success?X({ctx:t,options:s.options,paths:s.paths,explicitLineNumbers:s.explicitLineNumbers}):s.error}},qe={name:"rg",flags:[{flag:"-i",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-N",type:"boolean"},{flag:"--hidden",type:"boolean"},{flag:"--no-ignore",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-g",type:"value",valueHint:"pattern"},{flag:"-t",type:"value",valueHint:"string"},{flag:"-T",type:"value",valueHint:"string"}],needsArgs:!0};export{Ge as a,qe as b}; diff --git a/packages/just-bash/dist/bin/chunks/chunk-GXX3QUMM.js b/packages/just-bash/dist/bin/chunks/chunk-GXX3QUMM.js deleted file mode 100644 index a0295baa..00000000 --- a/packages/just-bash/dist/bin/chunks/chunk-GXX3QUMM.js +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{f as G}from"./chunk-MLUOPG3W.js";import{a as q}from"./chunk-3MRB66F4.js";import{a as z,b as E,c as U}from"./chunk-UI7CV277.js";import{a as $}from"./chunk-52FZYTIX.js";import{a as L}from"./chunk-DHIKZU63.js";import{a as B,b as _,c as D}from"./chunk-MUFNRCMY.js";var H=G({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),M=class{types;constructor(){this.types=new Map(Object.entries(H).map(([t,n])=>[t,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(t){let n=t.indexOf(":");if(n===-1)return;let s=t.slice(0,n),r=t.slice(n+1);if(r.startsWith("include:")){let l=r.slice(8),i=this.types.get(l);if(i){let a=this.types.get(s)||{extensions:[],globs:[]};a.extensions.push(...i.extensions),a.globs.push(...i.globs),this.types.set(s,a)}}else{let l=this.types.get(s)||{extensions:[],globs:[]};if(r.startsWith("*.")&&!r.slice(2).includes("*")){let i=r.slice(1);l.extensions.includes(i)||l.extensions.push(i)}else l.globs.includes(r)||l.globs.push(r);this.types.set(s,l)}}clearType(t){let n=this.types.get(t);n&&(n.extensions=[],n.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,n){let s=t.toLowerCase();for(let r of n){if(r==="all"){if(this.matchesAnyType(t))return!0;continue}let l=this.types.get(r);if(l){for(let i of l.extensions)if(s.endsWith(i))return!0;for(let i of l.globs)if(i.includes("*")){let a=i.replace(/\./g,"\\.").replace(/\*/g,".*");if($(`^${a}$`,"i").test(t))return!0}else if(s===i.toLowerCase())return!0}}return!1}matchesAnyType(t){let n=t.toLowerCase();for(let s of this.types.values()){for(let r of s.extensions)if(n.endsWith(r))return!0;for(let r of s.globs)if(r.includes("*")){let l=r.replace(/\./g,"\\.").replace(/\*/g,".*");if($(`^${l}$`,"i").test(t))return!0}else if(n===r.toLowerCase())return!0}return!1}};function V(){let e=[];for(let[t,n]of Object.entries(H).sort()){let s=[];for(let r of n.extensions)s.push(`*${r}`);for(let r of n.globs)s.push(r);e.push(`${t}: ${s.join(", ")}`)}return`${e.join(` -`)} -`}function Z(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}function se(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let n=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return n*1024;case"M":return n*1024*1024;case"G":return n*1024*1024*1024;default:return n}}function ne(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} -`,exitCode:1}}function J(e){return null}var Y=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:J},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:J},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:se,validate:ne},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],re=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),ie=new Set(["n","--line-number"]);function le(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function oe(e,t,n){let s=e[t];for(let r of Y){if(s.startsWith(`--${r.long}=`)){let l=s.slice(`--${r.long}=`.length),i=P(n,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&s.startsWith(`-${r.short}`)&&s.length>2){let l=s.slice(2),i=P(n,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&s===`-${r.short}`||s===`--${r.long}`){if(t+1>=e.length)return null;let l=e[t+1],i=P(n,r,l);return i?{newIndex:t+1,error:i}:{newIndex:t+1}}}return null}function ae(e){return Y.find(t=>t.short===e)}function P(e,t,n){if(t.validate){let r=t.validate(n);if(r)return r}if(t.ignored||!t.target)return;let s=t.parse?t.parse(n):n;t.multi?e[t.target].push(s):e[t.target]=s}function ce(e,t){let n=e[t];if(n==="--sort"&&t+1=e.length)return{success:!1,error:D("rg",`-${f}`)};let h=P(t,b,e[c+1]);if(h)return{success:!1,error:h};c++,m=!0;continue}}let x=re.get(f);if(x){x(t);continue}if(f.startsWith("--"))return{success:!1,error:D("rg",f)};if(f.length===1)return{success:!1,error:D("rg",`-${f}`)}}}else n===null&&t.patterns.length===0&&t.patternFiles.length===0?n=o:s.push(o)}return(r>=0||i>=0)&&(t.afterContext=Math.max(r>=0?r:0,i>=0?i:0)),(l>=0||i>=0)&&(t.beforeContext=Math.max(l>=0?l:0,i>=0?i:0)),n!==null&&t.patterns.push(n),(t.column||t.vimgrep)&&(a=!0),{success:!0,options:t,paths:s,explicitLineNumbers:a}}import{gunzipSync as he}from"node:zlib";var T=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let n=t.split(` -`);for(let s of n){let r=s.replace(/\s+$/,"");if(!r||r.startsWith("#"))continue;let l=!1;r.startsWith("!")&&(l=!0,r=r.slice(1));let i=!1;r.endsWith("/")&&(i=!0,r=r.slice(0,-1));let a=!1;r.startsWith("/")?(a=!0,r=r.slice(1)):r.includes("/")&&!r.startsWith("**/")&&(a=!0);let c=this.patternToRegex(r,a);this.patterns.push({pattern:s,regex:c,negated:l,directoryOnly:i,rooted:a})}}patternToRegex(t,n){let s="";n?s="^":s="(?:^|/)";let r=0;for(;r=t.length,s+=".*",r+=2):(s+="[^/]*",r++);else if(l==="?")s+="[^/]",r++;else if(l==="["){let i=r+1;for(i=2&&e[0]===31&&e[1]===139}function pe(e){let t=!1;for(let n=0;nh.length>0);l.push(...b)}catch{return{stdout:"",stderr:`rg: ${f}: No such file or directory -`,exitCode:2}}if(l.length===0)return n.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given -`,exitCode:2};let i=s.length===0?["."]:s,a=me(n,l),c,o;try{let f=de(l,n,a);c=f.regex,o=f.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${l.join(", ")} -`,exitCode:2}}let u=null;n.noIgnore||(u=await A(t.fs,t.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let d=new M;for(let f of n.typeClear)d.clearType(f);for(let f of n.typeAdd)d.addType(f);let{files:p,singleExplicitFile:g}=await Q(t,i,n,u,d);if(p.length===0)return{stdout:"",stderr:"",exitCode:1};let w=!n.noFilename&&(n.withFilename||!g||p.length>1),m=n.lineNumber;return r||(g&&p.length===1&&(m=!1),n.onlyMatching&&(m=!1)),we(t,p,c,n,w,m,o)}function me(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(n=>/[A-Z]/.test(n)):!1}function de(e,t,n){let s;return e.length===1?s=e[0]:s=e.map(r=>t.fixedStrings?r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${r})`).join("|"),E(s,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:n,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function Q(e,t,n,s,r){let l=[],i=0,a=0;for(let o of t){let u=e.fs.resolvePath(e.cwd,o);try{let d=await e.fs.stat(u);if(d.isFile){if(i++,n.maxFilesize>0&&d.size>n.maxFilesize)continue;te(o,n,s,u,r)&&l.push(o)}else d.isDirectory&&(a++,await ee(e,o,u,0,n,s,r,l))}catch{}}return{files:n.sort==="path"?l.sort():l,singleExplicitFile:i===1&&a===0}}async function ee(e,t,n,s,r,l,i,a){if(!(s>=r.maxDepth)){l&&await l.loadForDirectory(n);try{let c=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(n):(await e.fs.readdir(n)).map(o=>({name:o,isFile:void 0}));for(let o of c){let u=o.name;if(!r.noIgnore&&k.isCommonIgnored(u))continue;let d=u.startsWith("."),p=t==="."?u:t==="./"?`./${u}`:t.endsWith("/")?`${t}${u}`:`${t}/${u}`,g=e.fs.resolvePath(n,u),w,m,f=!1;if(o.isFile!==void 0&&"isDirectory"in o){let h=o;if(f=h.isSymbolicLink===!0,f&&!r.followSymlinks)continue;if(f&&r.followSymlinks)try{let y=await e.fs.stat(g);w=y.isFile,m=y.isDirectory}catch{continue}else w=h.isFile,m=h.isDirectory}else try{let h=e.fs.lstat?await e.fs.lstat(g):await e.fs.stat(g);if(f=h.isSymbolicLink===!0,f&&!r.followSymlinks)continue;let y=f&&r.followSymlinks?await e.fs.stat(g):h;w=y.isFile,m=y.isDirectory}catch{continue}if(!l?.matches(g,m)&&!(d&&!r.hidden&&!l?.isWhitelisted(g,m))){if(m)await ee(e,p,g,s+1,r,l,i,a);else if(w){if(r.maxFilesize>0)try{if((await e.fs.stat(g)).size>r.maxFilesize)continue}catch{continue}te(p,r,l,g,i)&&a.push(p)}}}}catch{}}}function te(e,t,n,s,r){let l=e.split("/").pop()||e;if(n?.matches(s,!1)||t.types.length>0&&!r.matchesType(l,t.types)||t.typesNot.length>0&&r.matchesType(l,t.typesNot))return!1;if(t.globs.length>0){let i=t.globCaseInsensitive,a=t.globs.filter(o=>!o.startsWith("!")),c=t.globs.filter(o=>o.startsWith("!")).map(o=>o.slice(1));if(a.length>0){let o=!1;for(let u of a)if(v(l,u,i)||v(e,u,i)){o=!0;break}if(!o)return!1}for(let o of c)if(o.startsWith("/")){let u=o.slice(1);if(v(e,u,i))return!1}else if(v(l,o,i)||v(e,o,i))return!1}if(t.iglobs.length>0){let i=t.iglobs.filter(c=>!c.startsWith("!")),a=t.iglobs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(i.length>0){let c=!1;for(let o of i)if(v(l,o,!0)||v(e,o,!0)){c=!0;break}if(!c)return!1}for(let c of a)if(c.startsWith("/")){let o=c.slice(1);if(v(e,o,!0))return!1}else if(v(l,c,!0)||v(e,c,!0))return!1}return!0}function v(e,t,n=!1){let s="^";for(let r=0;ro+a).join(""),stderr:"",exitCode:0}}function ye(e,t){if(t.length===0)return!0;for(let n of t)if(v(e,n,!1))return!0;return!1}async function be(e,t,n,s){try{if(s.preprocessor&&e.exec){let i=n.split("/").pop()||n;if(ye(i,s.preprocessorGlobs)){let a=await e.exec(q([s.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(a.exitCode===0&&a.stdout){let c=L(a.stdout),o=c.slice(0,8192);return{content:c,isBinary:o.includes("\0")}}}}if(s.searchZip&&n.endsWith(".gz")){let i=await e.fs.readFileBuffer(t);if(ge(i))try{let a=he(i),c=new TextDecoder().decode(a),o=c.slice(0,8192);return{content:c,isBinary:o.includes("\0")}}catch{return null}}let r=await e.fs.readFile(t),l=r.slice(0,8192);return{content:r,isBinary:l.includes("\0")}}catch{return null}}async function we(e,t,n,s,r,l,i){let a="",c=!1,o=[],u=0,d=0,p=0,g=50;e:for(let f=0;f{let y=e.fs.resolvePath(e.cwd,h),F=await be(e,y,h,s);if(!F)return null;let{content:C,isBinary:N}=F;if(p+=C.length,N&&!s.searchBinary)return null;let W=r&&!s.heading?h:"",S=z(C,n,{invertMatch:s.invertMatch,showLineNumbers:l,countOnly:s.count,countMatches:s.countMatches,filename:W,onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace!==null?U(s.replace):null,passthru:s.passthru,multiline:s.multiline,kResetGroup:i});return s.json&&S.matched?{file:h,result:S,content:C,isBinary:!1}:{file:h,result:S}}));for(let h of b){if(!h)continue;let{file:y,result:F}=h;if(F.matched){if(c=!0,d++,u+=F.matchCount,s.quiet&&!s.json)break e;if(s.json&&!s.quiet){let C=h.content||"";o.push(JSON.stringify({type:"begin",data:{path:{text:y}}}));let N=C.split(` -`);n.lastIndex=0;let W=0;for(let S=0;S0){let I={type:"match",data:{path:{text:y},lines:{text:`${j} -`},line_number:S+1,absolute_offset:W,submatches:O}};o.push(JSON.stringify(I))}W+=j.length+1}o.push(JSON.stringify({type:"end",data:{path:{text:y},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:C.length,bytes_printed:0,matched_lines:F.matchCount,matches:F.matchCount}}}))}else if(s.filesWithMatches){let C=s.nullSeparator?"\0":` -`;a+=`${y}${C}`}else s.filesWithoutMatch||(s.heading&&!s.noFilename&&(a+=`${y} -`),a+=F.output)}else if(s.filesWithoutMatch){let C=s.nullSeparator?"\0":` -`;a+=`${y}${C}`}else s.includeZero&&(s.count||s.countMatches)&&(a+=F.output)}}s.json&&(o.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:d,bytes_searched:p,bytes_printed:0,matched_lines:u,matches:u}}})),a=`${o.join(` -`)} -`);let w=s.quiet&&!s.json?"":a;if(s.stats&&!s.json){let f=["",`${u} matches`,`${u} matched lines`,`${d} files contained matches`,`${t.length} files searched`,`${p} bytes searched`].join(` -`);w+=`${f} -`}let m;return s.filesWithoutMatch?m=a.length>0?0:1:m=c?0:1,{stdout:w,stderr:"",exitCode:m}}var ve={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. -Unlike grep, rg is recursive by default and respects .gitignore files. - -EXAMPLES: - rg foo Search for 'foo' in current directory - rg foo src/ Search in src/ directory - rg -i foo Case-insensitive search - rg -w foo Match whole words only - rg -t js foo Search only JavaScript files - rg -g '*.ts' foo Search files matching glob - rg --hidden foo Include hidden files - rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ge={name:"rg",async execute(e,t){if(_(e))return B(ve);if(e.includes("--type-list"))return{stdout:V(),stderr:"",exitCode:0};let n=K(e);return n.success?X({ctx:t,options:n.options,paths:n.paths,explicitLineNumbers:n.explicitLineNumbers}):n.error}},qe={name:"rg",flags:[{flag:"-i",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-N",type:"boolean"},{flag:"--hidden",type:"boolean"},{flag:"--no-ignore",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-g",type:"value",valueHint:"pattern"},{flag:"-t",type:"value",valueHint:"string"},{flag:"-T",type:"value",valueHint:"string"}],needsArgs:!0};export{Ge as a,qe as b}; diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-J7XTZ47D.js b/packages/just-bash/dist/bin/chunks/chunk-HZR3FOJM.js similarity index 99% rename from packages/just-bash/dist/bin/shell/chunks/chunk-J7XTZ47D.js rename to packages/just-bash/dist/bin/chunks/chunk-HZR3FOJM.js index 6cf0cff5..b3af3108 100644 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-J7XTZ47D.js +++ b/packages/just-bash/dist/bin/chunks/chunk-HZR3FOJM.js @@ -1,6 +1,6 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as $l}from"./chunk-MNWK4UIM.js";import{a as Be,b as er}from"./chunk-LMA4D2KK.js";import{d as D}from"./chunk-MLUOPG3W.js";import{a as Qi,b as Zi}from"./chunk-AZH64XMJ.js";import{a as Bs}from"./chunk-LX2H4DPL.js";import{a as Hi}from"./chunk-DHIKZU63.js";import{k as Vs}from"./chunk-47WZ2U6M.js";import{a as js}from"./chunk-PBOVSFTJ.js";import{a as Xi,b as zi,c as he}from"./chunk-MUFNRCMY.js";import{a as Ot,c as w,e as Fs}from"./chunk-LNVSXNT7.js";var xr=w((xm,_r)=>{var{hasOwnProperty:nn}=Object.prototype,rn=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r +import{a as $l}from"./chunk-MNWK4UIM.js";import{a as Be,b as er}from"./chunk-ISLENKSH.js";import{d as D}from"./chunk-MLUOPG3W.js";import{a as Qi,b as Zi}from"./chunk-AZH64XMJ.js";import{a as Bs}from"./chunk-LX2H4DPL.js";import{a as Hi}from"./chunk-DHIKZU63.js";import{k as Vs}from"./chunk-47WZ2U6M.js";import{a as js}from"./chunk-PBOVSFTJ.js";import{a as Xi,b as zi,c as he}from"./chunk-MUFNRCMY.js";import{a as Ot,c as w,e as Fs}from"./chunk-LNVSXNT7.js";var xr=w((xm,_r)=>{var{hasOwnProperty:nn}=Object.prototype,rn=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r `:` `,n=e.whitespace?" = ":"=",i=[],r=e.sort?Object.keys(s).sort():Object.keys(s),o=0;e.align&&(o=z(r.filter(c=>s[c]===null||Array.isArray(s[c])||typeof s[c]!="object").map(c=>Array.isArray(s[c])?`${c}[]`:c).concat([""]).reduce((c,u)=>z(c).length>=z(u).length?c:u)).length);let a="",l=e.bracketedArray?"[]":"";for(let c of r){let u=s[c];if(u&&Array.isArray(u))for(let f of u)a+=z(`${c}${l}`).padEnd(o," ")+n+z(f)+t;else u&&typeof u=="object"?i.push(c):a+=z(c).padEnd(o," ")+n+z(u)+t}e.section&&a.length&&(a="["+z(e.section)+"]"+(e.newline?t+t:t)+a);for(let c of i){let u=qr(c,".").join("\\."),f=(e.section?e.section+".":"")+u,h=rn(s[c],{...e,section:f});a.length&&h.length&&(a+=t),a+=h}return a};function qr(s,e){var t=0,n=0,i=0,r=[];do if(i=s.indexOf(e,t),i!==-1){if(t=i+e.length,i>0&&s[i-1]==="\\")continue;r.push(s.slice(n,i)),n=i+e.length}while(i!==-1);return r.push(s.slice(n)),r}var Lr=(s,e={})=>{e.bracketedArray=e.bracketedArray!==!1;let t=Object.create(null),n=t,i=null,r=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,o=s.split(/[\r\n]+/g),a={};for(let c of o){if(!c||c.match(/^\s*[;#]/)||c.match(/^\s*$/))continue;let u=c.match(r);if(!u)continue;if(u[1]!==void 0){if(i=Mt(u[1]),i==="__proto__"){n=Object.create(null);continue}n=t[i]=t[i]||Object.create(null);continue}let f=Mt(u[2]),h;e.bracketedArray?h=f.length>2&&f.slice(-2)==="[]":(a[f]=(a?.[f]||0)+1,h=a[f]>1);let p=h&&f.endsWith("[]")?f.slice(0,-2):f;if(p==="__proto__")continue;let g=u[3]?Mt(u[4]):!0,d=g==="true"||g==="false"||g==="null"?JSON.parse(g):g;h&&(nn.call(n,p)?Array.isArray(n[p])||(n[p]=[n[p]]):n[p]=[]),Array.isArray(n[p])?n[p].push(d):n[p]=d}let l=[];for(let c of Object.keys(t)){if(!nn.call(t,c)||typeof t[c]!="object"||Array.isArray(t[c]))continue;let u=qr(c,".");n=t;let f=u.pop(),h=f.replace(/\\\./g,".");for(let p of u)p!=="__proto__"&&((!nn.call(n,p)||typeof n[p]!="object")&&(n[p]=Object.create(null)),n=n[p]);n===t&&h===f||(n[h]=t[c],l.push(c))}for(let c of l)delete t[c];return t},Pr=s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"),z=s=>typeof s!="string"||s.match(/[=\r\n]/)||s.match(/^\[/)||s.length>1&&Pr(s)||s!==s.trim()?JSON.stringify(s):s.split(";").join("\\;").split("#").join("\\#"),Mt=s=>{if(s=(s||"").trim(),Pr(s)){s.charAt(0)==="'"&&(s=s.slice(1,-1));try{s=JSON.parse(s)}catch{}}else{let e=!1,t="";for(let n=0,i=s.length;n{"use strict";var un=Symbol.for("yaml.alias"),Ur=Symbol.for("yaml.document"),jt=Symbol.for("yaml.map"),Kr=Symbol.for("yaml.pair"),fn=Symbol.for("yaml.scalar"),Ut=Symbol.for("yaml.seq"),Q=Symbol.for("yaml.node.type"),zc=s=>!!s&&typeof s=="object"&&s[Q]===un,Qc=s=>!!s&&typeof s=="object"&&s[Q]===Ur,Zc=s=>!!s&&typeof s=="object"&&s[Q]===jt,eu=s=>!!s&&typeof s=="object"&&s[Q]===Kr,Yr=s=>!!s&&typeof s=="object"&&s[Q]===fn,tu=s=>!!s&&typeof s=="object"&&s[Q]===Ut;function Dr(s){if(s&&typeof s=="object")switch(s[Q]){case jt:case Ut:return!0}return!1}function su(s){if(s&&typeof s=="object")switch(s[Q]){case un:case jt:case fn:case Ut:return!0}return!1}var nu=s=>(Yr(s)||Dr(s))&&!!s.anchor;x.ALIAS=un;x.DOC=Ur;x.MAP=jt;x.NODE_TYPE=Q;x.PAIR=Kr;x.SCALAR=fn;x.SEQ=Ut;x.hasAnchor=nu;x.isAlias=zc;x.isCollection=Dr;x.isDocument=Qc;x.isMap=Zc;x.isNode=su;x.isPair=eu;x.isScalar=Yr;x.isSeq=tu});var He=w(hn=>{"use strict";var _=C(),V=Symbol("break visit"),Jr=Symbol("skip children"),H=Symbol("remove node");function Kt(s,e){let t=Gr(e);_.isDocument(s)?ke(null,s.contents,t,Object.freeze([s]))===H&&(s.contents=null):ke(null,s,t,Object.freeze([]))}Kt.BREAK=V;Kt.SKIP=Jr;Kt.REMOVE=H;function ke(s,e,t,n){let i=Wr(s,e,t,n);if(_.isNode(i)||_.isPair(i))return Hr(s,n,i),ke(s,i,t,n);if(typeof i!="symbol"){if(_.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r{"use strict";var Xr=C(),iu=He(),ru={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},ou=s=>s.replace(/[!,[\]{}]/g,e=>ru[e]),Xe=class s{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},s.defaultYaml,e),this.tags=Object.assign({},s.defaultTags,t)}clone(){let e=new s(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new s(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:s.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},s.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:s.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},s.defaultTags),this.atNextDocument=!1);let n=e.trim().split(/[ \t]+/),i=n.shift();switch(i){case"%TAG":{if(n.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;let[r,o]=n;return this.tags[r]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,n.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[r]=n;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{let o=/^\d+\.\d+$/.test(r);return t(6,`Unsupported YAML version ${r}`,o),!1}}default:return t(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let o=e.slice(2,-1);return o==="!"||o==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),o)}let[,n,i]=e.match(/^(.*!)([^!]*)$/s);i||t(`The ${e} tag has no suffix`);let r=this.tags[n];if(r)try{return r+decodeURIComponent(i)}catch(o){return t(String(o)),null}return n==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+ou(e.substring(n.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags),i;if(e&&n.length>0&&Xr.isNode(e.contents)){let r={};iu.visit(e.contents,(o,a)=>{Xr.isNode(a)&&a.tag&&(r[a.tag]=!0)}),i=Object.keys(r)}else i=[];for(let[r,o]of n)r==="!!"&&o==="tag:yaml.org,2002:"||(!e||i.some(a=>a.startsWith(o)))&&t.push(`%TAG ${r} ${o}`);return t.join(` `)}};Xe.defaultYaml={explicit:!1,version:"1.2"};Xe.defaultTags={"!!":"tag:yaml.org,2002:"};zr.Directives=Xe});var Dt=w(ze=>{"use strict";var Qr=C(),au=He();function lu(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function Zr(s){let e=new Set;return au.visit(s,{Value(t,n){n.anchor&&e.add(n.anchor)}}),e}function eo(s,e){for(let t=1;;++t){let n=`${s}${t}`;if(!e.has(n))return n}}function cu(s,e){let t=[],n=new Map,i=null;return{onAnchor:r=>{t.push(r),i??(i=Zr(s));let o=eo(e,i);return i.add(o),o},setAnchors:()=>{for(let r of t){let o=n.get(r);if(typeof o=="object"&&o.anchor&&(Qr.isScalar(o.node)||Qr.isCollection(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=r,a}}},sourceObjects:n}}ze.anchorIsValid=lu;ze.anchorNames=Zr;ze.createNodeAnchors=cu;ze.findNewAnchor=eo});var pn=w(to=>{"use strict";function Qe(s,e,t,n){if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0,r=n.length;i{"use strict";var uu=C();function so(s,e,t){if(Array.isArray(s))return s.map((n,i)=>so(n,String(i),t));if(s&&typeof s.toJSON=="function"){if(!t||!uu.hasAnchor(s))return s.toJSON(e,t);let n={aliasCount:0,count:1,res:void 0};t.anchors.set(s,n),t.onCreate=r=>{n.res=r,delete t.onCreate};let i=s.toJSON(e,t);return t.onCreate&&t.onCreate(i),i}return typeof s=="bigint"&&!t?.keep?Number(s):s}no.toJS=so});var Jt=w(ro=>{"use strict";var fu=pn(),io=C(),hu=se(),mn=class{constructor(e){Object.defineProperty(this,io.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:i,reviver:r}={}){if(!io.isDocument(e))throw new TypeError("A document argument is required");let o={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n=="number"?n:100},a=hu.toJS(this,"",o);if(typeof i=="function")for(let{count:l,res:c}of o.anchors.values())i(c,l);return typeof r=="function"?fu.applyReviver(r,{"":a},"",a):a}};ro.NodeBase=mn});var Ze=w(oo=>{"use strict";var du=Dt(),pu=He(),Le=C(),mu=Jt(),gu=se(),gn=class extends mu.NodeBase{constructor(e){super(Le.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],pu.visit(e,{Node:(r,o)=>{(Le.isAlias(o)||Le.hasAnchor(o))&&n.push(o)}}),t&&(t.aliasResolveCache=n));let i;for(let r of n){if(r===this)break;r.anchor===this.source&&(i=r)}return i}toJSON(e,t){if(!t)return{source:this.source};let{anchors:n,doc:i,maxAliasCount:r}=t,o=this.resolve(i,t);if(!o){let l=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(l)}let a=n.get(o);if(a||(gu.toJS(o,null,t),a=n.get(o)),a?.res===void 0){let l="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(l)}if(r>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=Gt(i,o,n)),a.count*a.aliasCount>r)){let l="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(l)}return a.res}toString(e,t,n){let i=`*${this.source}`;if(e){if(du.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${i} `}return i}};function Gt(s,e,t){if(Le.isAlias(e)){let n=e.resolve(s),i=t&&n&&t.get(n);return i?i.count*i.aliasCount:0}else if(Le.isCollection(e)){let n=0;for(let i of e.items){let r=Gt(s,i,t);r>n&&(n=r)}return n}else if(Le.isPair(e)){let n=Gt(s,e.key,t),i=Gt(s,e.value,t);return Math.max(n,i)}return 1}oo.Alias=gn});var L=w(yn=>{"use strict";var yu=C(),bu=Jt(),wu=se(),Su=s=>!s||typeof s!="function"&&typeof s!="object",ne=class extends bu.NodeBase{constructor(e){super(yu.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:wu.toJS(this.value,e,t)}toString(){return String(this.value)}};ne.BLOCK_FOLDED="BLOCK_FOLDED";ne.BLOCK_LITERAL="BLOCK_LITERAL";ne.PLAIN="PLAIN";ne.QUOTE_DOUBLE="QUOTE_DOUBLE";ne.QUOTE_SINGLE="QUOTE_SINGLE";yn.Scalar=ne;yn.isScalarValue=Su});var et=w(lo=>{"use strict";var Nu=Ze(),me=C(),ao=L(),Au="tag:yaml.org,2002:";function Eu(s,e,t){if(e){let n=t.filter(r=>r.tag===e),i=n.find(r=>!r.format)??n[0];if(!i)throw new Error(`Tag ${e} not found`);return i}return t.find(n=>n.identify?.(s)&&!n.format)}function vu(s,e,t){if(me.isDocument(s)&&(s=s.contents),me.isNode(s))return s;if(me.isPair(s)){let f=t.schema[me.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:n,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=t,l;if(n&&s&&typeof s=="object"){if(l=a.get(s),l)return l.anchor??(l.anchor=i(s)),new Nu.Alias(l.anchor);l={anchor:null,node:null},a.set(s,l)}e?.startsWith("!!")&&(e=Au+e.slice(2));let c=Eu(s,e,o.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new ao.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?o[me.MAP]:Symbol.iterator in Object(s)?o[me.SEQ]:o[me.MAP]}r&&(r(c),delete t.onTagObj);let u=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new ao.Scalar(s);return e?u.tag=e:c.default||(u.tag=c.tag),l&&(l.node=u),u}lo.createNode=vu});var Ht=w(Wt=>{"use strict";var Tu=et(),X=C(),Cu=Jt();function bn(s,e,t){let n=t;for(let i=e.length-1;i>=0;--i){let r=e[i];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let o=[];o[r]=n,n=o}else n=new Map([[r,n]])}return Tu.createNode(n,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var co=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,wn=class extends Cu.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(n=>X.isNode(n)||X.isPair(n)?n.clone(e):n),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(co(e))this.add(t);else{let[n,...i]=e,r=this.get(n,!0);if(X.isCollection(r))r.addIn(i,t);else if(r===void 0&&this.schema)this.set(n,bn(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let i=this.get(t,!0);if(X.isCollection(i))return i.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...i]=e,r=this.get(n,!0);return i.length===0?!t&&X.isScalar(r)?r.value:r:X.isCollection(r)?r.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!X.isPair(t))return!1;let n=t.value;return n==null||e&&X.isScalar(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let i=this.get(t,!0);return X.isCollection(i)?i.hasIn(n):!1}setIn(e,t){let[n,...i]=e;if(i.length===0)this.set(n,t);else{let r=this.get(n,!0);if(X.isCollection(r))r.setIn(i,t);else if(r===void 0&&this.schema)this.set(n,bn(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}};Wt.Collection=wn;Wt.collectionFromPath=bn;Wt.isEmptyPath=co});var tt=w(Xt=>{"use strict";var Ou=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function Sn(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var ku=(s,e,t)=>s.endsWith(` diff --git a/packages/just-bash/dist/bin/chunks/chunk-ISLENKSH.js b/packages/just-bash/dist/bin/chunks/chunk-ISLENKSH.js new file mode 100644 index 00000000..a4d2ca4d --- /dev/null +++ b/packages/just-bash/dist/bin/chunks/chunk-ISLENKSH.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node +import{createRequire} from"node:module";const require=createRequire(import.meta.url); +import{a as g,b as A,c as T,d as at,e as E,g as O,h as G}from"./chunk-MLUOPG3W.js";import{a as X,c as lt}from"./chunk-MROECM42.js";import{a as yt}from"./chunk-AZH64XMJ.js";import{a as R}from"./chunk-52FZYTIX.js";import{k as B}from"./chunk-47WZ2U6M.js";function W(t,r,e,n,c,o,u,p,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,a)=>{let y=c(h,e[0],n)[0],l=c(a,e[0],n)[0];return u(y,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:c(t,e[0],n).map(h=>{let a=0,y=t.length;for(;a>>1;u(t[l],h)<0?a=l+1:y=l}return au(a.key,y.key)),[h.map(a=>a.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let h of t){let a=JSON.stringify(c(h,e[0],n)[0]);i.has(a)||i.set(a,[]),i.get(a)?.push(h)}return[[...i.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)>0?i:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=c(i,e[0],n)[0],y=c(h,e[0],n)[0];return u(a,y)>0?i:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)<0?i:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=c(i,e[0],n)[0],y=c(h,e[0],n)[0];return u(a,y)<0?i:h})];case"add":{let i=h=>{let a=h.filter(y=>y!==null);return a.length===0?null:a.every(y=>typeof y=="number")?a.reduce((y,l)=>y+l,0):a.every(y=>typeof y=="string")?a.join(""):a.every(y=>Array.isArray(y))?a.flat():a.every(y=>y&&typeof y=="object"&&!Array.isArray(y))?lt(...a):null};if(e.length>=1){let h=c(t,e[0],n);return[i(h)]}return Array.isArray(t)?[i(t)]:[null]}case"any":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(c(h,e[1],n).some(p))return[!0]}catch(i){if(i instanceof f)throw i}return[!1]}return e.length===1?Array.isArray(t)?[t.some(i=>p(c(i,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(p)]:[!1]}case"all":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(!c(h,e[1],n).some(p))return[!1]}catch(i){if(i instanceof f)throw i}return[!0]}return e.length===1?Array.isArray(t)?[t.every(i=>p(c(i,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(p)]:[!0]}case"select":return e.length===0?[t]:c(t,e[0],n).some(p)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>c(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(i=>c(i,e[0],n))];if(t&&typeof t=="object"){let i=Object.create(null);for(let[h,a]of Object.entries(t)){if(!g(h))continue;let y=c(a,e[0],n);y.length>0&&A(i,h,y[0])}return[i]}return[null]}case"has":{if(e.length===0)return[!1];let h=c(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h=0&&t0)try{let s=o(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof p)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=c(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=c(t,e[0],n);if(e.length>1){for(let i of s)if(i<0)throw new Error("nth doesn't support negative indices");let f;try{f=o(t,e[1],n)}catch(i){if(i instanceof p)throw i;f=[]}return s.flatMap(i=>{let h=i;return h{let i=f;if(i<0)throw new Error("nth doesn't support negative indices");return il.length>=s,i=c(t,e[0],n);if(e.length===1){let l=[];for(let m of i){let b=m;for(let w=0;w0){for(let C=w;Ck;C+=N)if(y.push(C),f(y))return y}}return y}case"limit":return e.length<2?[]:c(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("limit doesn't support negative count");if(i===0)return[];let h;try{h=o(t,e[1],n)}catch(a){if(a instanceof p)throw a;h=[]}return h.slice(0,i)});case"isempty":{if(e.length<1)return[!0];try{return[o(t,e[0],n).length===0]}catch(s){if(s instanceof p)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[c(t,e[0],n).length>0]}catch(s){if(s instanceof p)throw s;return[!1]}}case"skip":return e.length<2?[]:c(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("skip doesn't support negative count");return c(t,e[1],n).slice(i)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let i=0;i=i)throw new p(`jq while: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,i=n.limits.maxIterations;for(let h=0;h=i)throw new p(`jq repeat: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function Z(t,r,e,n,c){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let o=new Date(t*1e3),u=o.getUTCFullYear(),p=o.getUTCMonth(),s=o.getUTCDate(),f=o.getUTCHours(),i=o.getUTCMinutes(),h=o.getUTCSeconds(),a=o.getUTCDay(),y=Date.UTC(u,0,1),l=Math.floor((o.getTime()-y)/(1440*60*1e3));return[[u,p,s,f,i,h,a,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[o,u,p,s=0,f=0,i=0]=t;if(typeof o!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(o,u,p??1,s??0,f??0,i??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=c(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let p;if(typeof t=="number")p=new Date(t*1e3);else if(Array.isArray(t)){let[a,y,l,m=0,b=0,w=0]=t;if(typeof a!="number"||typeof y!="number")throw new Error("strftime/1 requires parsed datetime inputs");p=new Date(Date.UTC(a,y,l??1,m??0,b??0,w??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],i=(a,y=2)=>String(a).padStart(y,"0");return[u.replace(/%Y/g,String(p.getUTCFullYear())).replace(/%m/g,i(p.getUTCMonth()+1)).replace(/%d/g,i(p.getUTCDate())).replace(/%H/g,i(p.getUTCHours())).replace(/%M/g,i(p.getUTCMinutes())).replace(/%S/g,i(p.getUTCSeconds())).replace(/%A/g,s[p.getUTCDay()]).replace(/%B/g,f[p.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=c(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,i,h,a,y,l]=s.map(Number),m=new Date(Date.UTC(f,i-1,h,a,y,l)),b=m.getUTCDay(),w=Date.UTC(f,0,1),k=Math.floor((m.getTime()-w)/(1440*60*1e3));return[[f,i-1,h,a,y,l,b,k]]}}let p=new Date(t);if(!Number.isNaN(p.getTime())){let s=p.getUTCFullYear(),f=p.getUTCMonth(),i=p.getUTCDate(),h=p.getUTCHours(),a=p.getUTCMinutes(),y=p.getUTCSeconds(),l=p.getUTCDay(),m=Date.UTC(s,0,1),b=Math.floor((p.getTime()-m)/(1440*60*1e3));return[[s,f,i,h,a,y,l,b]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let o=new Date(t);if(Number.isNaN(o.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(o.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function S(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function U(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function v(t,r){let e=O(t);for(let n of Object.keys(r)){if(!g(n))continue;let c=T(e,n)?E(e[n]):null,o=E(r[n]);c&&o?A(e,n,v(c,o)):A(e,n,r[n])}return e}function D(t,r=3e3){let e=0,n=t;for(;ep===null?0:typeof p=="boolean"?1:typeof p=="number"?2:typeof p=="string"?3:Array.isArray(p)?4:typeof p=="object"?5:6,n=e(t),c=e(r);if(n!==c)return n-c;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let p=0;pt.some(o=>F(o,c)));let e=E(t),n=E(r);return e&&n?Object.keys(n).every(c=>T(e,c)&&F(e[c],n[c])):!1}var Ot=2e3;function tt(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(c=>{if(c===null)return"";if(typeof c=="boolean")return c?"true":"false";if(typeof c=="number")return String(c);let o=String(c);return o.includes(",")||o.includes('"')||o.includes(` +`)||o.includes("\r")?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??Ot;return D(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function et(t,r,e,n,c,o){switch(r){case"index":return e.length===0?[null]:c(t,e[0],n).map(p=>{if(typeof t=="string"&&typeof p=="string"){if(p===""&&t==="")return null;let s=t.indexOf(p);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(p)){for(let f=0;f<=t.length-p.length;f++){let i=!0;for(let h=0;ho(f,p));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:c(t,e[0],n).map(p=>{if(typeof t=="string"&&typeof p=="string"){let s=t.lastIndexOf(p);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(p)){for(let s=t.length-p.length;s>=0;s--){let f=!0;for(let i=0;i=0;s--)if(o(t[s],p))return s;return null}return null});case"indices":return e.length===0?[[]]:c(t,e[0],n).map(p=>{let s=[];if(typeof t=="string"&&typeof p=="string"){let f=t.indexOf(p);for(;f!==-1;)s.push(f),f=t.indexOf(p,f+1)}else if(Array.isArray(t))if(Array.isArray(p)){let f=p.length;if(f===0)for(let i=0;i<=t.length;i++)s.push(i);else for(let i=0;i<=t.length-f;i++){let h=!0;for(let a=0;a{if(y.push(m),Array.isArray(m))for(let b of m)l(b);else if(m&&typeof m=="object")for(let b of Object.keys(m))l(m[b])};return l(t),y}let s=[],f=e.length>=2?e[1]:null,i=1e4,h=0,a=y=>{if(h++>i||f&&!c(y,f,n).some(o))return;s.push(y);let l=c(y,e[0],n);for(let m of l)m!=null&&a(m)};return a(t),s}case"recurse_down":return p(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=i=>{if(i&&typeof i=="object"){if(s.has(i))return i;s.add(i)}let h;if(Array.isArray(i))h=i.map(f);else if(i&&typeof i=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(i))g(l)&&A(y,l,f(m));h=y}else h=i;return c(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(i=>Array.isArray(i)?i.length:0)),f=[];for(let i=0;iArray.isArray(h)?h[i]:null));return[f]}case"combinations":{if(e.length>0){let h=c(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let a=[],y=(l,m)=>{if(m===h){a.push([...l]);return}for(let b of t)l.push(b),y(l,m+1),l.pop()};return y([],0),a}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let i of t)if(!Array.isArray(i))return[];let s=[],f=(i,h)=>{if(i===t.length){s.push([...h]);return}let a=t[i];for(let y of a)h.push(y),f(i+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?c(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let i=s.slice(0,s.length-f);return[u(n.root,i)]}else{let i=-f-1;if(i>=s.length)return[t];let h=s.slice(0,i);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let i=s.length-1;i>=0;i--)f.push(u(n.root,s.slice(0,i)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var Nt=2e3;function st(t,r,e,n,c){switch(r){case"keys":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) only strings have UTF-8 byte length`)}case"to_entries":{let o=E(t);return o?[Object.entries(o).map(([u,p])=>({key:u,value:p}))]:[null]}case"from_entries":if(Array.isArray(t)){let o=Object.create(null);for(let u of t){let p=E(u);if(p){let s=p.key??p.Key??p.name??p.Name??p.k,f=p.value??p.Value??p.v;if(s!==void 0){let i=String(s);g(i)&&A(o,i,f)}}}return[o]}return[null];case"with_entries":{if(e.length===0)return[t];let o=E(t);if(o){let p=Object.entries(o).map(([f,i])=>({key:f,value:i})).flatMap(f=>c(f,e[0],n)),s=Object.create(null);for(let f of p){let i=E(f);if(i){let h=i.key??i.name??i.k,a=i.value??i.v;if(h!==void 0){let y=String(h);g(y)&&A(s,y,a)}}}return[s]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?c(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let p=u;if(p<0)throw new Error("flatten depth must not be negative");return t.flat(p)}):[null];case"unique":if(Array.isArray(t)){let o=new Set,u=[];for(let p of t){let s=JSON.stringify(p);o.has(s)||(o.add(s),u.push(p))}return[u]}return[null];case"tojson":case"tojsonstream":{let o=n.limits.maxDepth??Nt;return D(t,o+1)>o?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let o=t.trim().toLowerCase();if(o==="nan")return[Number.NaN];if(o==="inf"||o==="infinity")return[Number.POSITIVE_INFINITY];if(o==="-inf"||o==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[at(JSON.parse(t))]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let o=Number(t);if(Number.isNaN(o))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[o]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) cannot be parsed as a boolean`)}case"tostream":{let o=[],u=(p,s)=>{if(p===null||typeof p!="object")o.push([s,p]);else if(Array.isArray(p))if(p.length===0)o.push([s,[]]);else for(let f=0;fo&&u.push([f.slice(o)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],i=s[1];f.length>o&&u.push([f.slice(o),i])}}return u}default:return null}}function it(t,r,e,n,c,o,u,p,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let i=c(t,e[0],n),h=[];for(let a of i){let y=a,l=t;for(let m of y){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof m=="string"){let b=E(l);if(!b||!Object.hasOwn(b,m)){l=null;break}l=b[m]}else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=c(t,e[0],n)[0],y=c(t,e[1],n)[0];return[u(t,h,y)]}case"delpaths":{if(e.length===0)return[t];let h=c(t,e[0],n)[0],a=t;for(let y of h.sort((l,m)=>m.length-l.length))a=p(a,y);return[a]}case"path":{if(e.length===0)return[[]];let i=[];return f(t,e[0],n,[],i),i}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let i=[];for(let a of e)f(t,a,n,[],i);let h=null;for(let a of i){for(let l of a)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let y=t;for(let l of a){if(y==null)break;if(Array.isArray(y)&&typeof l=="number")y=y[l];else if(typeof l=="string"){let m=E(y);if(!m||!Object.hasOwn(m,l)){y=null;break}y=m[l]}else{y=null;break}}h=u(h,a,y)}return[h]}case"paths":{let i=[],h=(a,y)=>{if(a&&typeof a=="object")if(Array.isArray(a))for(let l=0;l0?i.filter(a=>{let y=t;for(let m of a)if(Array.isArray(y)&&typeof m=="number")y=y[m];else if(typeof m=="string"){let b=E(y);if(!b||!Object.hasOwn(b,m))return!1;y=b[m]}else return!1;return c(y,e[0],n).some(o)}):i}case"leaf_paths":{let i=[],h=(a,y)=>{if(a===null||typeof a!="object")i.push(y);else if(Array.isArray(a))for(let l=0;lJSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[Object.create(null)];if(e.length===1){let s=c(t,e[0],n),f=Object.create(null);for(let i of s){let h=String(i);g(h)&&A(f,h,i)}return[f]}if(e.length===2){let s=c(t,e[0],n),f=Object.create(null);for(let i of s){let h=c(i,e[1],n);if(h.length>0){let a=String(h[0]);g(a)&&A(f,a,i)}}return[f]}let u=c(t,e[0],n),p=Object.create(null);for(let s of u){let f=c(s,e[1],n),i=c(s,e[2],n);if(f.length>0&&i.length>0){let h=String(f[0]);g(h)&&A(p,h,i[0])}}return[p]}case"JOIN":{if(e.length<2)return[null];let u=E(c(t,e[0],n)[0]);if(!u)return[null];if(!Array.isArray(t))return[null];let p=[];for(let s of t){let f=c(s,e[1],n),i=f.length>0?String(f[0]):"",h=T(u,i)?u[i]:null;p.push([s,h])}return[p]}default:return null}}function ft(t,r,e,n,c){switch(r){case"join":{if(!Array.isArray(t))return[null];let o=e.length>0?c(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return o.map(u=>t.map(p=>p===null?"":typeof p=="string"?p:String(p)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"g";return R(u,p.includes("g")?p:`${p}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"";return[...R(u,p.includes("g")?p:`${p}g`).matchAll(t)].map(i=>i.length>1?i.slice(1):i[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"";return[R(u,p).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"",f=R(u,`${p}d`).exec(t);if(!f)return[];let i=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,a)=>({offset:i?.[a+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"",f=R(u,p).match(t);return!f||!f.groups?[Object.create(null)]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let o=c(t,e[0],n),u=c(t,e[1],n),p=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(c(t,e[2],n)[0]):"";return[R(p,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let o=c(t,e[0],n),u=c(t,e[1],n),p=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(c(t,e[2],n)[0]):"g",i=f.includes("g")?f:`${f}g`;return[R(p,i).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,o=>String.fromCharCode(o.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,o=>String.fromCharCode(o.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);if(u==="")return[t];let p=t;return p.startsWith(u)&&(p=p.slice(u.length)),p.endsWith(u)&&(p=p.slice(0,-u.length)),[p]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n);return[t.startsWith(String(o[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n);return[t.endsWith(String(o[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(o=>o.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(p=>{if(typeof p=="string")throw new Error(`string (${JSON.stringify(p)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof p!="number"||Number.isNaN(p))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(p);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function ct(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function K(t,r,e){if(r.length===0)return e;let[n,...c]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let f=Array.isArray(t)?[...t]:[];for(;f.length<=n;)f.push(null);return f[n]=K(f[n],c,e),f}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!g(n))return t??Object.create(null);let o=E(t),u=o?O(o):Object.create(null),p=Object.hasOwn(u,n)?u[n]:void 0;return A(u,n,K(p,c,e)),u}function V(t,r){if(r.length===0)return null;if(r.length===1){let c=r[0];if(Array.isArray(t)&&typeof c=="number"){let o=[...t];return o.splice(c,1),o}if(t&&typeof t=="object"&&!Array.isArray(t)){let o=String(c);if(!g(o))return t;let u=O(t);return delete u[o],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let c=[...t];return c[e]=V(c[e],n),c}if(t&&typeof t=="object"&&!Array.isArray(t)){let c=String(e);if(!g(c))return t;let o=O(t);return Object.hasOwn(o,c)&&A(o,c,V(o[c],n)),o}return t}var P=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},H=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},St=1e4,bt=2e3,Ct=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function Tt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??St,maxDepth:t?.limits?.maxDepth??bt},env:t?.env,coverage:t?.coverage,requireDefenseContext:t?.requireDefenseContext,defenseContextChecked:!1}}function q(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,requireDefenseContext:t.requireDefenseContext,defenseContextChecked:t.defenseContextChecked,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels,coverage:t.coverage}}function L(t,r,e){switch(r.type){case"var":return q(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let c=0;c0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=pt(t,r.left);return e===null?null:pt(e,r.right)}return r.type==="Identity"?t:null}function mt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(c){if(c instanceof B)throw c;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(c){if(c instanceof B)throw c;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Tt(e);switch(n.defenseContextChecked||(yt(n.requireDefenseContext,"query-engine","evaluation"),n={...n,defenseContextChecked:!0}),n.root===void 0&&(n={...n,root:t,currentPath:[]}),n.coverage?.hit(`jq:node:${r.type}`),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(o=>{let u=E(o);if(u){if(!Object.hasOwn(u,r.name))return[null];let s=u[r.name];return[s===void 0?null:s]}if(o===null)return[null];let p=Array.isArray(o)?"array":typeof o;throw new Error(`Cannot index ${p} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(o=>d(o,r.index,n).flatMap(p=>{if(typeof p=="number"&&Array.isArray(o)){if(Number.isNaN(p))return[null];let s=Math.trunc(p),f=s<0?o.length+s:s;return f>=0&&f{if(o===null)return[null];if(!Array.isArray(o)&&typeof o!="string")throw new Error(`Cannot slice ${typeof o} (${JSON.stringify(o)})`);let u=o.length,p=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return p.flatMap(f=>s.map(i=>{let h=f,a=i,y=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(a)?u:Number.isInteger(a)?a:Math.ceil(a),m=dt(y,u),b=dt(l,u);return Array.isArray(o),o.slice(m,b)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(o=>Array.isArray(o)?o:o&&typeof o=="object"?Object.values(o):[]);case"Pipe":{let c=d(t,r.left,n),o=M(r.left),u=[];for(let p of c)try{if(o!==null){let s={...n,currentPath:[...n.currentPath??[],...o]};u.push(...d(p,r.right,s))}else u.push(...d(p,r.right,n))}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Comma":{let c=d(t,r.left,n),o=d(t,r.right,n);return[...c,...o]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let c=[Object.create(null)];for(let o of r.entries){let u=typeof o.key=="string"?[o.key]:d(t,o.key,n),p=d(t,o.value,n),s=[];for(let f of c)for(let i of u){if(typeof i!="string"){let h=i===null?"null":Array.isArray(i)?"array":typeof i;throw new Error(`Cannot use ${h} (${JSON.stringify(i)}) as object key`)}if(!g(i)){for(let h of p)s.push(O(f));continue}for(let h of p){let a=O(f);A(a,i,h),s.push(a)}}c.length=0,c.push(...s)}return c}case"Paren":return d(t,r.expr,n);case"BinaryOp":return xt(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(o=>{if(r.op==="-"){if(typeof o=="number")return-o;if(typeof o=="string"){let u=p=>p.length>5?`"${p.slice(0,3)}...`:JSON.stringify(p);throw new Error(`string (${u(o)}) cannot be negated`)}return null}return r.op==="not"?!S(o):null});case"Cond":return d(t,r.cond,n).flatMap(o=>{if(S(o))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(S))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(c){if(r.catch){let o=c instanceof H?c.value:c instanceof Error?c.message:String(c);return d(o,r.catch,n)}return[]}case"Call":return gt(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(o=>{let u=null,p=[];r.pattern?p.push(r.pattern):r.name&&p.push({type:"var",name:r.name}),r.alternatives&&p.push(...r.alternatives);for(let s of p)if(u=L(n,s,o),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?X(n.env):Object.create(null)];let c=n.vars.get(r.name);return c!==void 0?[c]:[null]}case"Recurse":{let c=[],o=new WeakSet,u=p=>{if(p&&typeof p=="object"){if(o.has(p))return;o.add(p)}if(c.push(p),Array.isArray(p))for(let s of p)u(s);else if(p&&typeof p=="object")for(let s of Object.keys(p))u(p[s])};return u(t),c}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(o=>typeof o=="string"?o:d(t,o,n).map(p=>typeof p=="string"?p:JSON.stringify(p)).join("")).join("")];case"UpdateOp":return[Mt(t,r.path,r.op,r.value,n)];case"Reduce":{let c=d(t,r.expr,n),o=d(t,r.init,n)[0],u=n.limits.maxDepth??bt;for(let p of c){let s;if(r.pattern){if(s=L(n,r.pattern,p),s===null)continue}else s=q(n,r.varName,p);if(o=d(o,r.update,s)[0],D(o,u+1)>u)return[null]}return[o]}case"Foreach":{let c=d(t,r.expr,n),o=d(t,r.init,n)[0],u=[];for(let p of c)try{let s;if(r.pattern){if(s=L(n,r.pattern,p),s===null)continue}else s=q(n,r.varName,p);if(o=d(o,r.update,s)[0],r.extract){let f=d(o,r.extract,s);u.push(...f)}else u.push(o)}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(c){if(c instanceof P&&c.label===r.name)return c.partialResults;throw c}case"Break":throw new P(r.name);case"Def":{let c=new Map(n.funcs??[]),o=`${r.name}/${r.params.length}`;c.set(o,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:c};return d(t,r.body,u)}default:{let c=r;throw new Error(`Unknown AST node type: ${c.type}`)}}}function dt(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Mt(t,r,e,n,c){function o(s,f){switch(e){case"=":return f;case"|=":return d(s,n,c)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?G(s,f):f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,i){switch(f.type){case"Identity":return i(s);case"Field":{if(!g(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a=O(h),y=Object.hasOwn(a,f.name)?a[f.name]:void 0;return A(a,f.name,i(y)),a}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h=O(s),a=Object.hasOwn(h,f.name)?h[f.name]:void 0;return A(h,f.name,i(a)),h}return s}case"Index":{let a=d(t,f.index,c)[0];if(typeof a=="number"&&Number.isNaN(a))throw new Error("Cannot set array element at NaN index");if(typeof a=="number"&&!Number.isInteger(a)&&(a=Math.trunc(a)),f.base)return u(s,f.base,y=>{if(typeof a=="number"&&Array.isArray(y)){let l=[...y],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(typeof a=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(a))return y;let l=O(y),m=Object.hasOwn(l,a)?l[a]:void 0;return A(l,a,i(m)),l}return y});if(typeof a=="number"){if(a>536870911)throw new Error("Array index too large");if(a<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(s==null){let l=[];for(;l.length<=a;)l.push(null);return l[a]=i(null),l}return s}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!g(a))return s;let y=O(s),l=Object.hasOwn(y,a)?y[a]:void 0;return A(y,a,i(l)),y}return s}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(y=>i(y));if(a&&typeof a=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(a))g(l)&&A(y,l,i(m));return y}return a};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,a=>a);return u(h,f.right,i)}default:return i(s)}}return u(t,r,s=>{if(e==="|=")return o(s,s);let f=d(t,n,c);return o(s,f[0]??null)})}function jt(t,r,e){function n(o,u,p){switch(u.type){case"Identity":return p;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0],f=n(s,{type:"Field",name:u.name},p);return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){let s=O(o);return A(s,u.name,p),s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0],h=n(i,{type:"Index",index:u.index},p);return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h=0&&h=0&&NS(s)?d(t,n,c).map(i=>S(i)):[!1]);if(r==="or")return d(t,e,c).flatMap(s=>S(s)?[!0]:d(t,n,c).map(i=>S(i)));if(r==="//"){let s=d(t,e,c).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,c)}let o=d(t,e,c),u=d(t,n,c);return o.flatMap(p=>u.map(s=>{switch(r){case"+":return p===null?s:s===null?p:typeof p=="number"&&typeof s=="number"||typeof p=="string"&&typeof s=="string"?p+s:Array.isArray(p)&&Array.isArray(s)?[...p,...s]:p&&s&&typeof p=="object"&&typeof s=="object"&&!Array.isArray(p)&&!Array.isArray(s)?G(p,s):null;case"-":if(typeof p=="number"&&typeof s=="number")return p-s;if(Array.isArray(p)&&Array.isArray(s)){let f=new Set(s.map(i=>JSON.stringify(i)));return p.filter(i=>!f.has(JSON.stringify(i)))}if(typeof p=="string"&&typeof s=="string"){let f=i=>i.length>10?`"${i.slice(0,10)}...`:JSON.stringify(i);throw new Error(`string (${f(p)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":if(typeof p=="number"&&typeof s=="number")return p*s;if(typeof p=="string"&&typeof s=="number")return p.repeat(s);{let f=E(p),i=E(s);if(f&&i)return v(f,i)}return null;case"/":if(typeof p=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${p}) and number (${s}) cannot be divided because the divisor is zero`);return p/s}return typeof p=="string"&&typeof s=="string"?p.split(s):null;case"%":if(typeof p=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${p}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(p)&&!Number.isNaN(p)?!Number.isFinite(s)&&!Number.isNaN(s)&&p<0&&s>0?-1:0:p%s}return null;case"==":return I(p,s);case"!=":return!I(p,s);case"<":return U(p,s)<0;case"<=":return U(p,s)<=0;case">":return U(p,s)>0;case">=":return U(p,s)>=0;default:return null}}))}function gt(t,r,e,n){let c=Ct.get(r);if(c)return typeof t=="number"?[c(t)]:[null];let o=rt(t,r,e,n,d);if(o!==null)return o;let u=ft(t,r,e,n,d);if(u!==null)return u;let p=Z(t,r,e,n,d);if(p!==null)return p;let s=tt(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ct(t,r);if(f!==null)return f;let i=st(t,r,e,n,d);if(i!==null)return i;let h=W(t,r,e,n,d,mt,$,S,F,B);if(h!==null)return h;let a=it(t,r,e,n,d,S,K,V,jt,J);if(a!==null)return a;let y=et(t,r,e,n,d,I);if(y!==null)return y;let l=z(t,r,e,n,d,mt,S,B);if(l!==null)return l;let m=nt(t,r,e,n,d,S,Rt,gt);if(m!==null)return m;let b=ot(t,r,e,n,d,I);if(b!==null)return b;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let w=e.length>0?d(t,e[0],n)[0]:t;throw new H(w)}case"env":return[n.env?X(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let w=`${r}/${e.length}`,k=n.funcs?.get(w);if(k){let N=k.closure??n.funcs??new Map,C=new Map(N);C.set(w,k);for(let _=0;_=0;Q--)x={type:"Comma",left:{type:"Literal",value:j[Q]},right:x}}C.set(`${kt}/0`,{params:[],body:x})}}let wt={...n,funcs:C};return d(t,k.body,wt)}throw new Error(`Unknown function: ${r}`)}}}function J(t,r,e,n,c){if(r.type==="Comma"){let p=r;J(t,p.left,e,n,c),J(t,p.right,e,n,c);return}let o=M(r);if(o!==null){c.push([...n,...o]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let p=0;p{if(c.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let i=0;i0&&c.push(n)}var At=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]),Y=new Set(At.values());function Et(t){let r=[],e=0,n=(f=0)=>t[e+f],c=()=>t[e++],o=()=>e>=t.length,u=f=>f>="0"&&f<="9",p=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>p(f)||u(f);for(;!o();){let f=e,i=c();if(!(i===" "||i===" "||i===` +`||i==="\r")){if(i==="#"){for(;!o()&&n()!==` +`;)c();continue}if(i==="."&&n()==="."){c(),r.push({type:"DOTDOT",pos:f});continue}if(i==="="&&n()==="="){c(),r.push({type:"EQ",pos:f});continue}if(i==="!"&&n()==="="){c(),r.push({type:"NE",pos:f});continue}if(i==="<"&&n()==="="){c(),r.push({type:"LE",pos:f});continue}if(i===">"&&n()==="="){c(),r.push({type:"GE",pos:f});continue}if(i==="/"&&n()==="/"){c(),n()==="="?(c(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(i==="+"&&n()==="="){c(),r.push({type:"UPDATE_ADD",pos:f});continue}if(i==="-"&&n()==="="){c(),r.push({type:"UPDATE_SUB",pos:f});continue}if(i==="*"&&n()==="="){c(),r.push({type:"UPDATE_MUL",pos:f});continue}if(i==="/"&&n()==="="){c(),r.push({type:"UPDATE_DIV",pos:f});continue}if(i==="%"&&n()==="="){c(),r.push({type:"UPDATE_MOD",pos:f});continue}if(i==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(i==="."){r.push({type:"DOT",pos:f});continue}if(i==="|"){n()==="="?(c(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(i===","){r.push({type:"COMMA",pos:f});continue}if(i===":"){r.push({type:"COLON",pos:f});continue}if(i===";"){r.push({type:"SEMICOLON",pos:f});continue}if(i==="("){r.push({type:"LPAREN",pos:f});continue}if(i===")"){r.push({type:"RPAREN",pos:f});continue}if(i==="["){r.push({type:"LBRACKET",pos:f});continue}if(i==="]"){r.push({type:"RBRACKET",pos:f});continue}if(i==="{"){r.push({type:"LBRACE",pos:f});continue}if(i==="}"){r.push({type:"RBRACE",pos:f});continue}if(i==="?"){r.push({type:"QUESTION",pos:f});continue}if(i==="+"){r.push({type:"PLUS",pos:f});continue}if(i==="-"){r.push({type:"MINUS",pos:f});continue}if(i==="*"){r.push({type:"STAR",pos:f});continue}if(i==="/"){r.push({type:"SLASH",pos:f});continue}if(i==="%"){r.push({type:"PERCENT",pos:f});continue}if(i==="<"){r.push({type:"LT",pos:f});continue}if(i===">"){r.push({type:"GT",pos:f});continue}if(u(i)){let h=i;for(;!o()&&(u(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[e+1]==="+"||t[e+1]==="-")&&(h+=c()),h+=c();r.push({type:"NUMBER",value:Number(h),pos:f});continue}if(i==='"'){let h="",a=0;for(;!o();){let y=n();if(a===0&&y==='"')break;if(a===0&&y==="\\"){if(c(),o())break;let l=c();switch(l){case"n":h+=` +`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(",a=1;break;default:h+=l}continue}if(a>0){if(y==='"'){for(h+=c();!o();){let l=n();if(l==="\\"){h+=c(),o()||(h+=c());continue}if(h+=c(),l==='"')break}continue}y==="("?a++:y===")"&&a--,h+=c();continue}h+=c()}o()||c(),r.push({type:"STRING",value:h,pos:f});continue}if(p(i)||i==="$"||i==="@"){let h=i;for(;!o()&&s(n());)h+=c();let a=At.get(h);a?r.push({type:a,value:h,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${i}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ut=class t{tokens;pos=0;constructor(r){this.tokens=r}peek(r=0){return this.tokens[this.pos+r]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(r){return this.peek().type===r}match(...r){for(let e of r)if(this.check(e))return this.advance();return null}expect(r,e){if(!this.check(r))throw new Error(`${e} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}isFieldNameAfterDot(r=0){let e=this.peek(r),n=this.peek(r+1);return n.type==="STRING"?!0:n.type==="IDENT"||Y.has(n.type)?n.pos===e.pos+1:!1}isIdentLike(){let r=this.peek().type;return r==="IDENT"||Y.has(r)}consumeFieldNameAfterDot(r){let e=this.peek();return e.type==="STRING"?this.advance().value:(e.type==="IDENT"||Y.has(e.type))&&e.pos===r.pos+1?this.advance().value:null}parse(){let r=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return r}parseExpr(){return this.parsePipe()}parsePattern(){if(this.match("LBRACKET")){let n=[];if(!this.check("RBRACKET"))for(n.push(this.parsePattern());this.match("COMMA")&&!this.check("RBRACKET");)n.push(this.parsePattern());return this.expect("RBRACKET","Expected ']' after array pattern"),{type:"array",elements:n}}if(this.match("LBRACE")){let n=[];if(!this.check("RBRACE"))for(n.push(this.parsePatternField());this.match("COMMA")&&!this.check("RBRACE");)n.push(this.parsePatternField());return this.expect("RBRACE","Expected '}' after object pattern"),{type:"object",fields:n}}let r=this.expect("IDENT","Expected variable name in pattern"),e=r.value;if(!e.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);return{type:"var",name:e}}parsePatternField(){if(this.match("LPAREN")){let e=this.parseExpr();this.expect("RPAREN","Expected ')' after computed key"),this.expect("COLON","Expected ':' after computed key");let n=this.parsePattern();return{key:e,pattern:n}}let r=this.peek();if(r.type==="IDENT"||Y.has(r.type)){let e=r.value;if(e.startsWith("$")){if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e.slice(1),pattern:n,keyVar:e}}return{key:e.slice(1),pattern:{type:"var",name:e}}}if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e,pattern:n}}return{key:e,pattern:{type:"var",name:`$${e}`}}}throw new Error(`Expected field name in object pattern at position ${r.pos}`)}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let e=this.parseComma();r={type:"Pipe",left:r,right:e}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let e=this.parseVarBind();r={type:"Comma",left:r,right:e}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let e=this.parsePattern(),n=[];for(;this.check("QUESTION")&&this.peekAhead(1)?.type==="ALT";)this.advance(),this.advance(),n.push(this.parsePattern());this.expect("PIPE","Expected '|' after variable binding");let c=this.parseExpr();return e.type==="var"&&n.length===0?{type:"VarBind",name:e.name,value:r,body:c}:{type:"VarBind",name:e.type==="var"?e.name:"",value:r,body:c,pattern:e.type!=="var"?e:void 0,alternatives:n.length>0?n:void 0}}return r}peekAhead(r){let e=this.pos+r;return e"],["GE",">="]]),n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let c=e.get(n.type);if(c){let o=this.parseAddSub();r={type:"BinaryOp",op:c,left:r,right:o}}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:e}}else if(this.match("MINUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:e}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let e=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:e}}else if(this.match("SLASH")){let e=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:e}}else if(this.match("PERCENT")){let e=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:e}}else break;return r}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let r=this.parsePrimary();for(;;)if(this.match("QUESTION"))r={type:"Optional",expr:r};else if(this.check("DOT")&&this.isFieldNameAfterDot())this.advance(),r={type:"Field",name:this.advance().value,base:r};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))r={type:"Iterate",base:r};else if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:e,base:r}}else{let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:e,end:n,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:e,base:r}}else break;return r}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.check("DOT")){let r=this.advance();if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let c=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:c}}let n=this.parseExpr();if(this.match("COLON")){let c=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:n,end:c}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:n}}let e=this.consumeFieldNameAfterDot(r);return e!==null?{type:"Field",name:e}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let e=this.advance().value;return e.includes("\\(")?this.parseStringInterpolation(e):{type:"Literal",value:e}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let r=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:r}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let r=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:r}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let r=this.parsePostfix(),e;return this.match("CATCH")&&(e=this.parsePostfix()),{type:"Try",body:r,catch:e}}if(this.match("REDUCE")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after reduce expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let c=this.parseExpr();this.expect("RPAREN","Expected ')' after update expression");let o=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:o,init:n,update:c,pattern:e.type!=="var"?e:void 0}}if(this.match("FOREACH")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after foreach expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let c=this.parseExpr(),o;this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions");let u=e.type==="var"?e.name:"";return{type:"Foreach",expr:r,varName:u,init:n,update:c,extract:o,pattern:e.type!=="var"?e:void 0}}if(this.match("LABEL")){let r=this.expect("IDENT","Expected label name (e.g., $out)"),e=r.value;if(!e.startsWith("$"))throw new Error(`Label name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after label name");let n=this.parseExpr();return{type:"Label",name:e,body:n}}if(this.match("BREAK")){let r=this.expect("IDENT","Expected label name to break to"),e=r.value;if(!e.startsWith("$"))throw new Error(`Break label must start with $ at position ${r.pos}`);return{type:"Break",name:e}}if(this.match("DEF")){let e=this.expect("IDENT","Expected function name after def").value,n=[];if(this.match("LPAREN")){if(!this.check("RPAREN")){let u=this.expect("IDENT","Expected parameter name");for(n.push(u.value);this.match("SEMICOLON");){let p=this.expect("IDENT","Expected parameter name");n.push(p.value)}}this.expect("RPAREN","Expected ')' after parameters")}this.expect("COLON","Expected ':' after function name");let c=this.parseExpr();this.expect("SEMICOLON","Expected ';' after function body");let o=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:c,body:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let e=this.advance().value;if(e.startsWith("$"))return{type:"VarRef",name:e};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:e,args:n}}return{type:"Call",name:e,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let e,n;if(this.match("LPAREN"))e=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.isIdentLike()){let c=this.advance().value;this.match("COLON")?(e=c,n=this.parseObjectValue()):(e=c,n={type:"Field",name:c})}else if(this.check("STRING"))e=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:e,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let e=this.parseVarBind();r={type:"Pipe",left:r,right:e}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let e=this.parseExpr(),n=[];for(;this.match("ELIF");){let o=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:o,then:u})}let c;return this.match("ELSE")&&(c=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:e,elifs:n,else:c}}parseStringInterpolation(r){let e=[],n="",c=0;for(;c0;){let f=r[c];if(f==='"'){for(u+=f,c++;c0&&(u+=f),c++}let p=Et(u),s=new t(p);e.push(s.parse())}else n+=r[c],c++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function Ne(t){let r=Et(t);return new ut(r).parse()}export{d as a,Ne as b}; diff --git a/packages/just-bash/dist/bin/chunks/chunk-LMA4D2KK.js b/packages/just-bash/dist/bin/chunks/chunk-LMA4D2KK.js deleted file mode 100644 index 0d8786f1..00000000 --- a/packages/just-bash/dist/bin/chunks/chunk-LMA4D2KK.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as g,b as A,c as T,d as at,e as E,g as O,h as G}from"./chunk-MLUOPG3W.js";import{a as X,c as lt}from"./chunk-MROECM42.js";import{a as yt}from"./chunk-AZH64XMJ.js";import{a as R}from"./chunk-52FZYTIX.js";import{k as B}from"./chunk-47WZ2U6M.js";function W(t,r,e,n,p,o,u,c,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,a)=>{let y=p(h,e[0],n)[0],l=p(a,e[0],n)[0];return u(y,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:p(t,e[0],n).map(h=>{let a=0,y=t.length;for(;a>>1;u(t[l],h)<0?a=l+1:y=l}return au(a.key,y.key)),[h.map(a=>a.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let h of t){let a=JSON.stringify(p(h,e[0],n)[0]);i.has(a)||i.set(a,[]),i.get(a)?.push(h)}return[[...i.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)>0?i:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)>0?i:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)<0?i:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)<0?i:h})];case"add":{let i=h=>{let a=h.filter(y=>y!==null);return a.length===0?null:a.every(y=>typeof y=="number")?a.reduce((y,l)=>y+l,0):a.every(y=>typeof y=="string")?a.join(""):a.every(y=>Array.isArray(y))?a.flat():a.every(y=>y&&typeof y=="object"&&!Array.isArray(y))?lt(...a):null};if(e.length>=1){let h=p(t,e[0],n);return[i(h)]}return Array.isArray(t)?[i(t)]:[null]}case"any":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(p(h,e[1],n).some(c))return[!0]}catch(i){if(i instanceof f)throw i}return[!1]}return e.length===1?Array.isArray(t)?[t.some(i=>c(p(i,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(c)]:[!1]}case"all":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(!p(h,e[1],n).some(c))return[!1]}catch(i){if(i instanceof f)throw i}return[!0]}return e.length===1?Array.isArray(t)?[t.every(i=>c(p(i,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(c)]:[!0]}case"select":return e.length===0?[t]:p(t,e[0],n).some(c)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>p(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(i=>p(i,e[0],n))];if(t&&typeof t=="object"){let i=Object.create(null);for(let[h,a]of Object.entries(t)){if(!g(h))continue;let y=p(a,e[0],n);y.length>0&&A(i,h,y[0])}return[i]}return[null]}case"has":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h=0&&t0)try{let s=o(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof c)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=p(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=p(t,e[0],n);if(e.length>1){for(let i of s)if(i<0)throw new Error("nth doesn't support negative indices");let f;try{f=o(t,e[1],n)}catch(i){if(i instanceof c)throw i;f=[]}return s.flatMap(i=>{let h=i;return h{let i=f;if(i<0)throw new Error("nth doesn't support negative indices");return il.length>=s,i=p(t,e[0],n);if(e.length===1){let l=[];for(let m of i){let b=m;for(let w=0;w0){for(let C=w;Ck;C+=N)if(y.push(C),f(y))return y}}return y}case"limit":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("limit doesn't support negative count");if(i===0)return[];let h;try{h=o(t,e[1],n)}catch(a){if(a instanceof c)throw a;h=[]}return h.slice(0,i)});case"isempty":{if(e.length<1)return[!0];try{return[o(t,e[0],n).length===0]}catch(s){if(s instanceof c)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[p(t,e[0],n).length>0]}catch(s){if(s instanceof c)throw s;return[!1]}}case"skip":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("skip doesn't support negative count");return p(t,e[1],n).slice(i)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let i=0;i=i)throw new c(`jq while: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,i=n.limits.maxIterations;for(let h=0;h=i)throw new c(`jq repeat: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function Z(t,r,e,n,p){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let o=new Date(t*1e3),u=o.getUTCFullYear(),c=o.getUTCMonth(),s=o.getUTCDate(),f=o.getUTCHours(),i=o.getUTCMinutes(),h=o.getUTCSeconds(),a=o.getUTCDay(),y=Date.UTC(u,0,1),l=Math.floor((o.getTime()-y)/(1440*60*1e3));return[[u,c,s,f,i,h,a,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[o,u,c,s=0,f=0,i=0]=t;if(typeof o!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(o,u,c??1,s??0,f??0,i??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let c;if(typeof t=="number")c=new Date(t*1e3);else if(Array.isArray(t)){let[a,y,l,m=0,b=0,w=0]=t;if(typeof a!="number"||typeof y!="number")throw new Error("strftime/1 requires parsed datetime inputs");c=new Date(Date.UTC(a,y,l??1,m??0,b??0,w??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],i=(a,y=2)=>String(a).padStart(y,"0");return[u.replace(/%Y/g,String(c.getUTCFullYear())).replace(/%m/g,i(c.getUTCMonth()+1)).replace(/%d/g,i(c.getUTCDate())).replace(/%H/g,i(c.getUTCHours())).replace(/%M/g,i(c.getUTCMinutes())).replace(/%S/g,i(c.getUTCSeconds())).replace(/%A/g,s[c.getUTCDay()]).replace(/%B/g,f[c.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,i,h,a,y,l]=s.map(Number),m=new Date(Date.UTC(f,i-1,h,a,y,l)),b=m.getUTCDay(),w=Date.UTC(f,0,1),k=Math.floor((m.getTime()-w)/(1440*60*1e3));return[[f,i-1,h,a,y,l,b,k]]}}let c=new Date(t);if(!Number.isNaN(c.getTime())){let s=c.getUTCFullYear(),f=c.getUTCMonth(),i=c.getUTCDate(),h=c.getUTCHours(),a=c.getUTCMinutes(),y=c.getUTCSeconds(),l=c.getUTCDay(),m=Date.UTC(s,0,1),b=Math.floor((c.getTime()-m)/(1440*60*1e3));return[[s,f,i,h,a,y,l,b]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let o=new Date(t);if(Number.isNaN(o.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(o.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function S(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function U(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function v(t,r){let e=O(t);for(let n of Object.keys(r)){if(!g(n))continue;let p=T(e,n)?E(e[n]):null,o=E(r[n]);p&&o?A(e,n,v(p,o)):A(e,n,r[n])}return e}function D(t,r=3e3){let e=0,n=t;for(;ec===null?0:typeof c=="boolean"?1:typeof c=="number"?2:typeof c=="string"?3:Array.isArray(c)?4:typeof c=="object"?5:6,n=e(t),p=e(r);if(n!==p)return n-p;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let c=0;ct.some(o=>F(o,p)));let e=E(t),n=E(r);return e&&n?Object.keys(n).every(p=>T(e,p)&&F(e[p],n[p])):!1}var Ot=2e3;function tt(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(p=>{if(p===null)return"";if(typeof p=="boolean")return p?"true":"false";if(typeof p=="number")return String(p);let o=String(p);return o.includes(",")||o.includes('"')||o.includes(` -`)||o.includes("\r")?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??Ot;return D(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function et(t,r,e,n,p,o){switch(r){case"index":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){if(c===""&&t==="")return null;let s=t.indexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let f=0;f<=t.length-c.length;f++){let i=!0;for(let h=0;ho(f,c));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){let s=t.lastIndexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let s=t.length-c.length;s>=0;s--){let f=!0;for(let i=0;i=0;s--)if(o(t[s],c))return s;return null}return null});case"indices":return e.length===0?[[]]:p(t,e[0],n).map(c=>{let s=[];if(typeof t=="string"&&typeof c=="string"){let f=t.indexOf(c);for(;f!==-1;)s.push(f),f=t.indexOf(c,f+1)}else if(Array.isArray(t))if(Array.isArray(c)){let f=c.length;if(f===0)for(let i=0;i<=t.length;i++)s.push(i);else for(let i=0;i<=t.length-f;i++){let h=!0;for(let a=0;a{if(y.push(m),Array.isArray(m))for(let b of m)l(b);else if(m&&typeof m=="object")for(let b of Object.keys(m))l(m[b])};return l(t),y}let s=[],f=e.length>=2?e[1]:null,i=1e4,h=0,a=y=>{if(h++>i||f&&!p(y,f,n).some(o))return;s.push(y);let l=p(y,e[0],n);for(let m of l)m!=null&&a(m)};return a(t),s}case"recurse_down":return c(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=i=>{if(i&&typeof i=="object"){if(s.has(i))return i;s.add(i)}let h;if(Array.isArray(i))h=i.map(f);else if(i&&typeof i=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(i))g(l)&&A(y,l,f(m));h=y}else h=i;return p(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(i=>Array.isArray(i)?i.length:0)),f=[];for(let i=0;iArray.isArray(h)?h[i]:null));return[f]}case"combinations":{if(e.length>0){let h=p(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let a=[],y=(l,m)=>{if(m===h){a.push([...l]);return}for(let b of t)l.push(b),y(l,m+1),l.pop()};return y([],0),a}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let i of t)if(!Array.isArray(i))return[];let s=[],f=(i,h)=>{if(i===t.length){s.push([...h]);return}let a=t[i];for(let y of a)h.push(y),f(i+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?p(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let i=s.slice(0,s.length-f);return[u(n.root,i)]}else{let i=-f-1;if(i>=s.length)return[t];let h=s.slice(0,i);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let i=s.length-1;i>=0;i--)f.push(u(n.root,s.slice(0,i)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var Nt=2e3;function st(t,r,e,n,p){switch(r){case"keys":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) only strings have UTF-8 byte length`)}case"to_entries":{let o=E(t);return o?[Object.entries(o).map(([u,c])=>({key:u,value:c}))]:[null]}case"from_entries":if(Array.isArray(t)){let o=Object.create(null);for(let u of t){let c=E(u);if(c){let s=c.key??c.Key??c.name??c.Name??c.k,f=c.value??c.Value??c.v;if(s!==void 0){let i=String(s);g(i)&&A(o,i,f)}}}return[o]}return[null];case"with_entries":{if(e.length===0)return[t];let o=E(t);if(o){let c=Object.entries(o).map(([f,i])=>({key:f,value:i})).flatMap(f=>p(f,e[0],n)),s=Object.create(null);for(let f of c){let i=E(f);if(i){let h=i.key??i.name??i.k,a=i.value??i.v;if(h!==void 0){let y=String(h);g(y)&&A(s,y,a)}}}return[s]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?p(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let c=u;if(c<0)throw new Error("flatten depth must not be negative");return t.flat(c)}):[null];case"unique":if(Array.isArray(t)){let o=new Set,u=[];for(let c of t){let s=JSON.stringify(c);o.has(s)||(o.add(s),u.push(c))}return[u]}return[null];case"tojson":case"tojsonstream":{let o=n.limits.maxDepth??Nt;return D(t,o+1)>o?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let o=t.trim().toLowerCase();if(o==="nan")return[Number.NaN];if(o==="inf"||o==="infinity")return[Number.POSITIVE_INFINITY];if(o==="-inf"||o==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[at(JSON.parse(t))]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let o=Number(t);if(Number.isNaN(o))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[o]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) cannot be parsed as a boolean`)}case"tostream":{let o=[],u=(c,s)=>{if(c===null||typeof c!="object")o.push([s,c]);else if(Array.isArray(c))if(c.length===0)o.push([s,[]]);else for(let f=0;fo&&u.push([f.slice(o)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],i=s[1];f.length>o&&u.push([f.slice(o),i])}}return u}default:return null}}function it(t,r,e,n,p,o,u,c,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let i=p(t,e[0],n),h=[];for(let a of i){let y=a,l=t;for(let m of y){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof m=="string"){let b=E(l);if(!b||!Object.hasOwn(b,m)){l=null;break}l=b[m]}else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=p(t,e[0],n)[0],y=p(t,e[1],n)[0];return[u(t,h,y)]}case"delpaths":{if(e.length===0)return[t];let h=p(t,e[0],n)[0],a=t;for(let y of h.sort((l,m)=>m.length-l.length))a=c(a,y);return[a]}case"path":{if(e.length===0)return[[]];let i=[];return f(t,e[0],n,[],i),i}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let i=[];for(let a of e)f(t,a,n,[],i);let h=null;for(let a of i){for(let l of a)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let y=t;for(let l of a){if(y==null)break;if(Array.isArray(y)&&typeof l=="number")y=y[l];else if(typeof l=="string"){let m=E(y);if(!m||!Object.hasOwn(m,l)){y=null;break}y=m[l]}else{y=null;break}}h=u(h,a,y)}return[h]}case"paths":{let i=[],h=(a,y)=>{if(a&&typeof a=="object")if(Array.isArray(a))for(let l=0;l0?i.filter(a=>{let y=t;for(let m of a)if(Array.isArray(y)&&typeof m=="number")y=y[m];else if(typeof m=="string"){let b=E(y);if(!b||!Object.hasOwn(b,m))return!1;y=b[m]}else return!1;return p(y,e[0],n).some(o)}):i}case"leaf_paths":{let i=[],h=(a,y)=>{if(a===null||typeof a!="object")i.push(y);else if(Array.isArray(a))for(let l=0;lJSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[Object.create(null)];if(e.length===1){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=String(i);g(h)&&A(f,h,i)}return[f]}if(e.length===2){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=p(i,e[1],n);if(h.length>0){let a=String(h[0]);g(a)&&A(f,a,i)}}return[f]}let u=p(t,e[0],n),c=Object.create(null);for(let s of u){let f=p(s,e[1],n),i=p(s,e[2],n);if(f.length>0&&i.length>0){let h=String(f[0]);g(h)&&A(c,h,i[0])}}return[c]}case"JOIN":{if(e.length<2)return[null];let u=E(p(t,e[0],n)[0]);if(!u)return[null];if(!Array.isArray(t))return[null];let c=[];for(let s of t){let f=p(s,e[1],n),i=f.length>0?String(f[0]):"",h=T(u,i)?u[i]:null;c.push([s,h])}return[c]}default:return null}}function ft(t,r,e,n,p){switch(r){case"join":{if(!Array.isArray(t))return[null];let o=e.length>0?p(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return o.map(u=>t.map(c=>c===null?"":typeof c=="string"?c:String(c)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"g";return R(u,c.includes("g")?c:`${c}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[...R(u,c.includes("g")?c:`${c}g`).matchAll(t)].map(i=>i.length>1?i.slice(1):i[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[R(u,c).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,`${c}d`).exec(t);if(!f)return[];let i=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,a)=>({offset:i?.[a+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,c).match(t);return!f||!f.groups?[Object.create(null)]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"";return[R(c,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"g",i=f.includes("g")?f:`${f}g`;return[R(c,i).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,o=>String.fromCharCode(o.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,o=>String.fromCharCode(o.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);if(u==="")return[t];let c=t;return c.startsWith(u)&&(c=c.slice(u.length)),c.endsWith(u)&&(c=c.slice(0,-u.length)),[c]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n);return[t.startsWith(String(o[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n);return[t.endsWith(String(o[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(o=>o.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(c=>{if(typeof c=="string")throw new Error(`string (${JSON.stringify(c)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof c!="number"||Number.isNaN(c))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(c);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function ct(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function K(t,r,e){if(r.length===0)return e;let[n,...p]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let f=Array.isArray(t)?[...t]:[];for(;f.length<=n;)f.push(null);return f[n]=K(f[n],p,e),f}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!g(n))return t??Object.create(null);let o=E(t),u=o?O(o):Object.create(null),c=Object.hasOwn(u,n)?u[n]:void 0;return A(u,n,K(c,p,e)),u}function V(t,r){if(r.length===0)return null;if(r.length===1){let p=r[0];if(Array.isArray(t)&&typeof p=="number"){let o=[...t];return o.splice(p,1),o}if(t&&typeof t=="object"&&!Array.isArray(t)){let o=String(p);if(!g(o))return t;let u=O(t);return delete u[o],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let p=[...t];return p[e]=V(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!g(p))return t;let o=O(t);return Object.hasOwn(o,p)&&A(o,p,V(o[p],n)),o}return t}var P=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},H=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},St=1e4,bt=2e3,Ct=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function Tt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??St,maxDepth:t?.limits?.maxDepth??bt},env:t?.env,coverage:t?.coverage,requireDefenseContext:t?.requireDefenseContext,defenseContextChecked:!1}}function q(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,requireDefenseContext:t.requireDefenseContext,defenseContextChecked:t.defenseContextChecked,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels,coverage:t.coverage}}function L(t,r,e){switch(r.type){case"var":return q(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let p=0;p0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=pt(t,r.left);return e===null?null:pt(e,r.right)}return r.type==="Identity"?t:null}function mt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof B)throw p;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(p){if(p instanceof B)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Tt(e);switch(n.defenseContextChecked||(yt(n.requireDefenseContext,"query-engine","evaluation"),n={...n,defenseContextChecked:!0}),n.root===void 0&&(n={...n,root:t,currentPath:[]}),n.coverage?.hit(`jq:node:${r.type}`),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(o=>{let u=E(o);if(u){if(!Object.hasOwn(u,r.name))return[null];let s=u[r.name];return[s===void 0?null:s]}if(o===null)return[null];let c=Array.isArray(o)?"array":typeof o;throw new Error(`Cannot index ${c} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(o=>d(o,r.index,n).flatMap(c=>{if(typeof c=="number"&&Array.isArray(o)){if(Number.isNaN(c))return[null];let s=Math.trunc(c),f=s<0?o.length+s:s;return f>=0&&f{if(o===null)return[null];if(!Array.isArray(o)&&typeof o!="string")throw new Error(`Cannot slice ${typeof o} (${JSON.stringify(o)})`);let u=o.length,c=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return c.flatMap(f=>s.map(i=>{let h=f,a=i,y=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(a)?u:Number.isInteger(a)?a:Math.ceil(a),m=dt(y,u),b=dt(l,u);return Array.isArray(o),o.slice(m,b)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(o=>Array.isArray(o)?o:o&&typeof o=="object"?Object.values(o):[]);case"Pipe":{let p=d(t,r.left,n),o=M(r.left),u=[];for(let c of p)try{if(o!==null){let s={...n,currentPath:[...n.currentPath??[],...o]};u.push(...d(c,r.right,s))}else u.push(...d(c,r.right,n))}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Comma":{let p=d(t,r.left,n),o=d(t,r.right,n);return[...p,...o]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let p=[Object.create(null)];for(let o of r.entries){let u=typeof o.key=="string"?[o.key]:d(t,o.key,n),c=d(t,o.value,n),s=[];for(let f of p)for(let i of u){if(typeof i!="string"){let h=i===null?"null":Array.isArray(i)?"array":typeof i;throw new Error(`Cannot use ${h} (${JSON.stringify(i)}) as object key`)}if(!g(i)){for(let h of c)s.push(O(f));continue}for(let h of c){let a=O(f);A(a,i,h),s.push(a)}}p.length=0,p.push(...s)}return p}case"Paren":return d(t,r.expr,n);case"BinaryOp":return xt(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(o=>{if(r.op==="-"){if(typeof o=="number")return-o;if(typeof o=="string"){let u=c=>c.length>5?`"${c.slice(0,3)}...`:JSON.stringify(c);throw new Error(`string (${u(o)}) cannot be negated`)}return null}return r.op==="not"?!S(o):null});case"Cond":return d(t,r.cond,n).flatMap(o=>{if(S(o))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(S))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(p){if(r.catch){let o=p instanceof H?p.value:p instanceof Error?p.message:String(p);return d(o,r.catch,n)}return[]}case"Call":return gt(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(o=>{let u=null,c=[];r.pattern?c.push(r.pattern):r.name&&c.push({type:"var",name:r.name}),r.alternatives&&c.push(...r.alternatives);for(let s of c)if(u=L(n,s,o),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?X(n.env):Object.create(null)];let p=n.vars.get(r.name);return p!==void 0?[p]:[null]}case"Recurse":{let p=[],o=new WeakSet,u=c=>{if(c&&typeof c=="object"){if(o.has(c))return;o.add(c)}if(p.push(c),Array.isArray(c))for(let s of c)u(s);else if(c&&typeof c=="object")for(let s of Object.keys(c))u(c[s])};return u(t),p}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(o=>typeof o=="string"?o:d(t,o,n).map(c=>typeof c=="string"?c:JSON.stringify(c)).join("")).join("")];case"UpdateOp":return[Mt(t,r.path,r.op,r.value,n)];case"Reduce":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=n.limits.maxDepth??bt;for(let c of p){let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],D(o,u+1)>u)return[null]}return[o]}case"Foreach":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=[];for(let c of p)try{let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],r.extract){let f=d(o,r.extract,s);u.push(...f)}else u.push(o)}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(p){if(p instanceof P&&p.label===r.name)return p.partialResults;throw p}case"Break":throw new P(r.name);case"Def":{let p=new Map(n.funcs??[]),o=`${r.name}/${r.params.length}`;p.set(o,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:p};return d(t,r.body,u)}default:{let p=r;throw new Error(`Unknown AST node type: ${p.type}`)}}}function dt(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Mt(t,r,e,n,p){function o(s,f){switch(e){case"=":return f;case"|=":return d(s,n,p)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?G(s,f):f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,i){switch(f.type){case"Identity":return i(s);case"Field":{if(!g(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a=O(h),y=Object.hasOwn(a,f.name)?a[f.name]:void 0;return A(a,f.name,i(y)),a}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h=O(s),a=Object.hasOwn(h,f.name)?h[f.name]:void 0;return A(h,f.name,i(a)),h}return s}case"Index":{let a=d(t,f.index,p)[0];if(typeof a=="number"&&Number.isNaN(a))throw new Error("Cannot set array element at NaN index");if(typeof a=="number"&&!Number.isInteger(a)&&(a=Math.trunc(a)),f.base)return u(s,f.base,y=>{if(typeof a=="number"&&Array.isArray(y)){let l=[...y],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(typeof a=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(a))return y;let l=O(y),m=Object.hasOwn(l,a)?l[a]:void 0;return A(l,a,i(m)),l}return y});if(typeof a=="number"){if(a>536870911)throw new Error("Array index too large");if(a<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(s==null){let l=[];for(;l.length<=a;)l.push(null);return l[a]=i(null),l}return s}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!g(a))return s;let y=O(s),l=Object.hasOwn(y,a)?y[a]:void 0;return A(y,a,i(l)),y}return s}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(y=>i(y));if(a&&typeof a=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(a))g(l)&&A(y,l,i(m));return y}return a};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,a=>a);return u(h,f.right,i)}default:return i(s)}}return u(t,r,s=>{if(e==="|=")return o(s,s);let f=d(t,n,p);return o(s,f[0]??null)})}function jt(t,r,e){function n(o,u,c){switch(u.type){case"Identity":return c;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0],f=n(s,{type:"Field",name:u.name},c);return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){let s=O(o);return A(s,u.name,c),s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0],h=n(i,{type:"Index",index:u.index},c);return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h=0&&h=0&&NS(s)?d(t,n,p).map(i=>S(i)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>S(s)?[!0]:d(t,n,p).map(i=>S(i)));if(r==="//"){let s=d(t,e,p).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,p)}let o=d(t,e,p),u=d(t,n,p);return o.flatMap(c=>u.map(s=>{switch(r){case"+":return c===null?s:s===null?c:typeof c=="number"&&typeof s=="number"||typeof c=="string"&&typeof s=="string"?c+s:Array.isArray(c)&&Array.isArray(s)?[...c,...s]:c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?G(c,s):null;case"-":if(typeof c=="number"&&typeof s=="number")return c-s;if(Array.isArray(c)&&Array.isArray(s)){let f=new Set(s.map(i=>JSON.stringify(i)));return c.filter(i=>!f.has(JSON.stringify(i)))}if(typeof c=="string"&&typeof s=="string"){let f=i=>i.length>10?`"${i.slice(0,10)}...`:JSON.stringify(i);throw new Error(`string (${f(c)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":if(typeof c=="number"&&typeof s=="number")return c*s;if(typeof c=="string"&&typeof s=="number")return c.repeat(s);{let f=E(c),i=E(s);if(f&&i)return v(f,i)}return null;case"/":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided because the divisor is zero`);return c/s}return typeof c=="string"&&typeof s=="string"?c.split(s):null;case"%":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(c)&&!Number.isNaN(c)?!Number.isFinite(s)&&!Number.isNaN(s)&&c<0&&s>0?-1:0:c%s}return null;case"==":return I(c,s);case"!=":return!I(c,s);case"<":return U(c,s)<0;case"<=":return U(c,s)<=0;case">":return U(c,s)>0;case">=":return U(c,s)>=0;default:return null}}))}function gt(t,r,e,n){let p=Ct.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let o=rt(t,r,e,n,d);if(o!==null)return o;let u=ft(t,r,e,n,d);if(u!==null)return u;let c=Z(t,r,e,n,d);if(c!==null)return c;let s=tt(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ct(t,r);if(f!==null)return f;let i=st(t,r,e,n,d);if(i!==null)return i;let h=W(t,r,e,n,d,mt,$,S,F,B);if(h!==null)return h;let a=it(t,r,e,n,d,S,K,V,jt,J);if(a!==null)return a;let y=et(t,r,e,n,d,I);if(y!==null)return y;let l=z(t,r,e,n,d,mt,S,B);if(l!==null)return l;let m=nt(t,r,e,n,d,S,Rt,gt);if(m!==null)return m;let b=ot(t,r,e,n,d,I);if(b!==null)return b;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let w=e.length>0?d(t,e[0],n)[0]:t;throw new H(w)}case"env":return[n.env?X(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let w=`${r}/${e.length}`,k=n.funcs?.get(w);if(k){let N=k.closure??n.funcs??new Map,C=new Map(N);C.set(w,k);for(let _=0;_=0;Q--)x={type:"Comma",left:{type:"Literal",value:j[Q]},right:x}}C.set(`${kt}/0`,{params:[],body:x})}}let wt={...n,funcs:C};return d(t,k.body,wt)}throw new Error(`Unknown function: ${r}`)}}}function J(t,r,e,n,p){if(r.type==="Comma"){let c=r;J(t,c.left,e,n,p),J(t,c.right,e,n,p);return}let o=M(r);if(o!==null){p.push([...n,...o]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let c=0;c{if(p.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let i=0;i0&&p.push(n)}var At=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]),Y=new Set(At.values());function Et(t){let r=[],e=0,n=(f=0)=>t[e+f],p=()=>t[e++],o=()=>e>=t.length,u=f=>f>="0"&&f<="9",c=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>c(f)||u(f);for(;!o();){let f=e,i=p();if(!(i===" "||i===" "||i===` -`||i==="\r")){if(i==="#"){for(;!o()&&n()!==` -`;)p();continue}if(i==="."&&n()==="."){p(),r.push({type:"DOTDOT",pos:f});continue}if(i==="="&&n()==="="){p(),r.push({type:"EQ",pos:f});continue}if(i==="!"&&n()==="="){p(),r.push({type:"NE",pos:f});continue}if(i==="<"&&n()==="="){p(),r.push({type:"LE",pos:f});continue}if(i===">"&&n()==="="){p(),r.push({type:"GE",pos:f});continue}if(i==="/"&&n()==="/"){p(),n()==="="?(p(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(i==="+"&&n()==="="){p(),r.push({type:"UPDATE_ADD",pos:f});continue}if(i==="-"&&n()==="="){p(),r.push({type:"UPDATE_SUB",pos:f});continue}if(i==="*"&&n()==="="){p(),r.push({type:"UPDATE_MUL",pos:f});continue}if(i==="/"&&n()==="="){p(),r.push({type:"UPDATE_DIV",pos:f});continue}if(i==="%"&&n()==="="){p(),r.push({type:"UPDATE_MOD",pos:f});continue}if(i==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(i==="."){r.push({type:"DOT",pos:f});continue}if(i==="|"){n()==="="?(p(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(i===","){r.push({type:"COMMA",pos:f});continue}if(i===":"){r.push({type:"COLON",pos:f});continue}if(i===";"){r.push({type:"SEMICOLON",pos:f});continue}if(i==="("){r.push({type:"LPAREN",pos:f});continue}if(i===")"){r.push({type:"RPAREN",pos:f});continue}if(i==="["){r.push({type:"LBRACKET",pos:f});continue}if(i==="]"){r.push({type:"RBRACKET",pos:f});continue}if(i==="{"){r.push({type:"LBRACE",pos:f});continue}if(i==="}"){r.push({type:"RBRACE",pos:f});continue}if(i==="?"){r.push({type:"QUESTION",pos:f});continue}if(i==="+"){r.push({type:"PLUS",pos:f});continue}if(i==="-"){r.push({type:"MINUS",pos:f});continue}if(i==="*"){r.push({type:"STAR",pos:f});continue}if(i==="/"){r.push({type:"SLASH",pos:f});continue}if(i==="%"){r.push({type:"PERCENT",pos:f});continue}if(i==="<"){r.push({type:"LT",pos:f});continue}if(i===">"){r.push({type:"GT",pos:f});continue}if(u(i)){let h=i;for(;!o()&&(u(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[e+1]==="+"||t[e+1]==="-")&&(h+=p()),h+=p();r.push({type:"NUMBER",value:Number(h),pos:f});continue}if(i==='"'){let h="";for(;!o()&&n()!=='"';)if(n()==="\\"){if(p(),o())break;let a=p();switch(a){case"n":h+=` -`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(";break;default:h+=a}}else h+=p();o()||p(),r.push({type:"STRING",value:h,pos:f});continue}if(c(i)||i==="$"||i==="@"){let h=i;for(;!o()&&s(n());)h+=p();let a=At.get(h);a?r.push({type:a,value:h,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${i}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ut=class t{tokens;pos=0;constructor(r){this.tokens=r}peek(r=0){return this.tokens[this.pos+r]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(r){return this.peek().type===r}match(...r){for(let e of r)if(this.check(e))return this.advance();return null}expect(r,e){if(!this.check(r))throw new Error(`${e} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}isFieldNameAfterDot(r=0){let e=this.peek(r),n=this.peek(r+1);return n.type==="STRING"?!0:n.type==="IDENT"||Y.has(n.type)?n.pos===e.pos+1:!1}isIdentLike(){let r=this.peek().type;return r==="IDENT"||Y.has(r)}consumeFieldNameAfterDot(r){let e=this.peek();return e.type==="STRING"?this.advance().value:(e.type==="IDENT"||Y.has(e.type))&&e.pos===r.pos+1?this.advance().value:null}parse(){let r=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return r}parseExpr(){return this.parsePipe()}parsePattern(){if(this.match("LBRACKET")){let n=[];if(!this.check("RBRACKET"))for(n.push(this.parsePattern());this.match("COMMA")&&!this.check("RBRACKET");)n.push(this.parsePattern());return this.expect("RBRACKET","Expected ']' after array pattern"),{type:"array",elements:n}}if(this.match("LBRACE")){let n=[];if(!this.check("RBRACE"))for(n.push(this.parsePatternField());this.match("COMMA")&&!this.check("RBRACE");)n.push(this.parsePatternField());return this.expect("RBRACE","Expected '}' after object pattern"),{type:"object",fields:n}}let r=this.expect("IDENT","Expected variable name in pattern"),e=r.value;if(!e.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);return{type:"var",name:e}}parsePatternField(){if(this.match("LPAREN")){let e=this.parseExpr();this.expect("RPAREN","Expected ')' after computed key"),this.expect("COLON","Expected ':' after computed key");let n=this.parsePattern();return{key:e,pattern:n}}let r=this.peek();if(r.type==="IDENT"||Y.has(r.type)){let e=r.value;if(e.startsWith("$")){if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e.slice(1),pattern:n,keyVar:e}}return{key:e.slice(1),pattern:{type:"var",name:e}}}if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e,pattern:n}}return{key:e,pattern:{type:"var",name:`$${e}`}}}throw new Error(`Expected field name in object pattern at position ${r.pos}`)}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let e=this.parseComma();r={type:"Pipe",left:r,right:e}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let e=this.parseVarBind();r={type:"Comma",left:r,right:e}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let e=this.parsePattern(),n=[];for(;this.check("QUESTION")&&this.peekAhead(1)?.type==="ALT";)this.advance(),this.advance(),n.push(this.parsePattern());this.expect("PIPE","Expected '|' after variable binding");let p=this.parseExpr();return e.type==="var"&&n.length===0?{type:"VarBind",name:e.name,value:r,body:p}:{type:"VarBind",name:e.type==="var"?e.name:"",value:r,body:p,pattern:e.type!=="var"?e:void 0,alternatives:n.length>0?n:void 0}}return r}peekAhead(r){let e=this.pos+r;return e"],["GE",">="]]),n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let p=e.get(n.type);if(p){let o=this.parseAddSub();r={type:"BinaryOp",op:p,left:r,right:o}}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:e}}else if(this.match("MINUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:e}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let e=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:e}}else if(this.match("SLASH")){let e=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:e}}else if(this.match("PERCENT")){let e=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:e}}else break;return r}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let r=this.parsePrimary();for(;;)if(this.match("QUESTION"))r={type:"Optional",expr:r};else if(this.check("DOT")&&this.isFieldNameAfterDot())this.advance(),r={type:"Field",name:this.advance().value,base:r};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))r={type:"Iterate",base:r};else if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:e,base:r}}else{let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:e,end:n,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:e,base:r}}else break;return r}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.check("DOT")){let r=this.advance();if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:p}}let n=this.parseExpr();if(this.match("COLON")){let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:n,end:p}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:n}}let e=this.consumeFieldNameAfterDot(r);return e!==null?{type:"Field",name:e}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let e=this.advance().value;return e.includes("\\(")?this.parseStringInterpolation(e):{type:"Literal",value:e}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let r=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:r}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let r=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:r}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let r=this.parsePostfix(),e;return this.match("CATCH")&&(e=this.parsePostfix()),{type:"Try",body:r,catch:e}}if(this.match("REDUCE")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after reduce expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr();this.expect("RPAREN","Expected ')' after update expression");let o=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:o,init:n,update:p,pattern:e.type!=="var"?e:void 0}}if(this.match("FOREACH")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after foreach expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr(),o;this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions");let u=e.type==="var"?e.name:"";return{type:"Foreach",expr:r,varName:u,init:n,update:p,extract:o,pattern:e.type!=="var"?e:void 0}}if(this.match("LABEL")){let r=this.expect("IDENT","Expected label name (e.g., $out)"),e=r.value;if(!e.startsWith("$"))throw new Error(`Label name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after label name");let n=this.parseExpr();return{type:"Label",name:e,body:n}}if(this.match("BREAK")){let r=this.expect("IDENT","Expected label name to break to"),e=r.value;if(!e.startsWith("$"))throw new Error(`Break label must start with $ at position ${r.pos}`);return{type:"Break",name:e}}if(this.match("DEF")){let e=this.expect("IDENT","Expected function name after def").value,n=[];if(this.match("LPAREN")){if(!this.check("RPAREN")){let u=this.expect("IDENT","Expected parameter name");for(n.push(u.value);this.match("SEMICOLON");){let c=this.expect("IDENT","Expected parameter name");n.push(c.value)}}this.expect("RPAREN","Expected ')' after parameters")}this.expect("COLON","Expected ':' after function name");let p=this.parseExpr();this.expect("SEMICOLON","Expected ';' after function body");let o=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:p,body:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let e=this.advance().value;if(e.startsWith("$"))return{type:"VarRef",name:e};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:e,args:n}}return{type:"Call",name:e,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let e,n;if(this.match("LPAREN"))e=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.isIdentLike()){let p=this.advance().value;this.match("COLON")?(e=p,n=this.parseObjectValue()):(e=p,n={type:"Field",name:p})}else if(this.check("STRING"))e=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:e,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let e=this.parseVarBind();r={type:"Pipe",left:r,right:e}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let e=this.parseExpr(),n=[];for(;this.match("ELIF");){let o=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:o,then:u})}let p;return this.match("ELSE")&&(p=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:e,elifs:n,else:p}}parseStringInterpolation(r){let e=[],n="",p=0;for(;p0;)r[p]==="("?o++:r[p]===")"&&o--,o>0&&(u+=r[p]),p++;let c=Et(u),s=new t(c);e.push(s.parse())}else n+=r[p],p++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function Ne(t){let r=Et(t);return new ut(r).parse()}export{d as a,Ne as b}; diff --git a/packages/just-bash/dist/bin/chunks/chunk-PDS5TEMS.js b/packages/just-bash/dist/bin/chunks/chunk-PDS5TEMS.js deleted file mode 100644 index 1c9f4c65..00000000 --- a/packages/just-bash/dist/bin/chunks/chunk-PDS5TEMS.js +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as O}from"./chunk-52FZYTIX.js";import{e as J,f as Y,g as $,h as ae,i as xe,j as _t,k as W}from"./chunk-47WZ2U6M.js";function _(e,t){for(;t>=","&=","|=","^="];function be(e){if(e.includes("#")){let[r,s]=e.split("#"),n=Number.parseInt(r,10);if(n<2||n>64)return Number.NaN;if(n<=36){let i=Number.parseInt(s,n);return i>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:i}let a=0;for(let i of s){let l;if(/[0-9]/.test(i))l=i.charCodeAt(0)-48;else if(/[a-z]/.test(i))l=i.charCodeAt(0)-97+10;else if(/[A-Z]/.test(i))l=i.charCodeAt(0)-65+36;else if(i==="@")l=62;else if(i==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(a=a*n+l,a>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return a}if(e.startsWith("0x")||e.startsWith("0X")){let r=Number.parseInt(e.slice(2),16);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let r=Number.parseInt(e,8);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function $t(e,t,r,s){if(r.slice(s,s+3)!=="$((")return null;let n=s+3,a=1,i=n;for(;n0;)r[n]==="("&&r[n+1]==="("?(a++,n+=2):r[n]===")"&&r[n+1]===")"?(a--,a>0&&(n+=2)):n++;let l=r.slice(i,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Ct(e,t){if(e.slice(t,t+2)!=="$'")return null;let r=t+2,s="";for(;r=e.length}function j(e,t,r){return _r(e,t,r)}function _r(e,t,r){let{expr:s,pos:n}=we(e,t,r);for(n=_(t,n);t[n]===",";){if(n++,Z(t,n))return Q(",",n);let{expr:i,pos:l}=we(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=_(t,l)}return{expr:s,pos:n}}function we(e,t,r){let{expr:s,pos:n}=$r(e,t,r);if(n=_(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=j(e,t,n);if(n=_(t,i),t[n]===":"){n++;let{expr:l,pos:o}=j(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function $r(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="||";){if(n+=2,Z(t,n))return Q("||",n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="&&";){if(n+=2,Z(t,n))return Q("&&",n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=_(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,Z(t,n))return Q("|",n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Mt(e,t,r);for(;n=_(t,n),t[n]==="^";){if(n++,Z(t,n))return Q("^",n);let{expr:i,pos:l}=Mt(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Mt(e,t,r){let{expr:s,pos:n}=Vt(e,t,r);for(;n=_(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,Z(t,n))return Q("&",n);let{expr:i,pos:l}=Vt(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Vt(e,t,r){let{expr:s,pos:n}=qt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=qt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function qt(e,t,r){let{expr:s,pos:n}=Qe(e,t,r);for(;;)if(n=_(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Qe(e,t,r){let{expr:s,pos:n}=Bt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Bt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Bt(e,t,r){let{expr:s,pos:n}=Ft(e,t,r);for(;n=_(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Ft(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Ft(e,t,r){let{expr:s,pos:n}=_e(e,t,r);for(;;)if(n=_(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,Z(t,n))return Q("*",n);let{expr:i,pos:l}=_e(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=_e(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function _e(e,t,r){let{expr:s,pos:n}=Ze(e,t,r),a=_(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,Z(t,a))return Q("**",a);let{expr:l,pos:o}=_e(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function Ze(e,t,r){let s=_(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=Ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=Ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Or(e,t,s)}function Cr(e,t){let r=e[t];return r==="$"||r==="`"}function Or(e,t,r){let{expr:s,pos:n}=zt(e,t,r,!1),a=[s];for(;Cr(t,n);){let{expr:l,pos:o}=zt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=j(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=_(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of ve)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=we(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:u}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function zt(e,t,r,s=!1){let n=_(t,r),a=$t(j,e,t,n);if(a)return a;let i=Ct(t,n);if(i)return i;let l=Ot(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let h=t.slice(u,f),d=f+1;if(t[d]==="#"){let m=d+1;for(;m0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(oa===" "||a===" "||a===` -`||a===";"||a==="&"||a==="|"||a==="<"||a===">"||a==="("||a===")";for(;s=e.length)return e.length;let i=e.indexOf(` -`,s);i===-1&&(i=e.length);let l=e.slice(s,i);if(a&&(l=l.replace(/^\t+/,"")),l===n){s=i+1;break}if(i>=e.length)return e.length;s=i+1}return Math.min(s,e.length)}function Zt(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,u=0,c=!1,f="",h=[],d=0;for(;i0;){let A=e[i];if(l)A==="'"&&(l=!1);else if(o)A==="\\"&&i+10&&d--,d===0&&A==="<"&&e[i+1]==="<"&&e[i+2]!=="<"){let S=i+2,y=!1;for(e[S]==="-"&&(y=!0,S++);e[S]===" "||e[S]===" ";)S++;let{delim:b,endPos:x}=Ue(e,S);if(b.length>0){h.push({delim:b,stripTabs:y}),f="",i=x;continue}}if(A===` -`&&h.length>0){let S=Lr(e,i,h);h.length=0,f="",i=S;continue}A==="'"?(l=!0,f=""):A==='"'?(o=!0,f=""):A==="\\"&&i+10?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",A==="("?i>0&&e[i-1]==="$"?a++:c||a++:A===")"?c?c=!1:a--:A===";"&&u>0&&i+10&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let m=e.slice(n,i),E=r().parse(m);return{part:w.commandSubstitution(E,!1),endIndex:i+1}}function Ut(e,t,r,s,n){let i=t+1,l="";for(;i=e.length&&n("unexpected EOF while looking for matching ``'");let u=s().parse(l);return{part:w.commandSubstitution(u,!0),endIndex:i+1}}var Wr=10485760,p;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(p||(p={}));var Ee=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},Ht=new Map([["if",p.IF],["then",p.THEN],["else",p.ELSE],["elif",p.ELIF],["fi",p.FI],["for",p.FOR],["while",p.WHILE],["until",p.UNTIL],["do",p.DO],["done",p.DONE],["case",p.CASE],["esac",p.ESAC],["in",p.IN],["function",p.FUNCTION],["select",p.SELECT],["time",p.TIME],["coproc",p.COPROC]]);function jt(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let r=e.slice(t[0].length);if(r===""||r==="+")return!0;if(r[0]==="["){let s=0,n=0;for(;n=r.length)return!1;let a=r.slice(n+1);return a===""||a==="+"}return!1}function Kt(e){let t=0;for(let r=0;r",">",p.AND_DGREAT]],Mr=[["[","[",p.DBRACK_START],["]","]",p.DBRACK_END],["(","(",p.DPAREN_START],[")",")",p.DPAREN_END],["&","&",p.AND_AND],["|","|",p.OR_OR],[";",";",p.DSEMI],[";","&",p.SEMI_AND],["|","&",p.PIPE_AMP],[">",">",p.DGREAT],["<","&",p.LESSAND],[">","&",p.GREATAND],["<",">",p.LESSGREAT],[">","|",p.CLOBBER],["&",">",p.AND_GREAT]],Vr=new Map([["|",p.PIPE],["&",p.AMP],[";",p.SEMICOLON],["(",p.LPAREN],[")",p.RPAREN],["<",p.LESS],[">",p.GREAT]]);function qr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Xt(e){return e===" "||e===" "||e===` -`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var $e=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,r){this.input=t,this.maxHeredocSize=r?.maxHeredocSize??Wr}tokenize(){let r=this.input.length,s=this.tokens,n=this.pendingHeredocs;for(;this.pos0&&s.length>0&&s[s.length-1].type===p.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=r)break;let a=this.nextToken();a&&s.push(a)}return s.push({type:p.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),s}skipWhitespace(){let t=this.input,r=t.length,s=this.pos,n=this.column,a=this.line;for(;s0?(this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n)):this.looksLikeNestedSubshells(r+2)||this.dparenClosesWithSpacedParens(r+2)?(this.pos=r+1,this.column=n+1,this.makeToken(p.LPAREN,"(",r,s,n)):(this.pos=r+2,this.column=n+2,this.dparenDepth=1,this.makeToken(p.DPAREN_START,"((",r,s,n));if(a===")"&&i===")")return this.dparenDepth===1?(this.pos=r+2,this.column=n+2,this.dparenDepth=0,this.makeToken(p.DPAREN_END,"))",r,s,n)):this.dparenDepth>1?(this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.RPAREN,")",r,s,n));for(let[u,c,f]of Mr)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===p.DSEMI||f===p.SEMI_AND||f===p.SEMI_SEMI_AND))&&a===u&&i===c){if(f===p.DBRACK_START||f===p.DBRACK_END){let h=t[r+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==` -`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,u+c,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n);let o=Vr.get(a);if(o!==void 0)return this.pos=r+1,this.column=n+1,this.makeToken(o,a,r,s,n);if(a==="{"){let u=this.scanFdVariable(r);return u!==null?(this.pos=u.end,this.column=n+(u.end-r),{type:p.FD_VARIABLE,value:u.varname,start:r,end:u.end,line:s,column:n}):i==="}"?(this.pos=r+2,this.column=n+2,{type:p.WORD,value:"{}",start:r,end:r+2,line:s,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(r)!==null?this.readWordWithBraceExpansion(r,s,n):this.scanLiteralBraceWord(r)!==null?this.readWordWithBraceExpansion(r,s,n):i!==void 0&&i!==" "&&i!==" "&&i!==` -`?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.LBRACE,"{",r,s,n))}return a==="}"?this.isWordCharFollowing(r+1)?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.RBRACE,"}",r,s,n)):a==="!"?i==="="?(this.pos=r+2,this.column=n+2,this.makeToken(p.WORD,"!=",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.BANG,"!",r,s,n)):this.readWord(r,s,n)}looksLikeNestedSubshells(t){let r=this.input,s=r.length,n=t;for(;n=s)return!1;let a=r[n];if(a==="(")return this.looksLikeNestedSubshells(n+1);let i=/[a-zA-Z_]/.test(a),l=a==="!"||a==="[";if(!i&&!l)return!1;let o=n;for(;o=s)return!1;let c=r[u];if(c==="="&&r[u+1]!=="="||c===` -`||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&r[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;i++}if(i>l){let y=n[i];if(!(y==="("&&i>l&&"@*+?!".includes(n[i-1]))){if(i>=a||y===" "||y===" "||y===` -`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let x=Ht.get(b);if(x!==void 0)return{type:x,value:b,start:t,end:i,line:r,column:s};let H=Kt(b);return H>0&&jt(b.slice(0,H))?{type:p.ASSIGNMENT_WORD,value:b,start:t,end:i,line:r,column:s}:/^[0-9]+$/.test(b)?{type:p.NUMBER,value:b,start:t,end:i,line:r,column:s}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:p.NAME,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}:{type:p.WORD,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}}}}i=this.pos;let o=this.column,u=this.line,c="",f=!1,h=!1,d=!1,m=!1,g=n[i]==='"'||n[i]==="'",E=!1,A=0;for(;i0&&"@*+?!".includes(c[c.length-1])){let b=this.scanExtglobPattern(i);if(b!==null){c+=b.content,i=b.end,o+=b.content.length;continue}}if(y==="["&&A===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let b=i+10){c.length>0&&c[c.length-1]!=="\\"&&A++,c+=y,i++,o++;continue}else if(y==="]"&&A>0){c.length>0&&c[c.length-1]!=="\\"&&A--,c+=y,i++,o++;continue}if(A>0){if(y===` -`)break;c+=y,i++,o++;continue}if(y===" "||y===" "||y===` -`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+10&&i0&&De--,De===0&&L==="<"&&n[i+1]==="<"&&n[i+2]!=="<"){let V=i+2,ie=!1;for(n[V]==="-"&&(ie=!0,V++);n[V]===" "||n[V]===" ";)V++;let{delim:ce,endPos:C}=Ue(n,V);if(ce.length>0){c+=n.slice(i+1,C),o+=C-i,me.push({delim:ce,stripTabs:ie}),i=C;continue}}if(L===` -`&&me.length>0){u++,o=0;let V=i+1;for(let{delim:ie,stripTabs:ce}of me)for(;!(V>=a);){let C=n.indexOf(` -`,V);C===-1&&(C=a);let vt=n.slice(V,C),Dr=ce?vt.replace(/^\t+/,""):vt;c+=n.slice(V,Math.min(C+1,a)),C=a;if(V=C+1,Dr===ie||xr)break}me.length=0,o=0,i=Math.min(V,a);continue}if(L==="'")x=!0,z="";else if(L==='"')H=!0,z="";else if(L==="\\"&&i+10&&i0?X=!0:z==="esac"&&le>0&&(le--,X=!1),z="",L==="("?i>0&&n[i-1]==="$"?b++:X||b++:L===")"?X?X=!1:b--:L===";"&&le>0&&(i+10&&i0&&i="0"&&b<="9"){c+=y+b,i+=2,o+=2;continue}}if(y==="`"&&!d){for(c+=y,i++,o++;i=2){if(c[0]==="'"&&c[c.length-1]==="'"){let y=c.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(c=y,f=!0,h=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let y=c.slice(1,-1),b=!1;for(let x=0;x0&&jt(c.slice(0,y)))return{type:p.ASSIGNMENT_WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}return/^[0-9]+$/.test(c)?{type:p.NUMBER,value:c,start:t,end:i,line:r,column:s}:qr(c)?{type:p.NAME,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}:{type:p.WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let r=this.pos,s=this.line,n=this.column,a="";for(;this.posthis.maxHeredocSize)throw new Ee(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,s,n);this.pos&|()]/.test(i))break;if(i==="'"||i==='"'){a=!0;let l=i;for(this.pos++,this.column++;this.pos=this.input.length)return!1;let r=this.input[t];return!(r===" "||r===" "||r===` -`||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(t,r,s){let n=this.input,a=n.length,i=t,l=s;for(;i")break;if(u==="{"){if(this.scanBraceExpansion(i)!==null){let f=1;for(i++,l++;i0;)n[i]==="{"?f++:n[i]==="}"&&f--,i++,l++;continue}i++,l++;continue}if(u==="}"){i++,l++;continue}if(u==="$"&&i+10&&i0&&i0;){let o=r[n];if(o==="{")a++,n++;else if(o==="}")a--,n++;else if(o===","&&a===1)i=!0,n++;else if(o==="."&&n+10;){let i=r[n];if(i==="{")a++,n++;else if(i==="}"){if(a--,a===0)return r.slice(t,n+1);n++}else{if(i===" "||i===" "||i===` -`||i===";"||i==="&"||i==="|")return null;n++}}return null}scanExtglobPattern(t){let r=this.input,s=r.length,n=t+1,a=1;for(;n0;){let i=r[n];if(i==="\\"&&n+1="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===a)return null;let i=r.slice(a,n);if(n>=s||r[n]!=="}"||(n++,n>=s))return null;let l=r[n],o=n+1"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:i,end:n}:null}dollarDparenIsSubshell(t){let r=this.input,s=r.length,n=t+1,a=2,i=!1,l=!1,o=!1;for(;n0;){let u=r[n];if(i){u==="'"&&(i=!1),u===` -`&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===` -`&&(o=!0),n++;continue}if(u==="'"){i=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===` -`&&(o=!0),u==="("){a++,n++;continue}if(u===")"){if(a--,a===1){let c=n+1;if(c0;){let o=r[n];if(i){o==="'"&&(i=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){i=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){a++,n++;continue}if(o===")"){if(a--,a===1){let u=n+1;if(u=194){let n=(s&31)<<6|e[r+1]&63;t+=String.fromCharCode(n),r+=2;continue}t+=String.fromCharCode(s),r++;continue}if((s&240)===224){if(r+2=55296&&n<=57343){t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(n),r+=3;continue}t+=String.fromCharCode(s),r++;continue}if((s&248)===240&&s<=244){if(r+31114111){t+=String.fromCharCode(s),r++;continue}t+=String.fromCodePoint(n),r+=4;continue}t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(s),r++}return t}function rn(e,t,r){let s=r+1;for(;s0;)t[i]===s?a++:t[i]===n&&a--,a>0&&i++;return a===0?i:-1}function ge(e,t,r){let s=r,n=1;for(;s0;){let a=t[s];if(a==="\\"&&s+10&&s++}return s}function sn(e,t,r){let s=r,n=!1;for(;s0)l.push(c),o+=2+u.length;else break}l.length>0?(s+=Br(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2({type:"Word",word:w.word(s(e,c,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:nn(a).map(c=>({type:"Word",word:w.word([w.literal(c)])}))},endIndex:n+1}:null}function Ye(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(Ye(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function cn(e,t){return{[p.LESS]:"<",[p.GREAT]:">",[p.DGREAT]:">>",[p.LESSAND]:"<&",[p.GREATAND]:">&",[p.LESSGREAT]:"<>",[p.CLOBBER]:">|",[p.TLESS]:"<<<",[p.AND_GREAT]:"&>",[p.AND_DGREAT]:"&>>",[p.DLESS]:"<",[p.DLESSDASH]:"<"}[t]||">"}function Ce(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:en.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return tn.has(s.type)}return Yt.has(r)}function Oe(e){let t=null,r;e.check(p.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(p.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=cn(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return zr(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function zr(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function fn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||Ce(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push(Gr(e)):a.push(Oe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(p.DBRACK_START)||e.check(p.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),Ce(e))a.push(Oe(e));else if(e.check(p.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(p.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(p.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(p.LPAREN);let h=et(e);e.expect(p.RPAREN);let d=h.map(g=>Ye(e,g)),m=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(p.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Gr(e){let t=e.expect(p.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,h=i+1;for(;i2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(p.DPAREN_END),i[0].trim()&&(s=q(e,i[0].trim())),i[1].trim()&&(n=q(e,i[1].trim())),i[2].trim()&&(a=q(e,i[2].trim())),e.skipNewlines(),e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(p.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(p.RBRACE)):(e.expect(p.DO),u=e.parseCompoundList(),e.expect(p.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:u,redirections:c,line:r}}function rt(e,t){e.expect(p.WHILE);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function st(e,t){e.expect(p.UNTIL);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function it(e,t){e.expect(p.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(p.IN),e.skipNewlines();let s=[];for(;!e.check(p.ESAC,p.EOF);){e.checkIterationLimit();let a=e.getPos(),i=Hr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function Hr(e){e.check(p.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(p.PIPE));)e.advance();if(t.length===0)return null;e.expect(p.RPAREN),e.skipNewlines();let r=[];for(;!e.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND,p.ESAC,p.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===p.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(p.LPAREN)&&e.peek(1).type===p.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(p.DSEMI)?(e.advance(),s=";;"):e.check(p.SEMI_AND)?(e.advance(),s=";&"):e.check(p.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function at(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function ot(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Kr=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Xr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function hn(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function pn(e){if(e.check(p.BANG)&&e.peek(1).type===p.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(p.EOF);)if(e.check(p.LPAREN))t++,r+="(",e.advance();else if(e.check(p.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(p.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function ct(e){return e.skipNewlines(),Jr(e)}function Jr(e){let t=dn(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=dn(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function dn(e){let t=lt(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=lt(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function lt(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:lt(e)}):Yr(e)}function Yr(e){if(e.check(p.LPAREN)){e.advance();let t=ct(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(hn(e)){let t=e.current(),r=t.value;if(Kr.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),hn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&Xr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=es(e):n==="=="||n==="!="?a=pn(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(p.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(p.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=pn(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function es(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(p.DBRACK_END)||e.check(p.AND_AND)||e.check(p.OR_OR)||e.check(p.NEWLINE)||e.check(p.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(p.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(p.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(p.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(p.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(p.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(p.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(p.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(p.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(p.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(p.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(p.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(p.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(p.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(p.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(p.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(p.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(p.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(p.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(p.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ne(e){return e.length>0?e:[w.literal("")]}function ns(e,t){let r=1,s=t+1;for(;s0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+10;)t[h]==="{"?f++:t[h]==="}"&&f--,f>0&&h++;let d=t.slice(r+2,h);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:h+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let c=1,f=n;for(;f0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new U("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:f+1}}let u=null;if(a){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n=t.length)throw new U("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,u),endIndex:n+1}}function ut(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=ge(e,t,a),S=t.slice(a,A),y=ue(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(Ne(y));if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let u=ge(e,t,a),c=t.slice(a,u),f=-1,h=0,d=0;for(let E=0;E0)d--;else{f=E;break}}let m=f>=0?c.slice(0,f):c,g=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Je(e,m),length:g!==null?Je(e,g):null},endIndex:u}}if("-=?+".includes(i)){a++;let o=ge(e,t,a),u=t.slice(a,o),c=ue(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(Ne(c));if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,u=i==="#"?"prefix":"suffix";a+=o?2:1;let c=ge(e,t,a),f=t.slice(a,c),h=ue(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(Ne(h)),side:u,greedy:o},endIndex:c}}if(i==="/"){let o=l==="/";a+=o?2:1;let u=null;t[a]==="#"?(u="start",a++):t[a]==="%"&&(u="end",a++);let c;u!==null&&(t[a]==="/"||t[a]==="}")?c=a:c=sn(e,t,a);let f=t.slice(a,c),h=ue(e,f,!1,!1,!1),d=w.word(Ne(h)),m=null,g=c;if(t[c]==="/"){let E=c+1,A=ge(e,t,E),S=t.slice(E,A),y=ue(e,S,!1,!1,!1);m=w.word(Ne(y)),g=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:m,all:o,anchor:u},endIndex:g}}if(i==="^"||i===","){let o=l===i,u=i==="^"?"upper":"lower";a+=o?2:1;let c=ge(e,t,a),f=t.slice(a,c),h=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:h},endIndex:c}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function ft(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),u=q(e,o);return{part:w.arithmeticExpansion(u),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?ss(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?rs(e,t,r):{part:w.literal("$"),endIndex:n}}function mn(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s{a&&(s.push(w.literal(a)),a="")};for(;n=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),g=!1;for(let E=0;E{h&&(c.push(w.literal(h)),h="")};for(;f0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let A=rn(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;c.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(m)&&f+1Jt)throw new U("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ke)throw new U(`Maximum parser nesting depth exceeded (${Ke})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,r){if(t.length>He)throw new U(`Input too large: ${t.length} bytes exceeds limit of ${He}`,1,1);this._input=t;let s=new $e(t,r);if(this.tokens=s.tokenize(),this.tokens.length>je)throw new U(`Too many tokens: ${this.tokens.length} exceeds limit of ${je}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new U(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new U(t,r.line,r.column,r)}skipNewlines(){for(;this.check(p.NEWLINE,p.COMMENT);)this.check(p.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(p.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(p.SEMICOLON,p.COMMENT)){this.advance();continue}if(t&&this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(p.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(p.EOF,p.NEWLINE,p.SEMICOLON,p.AMP,p.AND_AND,p.OR_OR,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.ASSIGNMENT_WORD||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.LPAREN||t===p.LBRACE||t===p.DPAREN_START||t===p.DBRACK_START||t===p.FUNCTION||t===p.BANG||t===p.TIME||t===p.IN||t===p.LESS||t===p.GREAT||t===p.DLESS||t===p.DGREAT||t===p.LESSAND||t===p.GREATAND||t===p.LESSGREAT||t===p.DLESSDASH||t===p.CLOBBER||t===p.TLESS||t===p.AND_GREAT||t===p.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(p.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(p.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===p.DO||t===p.DONE||t===p.THEN||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.RBRACE||t===p.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===p.DSEMI||t===p.SEMI_AND||t===p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===p.PIPE||t===p.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(p.AND_AND,p.OR_OR);){let o=this.advance();s.push(o.type===p.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();r.push(u)}this.check(p.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(p.TIME)&&(this.advance(),t=!0,this.check(p.WORD,p.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(p.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(p.PIPE,p.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===p.PIPE_AMP);let u=this.parseCommand();a.push(u)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?tt(this):this.check(p.FOR)?nt(this):this.check(p.WHILE)?rt(this):this.check(p.UNTIL)?st(this):this.check(p.CASE)?it(this):this.check(p.LPAREN)?at(this):this.check(p.LBRACE)?ot(this):this.check(p.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(p.DBRACK_START)?this.parseConditionalCommand():this.check(p.FUNCTION)?this.parseFunctionDef():this.check(p.NAME,p.WORD)&&this.peek(1).type===p.LPAREN&&this.peek(2).type===p.RPAREN?this.parseFunctionDef():fn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;rnew e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return Ut(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return Qt(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(p.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(p.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(p.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(p.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(p.DPAREN_START))s++,r+="((",this.advance();else if(this.check(p.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(p.LPAREN))n++,r+="(",this.advance();else if(this.check(p.RPAREN))n>0&&n--,r+=")",this.advance();else{let u=this.current().value,c=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(r+=" "),r+=u,this.advance()}}i||this.expect(p.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=ct(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(p.FUNCTION)){if(this.advance(),this.check(p.NAME)||this.check(p.WORD))t=this.advance().value;else{let n=this.current();throw new U("Expected function name",n.line,n.column,n)}this.check(p.LPAREN)&&(this.advance(),this.expect(p.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(p.LPAREN),this.expect(p.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return ot(this,{skipRedirections:r});if(this.check(p.LPAREN))return at(this,{skipRedirections:r});if(this.check(p.IF))return tt(this,{skipRedirections:r});if(this.check(p.FOR))return nt(this,{skipRedirections:r});if(this.check(p.WHILE))return rt(this,{skipRedirections:r});if(this.check(p.UNTIL))return st(this,{skipRedirections:r});if(this.check(p.CASE))return it(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(p.EOF,p.FI,p.ELSE,p.ELIF,p.THEN,p.DO,p.DONE,p.ESAC,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;Ce(this);){this.checkIterationLimit();let r=this.pos;if(t.push(Oe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return q(this,t)}};function Ni(e,t){return new B().parse(e,t)}var os=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function ht(e){return os.get(e)??""}function gn(e){let t=[],r="",s=0;for(;s0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function dt(e){let t=[],r="",s=0,n=!1,a=0;for(;athis.maxOps)throw new W(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return yn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i0?a.push(...l):a.push(t[i])}return a}async expand(t){if(this.globstar){let s=t.split("/"),n=0;for(let a of s)if(a==="**"&&(n++,n>En))throw new W(`Glob pattern has too many ** segments (max ${En})`,"glob_operations")}let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;um.name==="."),d=l.some(m=>m.name==="..");h||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let h of u)if(!(h.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(h.name,n)){let d=t==="/"?`/${h.name}`:`${t}/${h.name}`,m;r===""?m=h.name:r==="/"?m=`/${h.name}`:m=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([m])):h.isDirectory&&o.push(this.expandSegments(d,m,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let h of u)if(!(h.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(h,n)){let d=t==="/"?`/${h}`:`${t}/${h}`,m;r===""?m=h:r==="/"?m=`/${h}`:m=`${r}/${h}`,a.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,m,a)}catch(g){if(g instanceof W)throw g}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch(l){if(l instanceof W)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let u of a){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&i.push(c)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let u=0;uthis.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let c of i){let f=t==="."?c:`${t}/${c}`,h=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory&&l.push(f)}catch(d){if(d instanceof W)throw d}}let o=t==="."?r:`${t}/${r}`,u=await this.expandRecursive(o);s.push(...u);for(let c=0;cthis.walkDirectoryMultiGlobstar(h,r,s)))}}}catch(a){if(a instanceof W)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):r&&this.matchPattern(o.name,r)&&i.push(u)}s.push(...i);for(let o=0;othis.walkDirectory(c,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o{let h=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,h);try{this.checkOpsLimit();let m=await this.fs.stat(d);return{name:f,path:h,isDirectory:m.isDirectory}}catch(m){if(m instanceof W)throw m;return null}}));i.push(...c.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;othis.walkDirectory(c.path,r,s)))}}}catch(a){if(a instanceof W)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;nthis.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(a==="@")r+=`(?:${c})`;else if(a==="*")r+=`(?:${c})*`;else if(a==="+")r+=`(?:${c})+`;else if(a==="?")r+=`(?:${c})?`;else if(a==="!")if(ithis.computePatternLength(m));if(h.every(m=>m!==null)&&h.every(m=>m===h[0])&&h[0]!==null){let m=h[0];if(m===0)r+="(?:.+)";else{let g=[];m>0&&g.push(`.{0,${m-1}}`),g.push(`.{${m+1},}`),g.push(`(?!(?:${c})).{${m}}`),r+=`(?:${g.join("|")})`}}else r+=`(?:(?!(?:${c})).)*?`}else r+=`(?!(?:${c})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";ithis.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){r+=u[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function ls(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new $("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new $("division by 0");return e%t;case"**":if(t<0)throw new $("exponent less than 0");return e**t;case"<<":return e<>":return e>>t;case"<":return e":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function An(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function cs(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function us(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await D(e,t)}function fs(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new B,{expr:n,pos:a}=j(s,r,0);if(a100)throw new $("maximum variable indirection depth exceeded");if(r.has(t))return 0;r.add(t);let n=await us(e,t);if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n.trim()))return a;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await gt(e,i,r,s+1);let l=new B,{expr:o,pos:u}=j(l,i,0);if(u0&&(s===-1||h64)return 0;let a=`${n}#${t.value}`;return be(a)}case"ArithDynamicNumber":{let n=await Le(e,t.prefix)+t.suffix;return be(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await mt(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await D(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript -`,0;let f=Math.max(...o.map(([h])=>typeof h=="number"?h:0))+1+a;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript -`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return mt(e,l);if(a===0){let o=e.state.env.get(t.array);if(o!==void 0)return mt(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new J(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new $("double subscript","","");case"ArithNumberSubscript":throw new $(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new $(t.message,"","",!0);case"ArithSingleQuote":{if(r)throw new $(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await R(e,t.left,r)||await R(e,t.right,r)?1:0;if(t.operator==="&&")return await R(e,t.left,r)&&await R(e,t.right,r)?1:0;let s=await R(e,t.left,r),n=await R(e,t.right,r);return ls(s,n,t.operator)}case"ArithUnary":{let s=await R(e,t.operand,r);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,a=Number.parseInt(await D(e,n),10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,a=e.state.associativeArrays?.has(n),i;if(t.operand.stringKey!==void 0)i=`${n}_${t.operand.stringKey}`;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)i=`${n}_${t.operand.index.name}`;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await D(e,t.operand.index.name);i=`${n}_${u}`}else if(t.operand.index){let u=await R(e,t.operand.index,r);i=`${n}_${u}`}else return s;let l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let a of t.operand.parts)n+=await Ae(e,a,r);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)n+=await Ae(e,a,r);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await D(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=await R(e,t.operand.subscript,r),i=`${n}_${a}`,l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}}return s}return cs(s,t.operator)}case"ArithTernary":return await R(e,t.condition,r)?await R(e,t.consequent,r):await R(e,t.alternate,r);case"ArithAssignment":{let s=t.variable,n=s;if(t.stringKey!==void 0)n=`${s}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(s);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${s}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await D(e,t.subscript.name);n=`${s}_${u||"\\"}`}else if(o){let u=await R(e,t.subscript,r);n=`${s}_${u}`}else{let u=await R(e,t.subscript,r);if(u<0){let c=P(e,s);c.length>0&&(u=Math.max(...c.map(([h])=>typeof h=="number"?h:0))+1+u)}n=`${s}_${u}`}}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=An(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await R(e,t.expression,r);case"ArithConcat":{let s="";for(let n of t.parts)s+=await Ae(e,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)?await gt(e,s):Number.parseInt(s,10)||0}case"ArithDynamicAssignment":{let s="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)s+=await Ae(e,o,r);else t.target.type==="ArithVariable"&&(s=t.target.hasDollarPrefix?await D(e,t.target.name):t.target.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=s;if(t.subscript){let o=await R(e,t.subscript,r);n=`${s}_${o}`}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=An(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let s="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)s+=await Ae(e,l,r);else t.nameExpr.type==="ArithVariable"&&(s=t.nameExpr.hasDollarPrefix?await D(e,t.nameExpr.name):t.nameExpr.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=await R(e,t.subscript,r),a=`${s}_${n}`,i=e.state.env.get(a);return i!==void 0?fs(i):0}default:return 0}}async function Ae(e,t,r=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await R(e,t,r));case"ArithVariable":return t.hasDollarPrefix?await D(e,t.name):t.name;case"ArithSpecialVar":return await D(e,t.name);case"ArithBracedExpansion":return await Le(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let n of t.parts)s+=await Ae(e,n,r);return s}default:return String(await R(e,t,r))}}function yt(e){for(let t=0;tn-a)}function Fi(e,t){let r=`${t}_`;for(let s of e.state.env.keys())s.startsWith(r)&&e.state.env.delete(s)}function At(e,t){let r=`${t}_`,s=`${t}__length`,n=[];for(let a of e.state.env.keys())if(a!==s&&a.startsWith(r)){let i=a.slice(r.length);if(i.startsWith("_length"))continue;n.push(i)}return n.sort()}function We(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function zi(e){if(e.parts.length<2)return null;let t=e.parts[0],r=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let s,n=r,a=1;if(r.type==="Literal"&&r.value.startsWith("]")){let f=r.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))s=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let h=e.parts[2];if(h.type!=="Literal"||!h.value.startsWith("=")&&!h.value.startsWith("+="))return null;s=t.pattern.slice(1),n=h,a=2}else return null}else if(t.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(r.type==="SingleQuoted")s=r.value;else{s="";for(let h of r.parts)(h.type==="Literal"||h.type==="Escaped")&&(s+=h.value)}n=f,a=2}else if(t.pattern.endsWith("]")){if(r.type!=="Literal"||!r.value.startsWith("=")&&!r.value.startsWith("+="))return null;s=t.pattern.slice(1,-1)}else return null;s=We(s);let i;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?i=n.value.slice(1):i=n.value;let l=i.startsWith("+=");if(!l&&!i.startsWith("="))return null;let o=[],u=l?2:1,c=i.slice(u);c&&o.push({type:"Literal",value:c});for(let f=a+1;f{if(r.type==="Range"){let s=r.startStr??String(r.start),n=r.endStr??String(r.end),a=`${s}..${n}`;return r.step&&(a+=`..${r.step}`),a}return wn(r.word)}).join(",")}}`}function wn(e){let t="";for(let r of e.parts)switch(r.type){case"Literal":t+=r.value;break;case"Glob":t+=r.pattern;break;case"SingleQuoted":t+=r.value;break;case"DoubleQuoted":for(let s of r.parts)(s.type==="Literal"||s.type==="Escaped")&&(t+=s.value);break;case"Escaped":t+=r.value;break;case"BraceExpansion":t+="{",t+=r.items.map(s=>s.type==="Range"?`${s.startStr}..${s.endStr}${s.step?`..${s.step}`:""}`:wn(s.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",r.user&&(t+=r.user);break}return t}function M(e){return e.get("IFS")??` -`}function F(e){return e.get("IFS")===""}function Te(e){let t=M(e);if(t==="")return!0;for(let r of t)if(r!==" "&&r!==" "&&r!==` -`)return!1;return!0}function Nn(e){let t=!1,r=[];for(let s of e.split(""))s==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(s)?r.push(`\\${s}`):s===" "?r.push("\\t"):s===` -`?r.push("\\n"):r.push(s);return t&&r.push("\\-"),r.join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var ds=` -`;function ms(e){return ds.includes(e)}function St(e){let t=new Set,r=new Set;for(let s of e)ms(s)?t.add(s):r.add(s);return{whitespace:t,nonWhitespace:r}}function Qi(e,t,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:a}=St(t),i=[],l=[],o=0;for(;o=e.length)return{words:[],wordStarts:[]};if(a.has(e[o]))for(i.push(""),l.push(o),o++;o=r);){let u=o;for(l.push(u);o=e.length)break;for(;o=r);)for(i.push(""),l.push(o),o++;oo&&(i=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(n.push(""),a++;a=e.length){l=!1;break}let c=a;for(;a=e.length&&a>c&&(l=!0)}return{words:n,hadLeadingDelimiter:i,hadTrailingDelimiter:l}}function v(e,t){return Me(e,t).words}function gs(e,t){for(let r of e)if(t.has(r))return!0;return!1}function Zi(e,t,r){if(t==="")return e;let{whitespace:s,nonWhitespace:n}=St(t),a=e.length;for(;a>0&&s.has(e[a-1]);){if(!r&&a>=2){let l=0,o=a-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}a--}let i=e.substring(0,a);if(i.length>=1&&n.has(i[i.length-1])){if(!r&&i.length>=2){let o=0,u=i.length-2;for(;u>=0&&i[u]==="\\";)o++,u--;if(o%2===1)return i}let l=i.substring(0,i.length-1);if(!gs(l,n))return l}return i}function T(e,t){return e.state.namerefs?.has(t)??!1}function Hi(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function ji(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Ki(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function kn(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Xi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ys(e,t){let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],a=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),i=e.state.associativeArrays?.has(n)??!1;return a||i}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function ye(e,t,r=100){if(!T(e,t)||kn(e,t))return t;let s=new Set,n=t;for(;r-- >0;){if(s.has(n))return;if(s.add(n),!T(e,n))return n;let a=e.state.env.get(n);if(a===void 0||a===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return n;n=a}}function Pe(e,t){if(T(e,t))return e.state.env.get(t)}function Ji(e,t,r,s=100){if(!T(e,t)||kn(e,t))return t;let n=new Set,a=t;for(;s-- >0;){if(n.has(a))return;if(n.add(a),!T(e,a))return a;let i=e.state.env.get(a);if(i===void 0||i==="")return r!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ys(e,r)?a:null:a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return a;a=i}}function Es(e,t){let r=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(s,n)=>e.state.env.get(n)??"");return r=r.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(s,n)=>e.state.env.get(n)??""),r}function P(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((a,i)=>[i,a]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((a,i)=>[i,String(a)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((a,i)=>[i,a]):e.state.associativeArrays?.has(t)?At(e,t).map(a=>[a,e.state.env.get(`${t}_${a}`)??""]):Et(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function Re(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?At(e,t).length>0:Et(e,t).length>0}async function D(e,t,r=!0,s=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let l=[];for(let o=1;o<=i;o++)l.push(e.state.env.get(String(o))||"");return l.join(N(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return bn;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new J("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(r&&e.state.options.nounset)throw new J("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new J("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new ae(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let i=n[1],l=n[2];if(T(e,i)){let f=ye(e,i);if(f&&f!==i){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=f}}if(l==="@"||l==="*"){let f=P(e,i);if(f.length>0)return f.map(([,d])=>d).join(" ");let h=e.state.env.get(i);return h!==void 0?h:""}if(i==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(i==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let h=e.state.callLineStack?.[f];return h!==void 0?String(h):""}return""}if(i==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(i)){let f=We(l);f=Es(e,f);let h=e.state.env.get(`${i}_${f}`);if(h===void 0&&r&&e.state.options.nounset)throw new J(`${i}[${l}]`);return h||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new B,h=q(f,l);u=await R(e,h.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=P(e,i),h=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript -`,"";let m=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+u;return m<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript -`,""):e.state.env.get(`${i}_${m}`)||""}let c=e.state.env.get(`${i}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new J(`${i}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new J(t);return i||""}if(T(e,t)){let i=ye(e,t);if(i===void 0)return"";if(i!==t)return await D(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new J(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(Re(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new J(t);return""}async function re(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(T(e,n)){let o=ye(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=We(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new B,u=q(o,a);l=await R(e,u.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(T(e,t)){let n=ye(e,t);return n===void 0||n===t?e.state.env.has(t):re(e,n)}return!!(e.state.env.has(t)||Re(e,t))}async function Pn(e,t){let r="",s=0;for(;s0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let u=r.slice(i+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let u=r.slice(i+2,o-1),c=await D(e,u);a+=c,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l{if(o>0){let f=c<0,h=String(Math.abs(c)).padStart(o,"0");return f?`-${h}`:h}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f=t&&f="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let h=r!==void 0?`..${r}`:"";throw new _t(`{${e}..${t}${h}}: invalid sequence`)}let f=[];if(n<=a)for(let h=n,d=0;h<=a&&d=a&&dk(f,t,r)),c=u.length>0?u.join("|"):"(?:)";a==="@"?s+=`(?:${c})`:a==="*"?s+=`(?:${c})*`:a==="+"?s+=`(?:${c})+`:a==="?"?s+=`(?:${c})?`:a==="!"&&(s+=`(?!(?:${c})$).*`),n=i+1;continue}}if(a==="\\")if(n+10;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ws(e){let t=[],r="",s=0,n=0;for(;n0&&r=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function Se(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&a.add(u[1])}let i=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function Is(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function Ie(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,h=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=` -`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=u,s+=2;break;case"W":r+=c,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${h[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+20&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!r){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.lengtha.startsWith(`${t}_`)&&/^[0-9]+$/.test(a.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return s&&!n&&(r+="a"),n&&(r+="A"),e.state.integerVars?.has(t)&&(r+="i"),T(e,t)&&(r+="n"),Pt(e,t)&&(r+="r"),e.state.exportedVars?.has(t)&&(r+="x"),r}async function In(e,t,r,s){return e.coverage?.hit("bash:expansion:default_value"),(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):r.effectiveValue}async function Dn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:assign_default"),(s.isUnset||r.checkEmpty&&s.isEmpty)&&r.word){let i=await n(e,r.word.parts,s.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let h=new B,d=q(h,u);c=await R(e,d.expression)}catch{let h=e.state.env.get(u);c=h?Number.parseInt(h,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,i);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,i);return i}return s.effectiveValue}async function xn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),s.isUnset||r.checkEmpty&&s.isEmpty){let i=r.word?await n(e,r.word.parts,s.inDoubleQuotes):`${t}: parameter null or not set`;throw new Y(1,"",`bash: ${i} -`)}return s.effectiveValue}async function vn(e,t,r,s){return e.coverage?.hit("bash:expansion:use_alternative"),!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function _n(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_removal");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let o of r.pattern.parts)if(o.type==="Glob")a+=k(o.pattern,r.greedy,i);else if(o.type==="Literal")a+=k(o.value,r.greedy,i);else if(o.type==="SingleQuoted"||o.type==="Escaped")a+=I(o.value);else if(o.type==="DoubleQuoted"){let u=await s(e,o.parts);a+=I(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);a+=k(u,r.greedy,i)}else{let u=await n(e,o);a+=I(u)}if(r.side==="prefix")return O(`^${a}`,"s").replace(t,"");let l=O(`${a}$`,"s");if(r.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function $n(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_replacement");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let u of r.pattern.parts)if(u.type==="Glob")a+=k(u.pattern,!0,i);else if(u.type==="Literal")a+=k(u.value,!0,i);else if(u.type==="SingleQuoted"||u.type==="Escaped")a+=I(u.value);else if(u.type==="DoubleQuoted"){let c=await s(e,u.parts);a+=I(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);a+=k(c,!0,i)}else{let c=await n(e,u);a+=I(c)}let l=r.replacement?await s(e,r.replacement.parts):"";if(r.anchor==="start"?a=`^${a}`:r.anchor==="end"&&(a=`${a}$`),a==="")return t;let o=r.all?"gs":"s";try{let u=O(a,o);if(r.all){let c="",f=0,h=0,d=e.limits.maxStringLength,m=u.exec(t);for(;m!==null&&!(m[0].length===0&&m.index===t.length);){if(c+=t.slice(f,m.index)+l,f=m.index+m[0].length,m[0].length===0&&f++,h++,h%100===0&&c.length>d)throw new W(`pattern replacement: string length limit exceeded (${d} bytes)`,"string_length");m=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof W)throw u;return t}}function Cn(e,t,r){e.coverage?.hit("bash:expansion:length");let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(s){let n=s[1],a=P(e,n);return a.length>0?String(a.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&Re(e,t)){if(t==="FUNCNAME"){let a=e.state.funcNameStack?.[0]||"";return String([...a].length)}if(t==="BASH_LINENO"){let a=e.state.callLineStack?.[0];return String(a!==void 0?[...String(a)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...r].length)}async function On(e,t,r,s){e.coverage?.hit("bash:expansion:substring");let n=await R(e,s.offset.expression),a=s.length?await R(e,s.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let m=1;m<=u;m++)c.push(e.state.env.get(String(m))||"");let f=e.state.env.get("0")||"bash",h,d;if(n<=0)if(h=[f,...c],n<0){if(d=h.length+n,d<0)return""}else d=0;else h=c,d=n-1;if(d<0||d>=h.length)return"";if(a!==void 0){let m=a<0?h.length+a:d+a;return h.slice(d,Math.max(d,m)).join(" ")}return h.slice(d).join(" ")}let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i){let u=i[1];if(e.state.associativeArrays?.has(u))throw new Y(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution -`);let c=P(e,u),f=0;if(n<0){if(c.length>0){let h=c[c.length-1][0],m=(typeof h=="number"?h:0)+1+n;if(m<0||(f=c.findIndex(([g])=>typeof g=="number"&&g>=m),f<0))return""}}else if(f=c.findIndex(([h])=>typeof h=="number"&&h>=n),f<0)return"";if(a!==void 0){if(a<0)throw new $(`${i[1]}[@]: substring expression < 0`);return c.slice(f,f+a).map(([,h])=>h).join(" ")}return c.slice(f).map(([,h])=>h).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let u=l.length+a;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function Ln(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:case_modification"),r.pattern){let a=e.state.shoptOptions.extglob,i="";for(let f of r.pattern.parts)if(f.type==="Glob")i+=k(f.pattern,!0,a);else if(f.type==="Literal")i+=k(f.value,!0,a);else if(f.type==="SingleQuoted"||f.type==="Escaped")i+=I(f.value);else if(f.type==="DoubleQuoted"){let h=await s(e,f.parts);i+=I(h)}else if(f.type==="ParameterExpansion"){let h=await n(e,f);i+=k(h,!0,a)}let l=O(`^(?:${i})$`),o=r.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!r.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return r.direction==="upper"?r.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):r.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Wn(e,t,r,s,n){e.coverage?.hit("bash:expansion:transform");let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,u])=>he(u)).join(" ");if(a&&n.operator==="a")return pe(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return pe(e,i[1]);switch(n.operator){case"Q":return s?"":he(r);case"P":return Ie(e,r);case"a":return pe(e,t);case"A":return s?"":`${t}=${he(r)}`;case"E":return r.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return` -`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":he(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function Tn(e,t,r,s,n,a,i=!1){if(e.coverage?.hit("bash:expansion:indirection"),T(e,t))return Pe(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new ae(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new ae(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new ae(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,c,i)}return await D(e,o)}function Mn(e,t){e.coverage?.hit("bash:expansion:array_keys");let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function Vn(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let r=Se(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function qn(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=N(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:s?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Bn(e){let t=0;for(;t0;){let i=e[s];if(i==="\\"&&!n&&s+1E);if(c.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";u.pattern&&(h=await vs(e,u.pattern,r,s));let d=u.replacement?await r(e,u.replacement.parts):"",m=h;u.anchor==="start"?m=`^${h}`:u.anchor==="end"&&(m=`${h}$`);let g=[];try{let E=O(m,u.all?"g":"");for(let A of f)g.push(E.replace(A,d))}catch{g.push(...f)}if(o){let E=N(e.state.env);return{values:[g.join(E)],quoted:!0}}return{values:g,quoted:!0}}async function Zn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,g])=>g);if(c.length===0){let g=e.state.env.get(l);g!==void 0&&f.push(g)}if(f.length===0)return{values:[],quoted:!0};let h="",d=e.state.shoptOptions.extglob;if(u.pattern)for(let g of u.pattern.parts)if(g.type==="Glob")h+=k(g.pattern,u.greedy,d);else if(g.type==="Literal")h+=k(g.value,u.greedy,d);else if(g.type==="SingleQuoted"||g.type==="Escaped")h+=I(g.value);else if(g.type==="DoubleQuoted"){let E=await r(e,g.parts);h+=I(E)}else if(g.type==="ParameterExpansion"){let E=await s(e,g);h+=k(E,u.greedy,d)}else{let E=await s(e,g);h+=I(E)}let m=[];for(let g of f)m.push(oe(g,h,u.side,u.greedy));if(o){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}async function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let u=P(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,d])=>d===""),h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(h&&f):i=!c||h&&f,!i){if(u.length>0){let m=u.map(([,g])=>g);if(l){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,u=await re(e,o),c=await D(e,o),f=c==="",h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(h&&f):i=!u||h&&f,!i)return{values:[c],quoted:!0}}if(i&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let h=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(h){u=h[1],c=h[2]==="*";break}}if(u){let f=P(e,u);if(f.length>0){let d=f.map(([,m])=>m);if(c||l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function Hn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,u=null;for(let g=0;gg);if(h.length===0){let g=e.state.env.get(l);if(g!==void 0)d=[g];else{if(o)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let g=u,E="",A=e.state.shoptOptions.extglob;if(g.pattern)for(let S of g.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,g.greedy,A);else if(S.type==="Literal")E+=k(S.value,g.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,g.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>oe(S,E,g.side,g.greedy))}else if(u?.type==="PatternReplacement"){let g=u,E="";if(g.pattern)for(let y of g.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=g.replacement?await n(e,g.replacement.parts):"",S=E;g.anchor==="start"?S=`^${E}`:g.anchor==="end"&&(S=`${E}$`);try{let y=O(S,g.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let g=N(e.state.env);return{values:[c+d.join(g)+f],quoted:!0}}return d.length===1?{values:[c+d[0]+f],quoted:!0}:{values:[c+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function jn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;dd);if(c.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let m=o+u;return{values:m?[m]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Kn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new Y(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution -`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(u<0){if(f.length>0){let m=f[f.length-1][0],E=(typeof m=="number"?m:0)+1+u;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([m])=>typeof m=="number"&&m>=u),h<0&&(h=f.length);let d;if(c!==void 0){if(c<0)throw new $(`${i}[@]: substring expression < 0`);d=f.slice(h,h+c).map(([,m])=>m)}else d=f.slice(h).map(([,m])=>m);if(d.length===0)return{values:[],quoted:!0};if(l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}function Xn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=Ie(e,f);break;case"Q":h=he(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=pe(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>Ie(e,f));break;case"Q":c=o.map(([,f])=>he(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Jn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(T(e,a)){let o=Pe(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Yn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!T(e,n))return null;let a=Pe(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function er(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await D(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let m=Number.parseInt(e.state.env.get("#")||"0",10),g=[];for(let E=1;E<=m;E++)g.push(e.state.env.get(String(E))||"");return o==="*"?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}return null}let c=u[1],f=u[2]==="*",h=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return _s(e,h,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return $s(e,h,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let g=pe(e,c),E=h.map(()=>g);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let m=[];for(let[,g]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",g);try{let S=await s(e,E,!0);m.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}if(h.length>0){let m=h.map(([,g])=>g);return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function _s(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],h=(typeof c=="number"?c:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new $(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function $s(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function tr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await D(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await re(e,r.parameter),c=await D(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=u&&!(f&&c):h=!u||f&&c,h){let d=o[1],m=o[2]==="*",g=P(e,d);if(g.length>0){let A=g.map(([,S])=>S);return m?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function nr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await D(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await D(e,r.parameter),f=await re(e,r.parameter),h=c==="",d=n.checkEmpty??!1,m;if(n.type==="UseAlternative"?m=f&&!(d&&h):m=!f||d&&h,m){let g=u[1],E=u[2]==="*",A=P(e,g);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(g);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function rr(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function sr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S=h.length)m=[];else if(c!==void 0){let y=c<0?h.length+c:S+c;m=h.slice(S,Math.max(S,y))}else m=h.slice(S)}let g="";for(let S=0;S0)s.push(...a);else{if(r.hasFailglob())throw new xe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function lr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;SS);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let m=[];try{let S=O(d,o.all?"g":"");for(let y of c)m.push(S.replace(y,h))}catch{m.push(...c)}let g=M(e.state.env),E=F(e.state.env);if(i){let S=N(e.state.env),y=m.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:v(y,g),quoted:!1}}if(E)return{values:m,quoted:!1};let A=[];for(let S of m)S===""?A.push(""):A.push(...v(S,g));return{values:A,quoted:!1}}async function cr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;AA);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(oe(A,f,o.side,o.greedy));let m=M(e.state.env),g=F(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return g?{values:S?[S]:[],quoted:!1}:{values:v(S,m),quoted:!1}}if(g)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...v(A,m));return{values:E,quoted:!1}}async function ur(e,t,r,s){let n=-1,a=!1;for(let E=0;E=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let m="";for(let y=0;yu!=="");else{let u=N(e.state.env),c=n.join(u);o=v(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=v(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=v(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Be(e,o),quoted:!1}}async function pr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=M(e.state.env),o=F(e.state.env),u=Te(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);c=v(h,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let h=v(f,l);c.push(...h)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let h=v(f,l);c.push(...h)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Be(e,c),quoted:!1}}function dr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=Se(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=M(e.state.env),a=F(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=v(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=v(l,n);i.push(...o)}}return{values:i,quoted:!1}}function mr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=M(e.state.env),i=F(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=v(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=v(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function gr(e,t,r){let s=-1;for(let h=0;hd!=="");else if(c){f=[];for(let d of h){if(d==="")continue;let m=v(d,o);f.push(...m)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let m=v(d,o);f.push(...m)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Be(e,f),quoted:!1}}async function Ar(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ke(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Os(e,h,n);let d=await Ls(e,s,l,u,c,r);if(d!==null)return d;let m=await Ts(e,s,r);if(m!==null)return m;let g=await Ms(e,s,r);if(g!==null)return g;let E=await qs(e,s,r.expandPart);if(E!==null)return Er(e,E);if((a||i||o)&&!F(e.state.env)){let S=M(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return Er(e,b)}let A=await r.expandWordAsync(e,t);return Bs(e,t,s,A,n,r.expandWordForGlobbing)}async function Os(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&se(n,e.state.shoptOptions.extglob)){let a=await Fe(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Ls(e,t,r,s,n,a){if(r){let i=Jn(e,t);if(i!==null)return i}{let i=Yn(e,t);if(i!==null)return i}{let i=await Un(e,t);if(i!==null)return i}{let i=await Hn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await jn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Kn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Xn(e,t);if(i!==null)return i}{let i=await Qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Ws(e,t);if(i!==null)return i}{let i=await er(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await tr(e,t);if(i!==null)return i}{let i=await nr(e,t);if(i!==null)return i}return null}function Ws(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=Se(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function Ts(e,t,r){{let s=await sr(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await ar(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await or(e,t,r.expandPart);if(s!==null)return s}return null}async function Ms(e,t,r){{let s=await lr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await cr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ur(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await fr(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await hr(e,t);if(s!==null)return s}{let s=await pr(e,t);if(s!==null)return s}{let s=dr(e,t);if(s!==null)return s}{let s=mr(e,t);if(s!==null)return s}{let s=await gr(e,t,r.expandPart);if(s!==null)return s}return null}function yr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;to),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function qs(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(yr(o)){s=!0;break}if(!s)return null;let n=M(e.state.env),a=F(e.state.env),i=[];for(let o of t){let u=yr(o);if(u&&o.type==="DoubleQuoted"){let c=await Vs(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=v(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=v(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c0)return s;if(r.hasFailglob())throw new xe(t);return r.hasNullglob()?[]:[t]}async function Bs(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(se(l,e.state.shoptOptions.extglob)){let u=await Fe(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=Nt(s);if(!F(e.state.env)){let u=M(e.state.env);return{values:v(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&se(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(se(l,e.state.shoptOptions.extglob)){let o=await Fe(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=Nt(s);if(!F(e.state.env)){let o=M(e.state.env);return{values:v(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function br(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await re(e,t.parameter),i=await D(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Fs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function zs(e,t){if(t.type!=="ParameterExpansion")return null;let r=await br(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Fs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Gs(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?yt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Sn(e))}async function wr(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await br(e,h);if(d&&d.length>0&&d.length>1&&d.some(g=>g.type==="DoubleQuoted"||g.type==="SingleQuoted")&&d.some(g=>g.type==="Literal"||g.type==="ParameterExpansion"||g.type==="CommandSubstitution"||g.type==="ArithmeticExpansion"))return Sr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Gs(h),m=h.type==="DoubleQuoted"||h.type==="SingleQuoted",g=d?await zs(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:m,mixedDefaultParts:g??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let h of a)if(!h.isSplittable)c?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,c=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await Sr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let m=1;m0&&t.includes(e[0])}async function Sr(e,t,r,s,n){let a=[];for(let c of t){let h=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Qs(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Me(c.value,r);if(h.length===0)d&&(u=!0);else if(h.length===1)l+=h[0],o=!0,u=d;else{l+=h[0],i.push(l),o=!0;for(let m=1;mt)throw new W(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function te(e,t,r=!1){let s=[];for(let n of t)s.push(await K(e,n,r));return s.join("")}function Zs(e){return kr(e)}function Dl(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Zs(t))return!1;return!0}function Us(e,t,r=!1){let s=Nr(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Rt(e,t.pattern);default:return null}}async function Dt(e,t){return xt(e,t)}async function xl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await K(e,s);r.push(kt(n))}else r.push(await K(e,s));return r.join("")}async function vl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(ee(s.value));else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(ee(n))}else r.push(await K(e,s));return r.join("")}async function Pr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(ee(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(ee(n))}else s.type==="Glob"?Bn(s.pattern)?r.push(await zn(e,s.pattern)):r.push(Rt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await K(e,s));return r.join("")}function Ge(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Ge(t.parts))return!0;return!1}var It=1e5;async function Rr(e,t,r={count:0}){if(r.count>It)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=wt(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await Rr(e,c.word.parts,r);for(let h of f){r.count++;let d=[];for(let m of h)typeof m=="string"?d.push(m):d.push(await K(e,m));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>e.limits.maxBraceExpansionResults||r.count>It)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>It)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function Ir(e,t){let r=t.parts;if(!Ge(r))return[await Dt(e,t)];let s=await Rr(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await K(e,l));n.push(Gn(e,i.join("")))}return n}function Hs(){return{expandWordAsync:xt,expandWordForGlobbing:Pr,expandWordWithBracesAsync:Ir,expandWordPartsAsync:te,expandPart:K,expandParameterAsync:ze,hasBraceExpansion:Ge,evaluateArithmetic:R,buildIfsCharClassPattern:Nn,smartWordSplit:wr}}async function _l(e,t){return Ar(e,t,Hs())}function js(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ks(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function $l(e,t){if(Ks(e,t))return{error:`bash: $@: ambiguous redirect -`};let r=t.parts,{hasQuoted:s}=ke(r);if(Ge(r)&&(await Ir(e,t)).length>1)return{error:`bash: ${r.map(d=>d.type==="Literal"?d.value:d.type==="BraceExpansion"?`{${d.items.map(g=>{if(g.type==="Range"){let E=g.step?`..${g.step}`:"";return`${g.startStr??g.start}..${g.endStr??g.end}${E}`}return g.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect -`};let n=await xt(e,t),{hasParamExpansion:a,hasCommandSub:i}=ke(r);if((a||i)&&!s&&!F(e.state.env)){let f=M(e.state.env);if(v(n,f).length>1)return{error:`bash: $${js(r)}: ambiguous redirect -`}}if(s||e.state.options.noglob)return{target:n};let o=await Pr(e,t);if(!se(o,e.state.shoptOptions.extglob))return{target:n};let u=new fe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n} -`}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect -`}}async function xt(e,t){let r=t.parts,s=r.length;if(s===1){let i=await K(e,r[0]);return de(i,e.limits.maxStringLength,"word expansion"),i}let n=[];for(let i=0;i=i)throw new W(`Command substitution nesting limit exceeded (${i})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=a+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),d=h.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=d,e.state.env.set("?",String(d)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=o,e.substitutionDepth=l;let m=h.stdout.replace(/\n+$/,"");return de(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,h instanceof W)throw h;if(h instanceof Y){e.state.lastExitCode=h.exitCode,e.state.env.set("?",String(h.exitCode)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let d=h.stdout.replace(/\n+$/,"");return de(d,e.limits.maxStringLength,"command substitution"),d}throw h}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let i=await Pn(e,n),l=new B,o=q(l,i);return String(await R(e,o.expression,!0))}return String(await R(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let a of t.items)if(a.type==="Range"){let i=wt(a.start,a.end,a.step,a.startStr,a.endStr);if(i.expanded)n.push(...i.expanded);else return i.literal}else n.push(await Dt(e,a.word));return n.join(" ")}default:return""}}async function ze(e,t,r=!1){let{parameter:s}=t,{operation:n}=t,a=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,h,d]=a;if(e.state.associativeArrays?.has(h)||d.includes("$(")||d.includes("`")||d.includes("${")){let g=await bt(e,d);s=`${h}[${g}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&T(e,s)){let h=ye(e,s);if(h&&h!==s){let d=h.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,m,g]=d;if(e.state.associativeArrays?.has(m)||g.includes("$(")||g.includes("`")||g.includes("${")){let A=await bt(e,g);s=`${m}[${A}]`}}}}let i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await D(e,s,!i);if(!n)return l;let o=!await re(e,s),{isEmpty:u,effectiveValue:c}=qn(e,s,l,r),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:r};switch(n.type){case"DefaultValue":return In(e,n,f,te);case"AssignDefault":return Dn(e,s,n,f,te);case"ErrorIfUnset":return xn(e,s,n,f,te);case"UseAlternative":return vn(e,n,f,te);case"PatternRemoval":{let h=await _n(e,l,n,te,K);return de(h,e.limits.maxStringLength,"pattern removal"),h}case"PatternReplacement":{let h=await $n(e,l,n,te,K);return de(h,e.limits.maxStringLength,"pattern replacement"),h}case"Length":return Cn(e,s,l);case"LengthSliceError":throw new ae(s);case"BadSubstitution":throw new ae(n.text);case"Substring":return On(e,s,l,n);case"CaseModification":{let h=await Ln(e,l,n,te,ze);return de(h,e.limits.maxStringLength,"case modification"),h}case"Transform":return Wn(e,s,l,o,n);case"Indirection":return Tn(e,s,l,o,n,ze,r);case"ArrayKeys":return Mn(e,n);case"VarNamePrefix":return Vn(e,n);default:return l}}export{Vi as a,qi as b,Ee as c,U as d,q as e,B as f,Ni as g,Et as h,Fi as i,At as j,zi as k,wn as l,M as m,Qi as n,Zi as o,T as p,Hi as q,ji as r,Ki as s,Xi as t,ys as u,ye as v,Pe as w,Ji as x,P as y,Re as z,D as A,ee as B,kt as C,wa as D,Pt as E,Na as F,ka as G,Pa as H,Dl as I,Dt as J,xl as K,vl as L,_l as M,Ks as N,$l as O,R as P}; diff --git a/packages/just-bash/dist/bin/chunks/chunk-FJABJBIW.js b/packages/just-bash/dist/bin/chunks/chunk-RO3XCUVQ.js similarity index 99% rename from packages/just-bash/dist/bin/chunks/chunk-FJABJBIW.js rename to packages/just-bash/dist/bin/chunks/chunk-RO3XCUVQ.js index 6dffab95..c52930ba 100644 --- a/packages/just-bash/dist/bin/chunks/chunk-FJABJBIW.js +++ b/packages/just-bash/dist/bin/chunks/chunk-RO3XCUVQ.js @@ -1,6 +1,6 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as F,b,c as M,d as He,e as w,f as v,g as Y,h as Z}from"./chunk-NXYVRP6D.js";import{a as st}from"./chunk-MNWK4UIM.js";import{a as $}from"./chunk-LMA4D2KK.js";import{f as qe,g as X}from"./chunk-MLUOPG3W.js";import{a as J}from"./chunk-52FZYTIX.js";import{a as _e}from"./chunk-ZZP3RSWL.js";import{a as _}from"./chunk-DHIKZU63.js";import{a as D,b as G}from"./chunk-MUFNRCMY.js";import{b as We,d as et,e as tt,f as nt}from"./chunk-LNVSXNT7.js";var q,Je=We(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let r=new Map([["(","("],[")",")"],["[","["],["]","]"],["{","{"],["}","}"],[",",","],[":",":"],[";",";"],["+","+"],["-","-"],["*","*"],["%","%"],["<","<"],[">",">"],["!","!"],[".","."],["|","|"],["=","="]]).get(t);if(r!==void 0)return this.pos++,{type:r,value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.posH,parseNamedExpressions:()=>U});function U(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},a=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){a();continue}let d=[],u=0,p=r;for(;o().type!=="eof";){let i=o();if((i.type===","||i.type==="as")&&u===0)break;(i.type==="("||i.type==="["||i.type==="{")&&u++,(i.type===")"||i.type==="]"||i.type==="}")&&u--,d.push(a())}d.push({type:"eof",value:"",pos:0});let h=new z(d).parse(),l;if(o().type==="as")if(a(),o().type==="("){a();let i=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(i.push(o().value),a()),o().type===","&&a();o().type===")"&&a(),l=i}else if(o().type==="ident"||o().type==="string")l=o().value,a();else throw new Error(`Expected name after 'as', got ${o().type}`);else l=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),h.type==="identifier"&&(l=h.name);n.push({expr:h,name:l})}return n}function H(e){let t=new q(e).tokenize();return new z(t).parse()}var R,z,V=We(()=>{"use strict";Je();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},z=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=this.pos;if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=[this.peek().value];this.advance();let o=!0;for(;this.peek().type===",";)if(this.advance(),this.peek().type==="ident")r.push(this.peek().value),this.advance();else{o=!1;break}if(o&&this.peek().type===")"&&this.peekAt(1).type==="=>"){this.advance(),this.advance();let a=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:r,body:a},r)}this.pos=t}let s=this.parseExpr(0);return this.expect(")"),s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,a=this.pos+1;a0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let a=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:n},{expr:a}]}}if(s.type==="|"){this.advance();let a=this.parseExpr(t);return this.handlePipe(n,a)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}peekAt(n){return this.tokens[this.pos+n]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});V();function E(e,n){return n.length===0?I(e,[]):n.length===1?{type:"Pipe",left:n[0],right:I(e,[])}:{type:"Pipe",left:n[0],right:I(e,n.slice(1))}}var K={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>I("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?I("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?I("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?I("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>I("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>I("select",e),empty:()=>I("empty",[]),count:()=>I("length",[]),sum:e=>e.length===0?I("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:I("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",I("add",[]),I("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",I("add",[]),I("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?I("tonumber",[]):I("tonumber",e),tostring:e=>e.length===0?I("tostring",[]):I("tostring",e),if:e=>Ke(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return Ke(s,n,t.length===1?t[0]:K.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>I("now",[]),fmt:e=>I("tostring",e),format:e=>I("tostring",e)};Object.setPrototypeOf(K,null);function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function I(e,n){return{type:"Call",name:e,args:n}}var rt="then";function Ke(e,n,t){let s=qe({type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}});return s[rt]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function O(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>O(r.expr,n)),s=Object.hasOwn(K,e.name)?K[e.name]:void 0;return typeof s=="function"?s(t):I(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=O(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:O(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?O(e.start,n):void 0,end:e.end?O(e.end,n):void 0};case"lambda":return O(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function ee(e){let n=[],t=0;for(;t=e.length)break;let s=t;for(;t0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let d=e.slice(a,t).trim();for(t++;t0?r[0]:null}function te(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Be(r)?o=e.map(a=>a[r]).filter(a=>a!=null):o=e.map(a=>Q(a,r,t)).filter(a=>a!=null),s){case"count":return Be(r)?o.length:o.filter(a=>!!a).length;case"sum":return o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d))).reduce((d,u)=>d+u,0);case"mean":case"avg":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?a.reduce((d,u)=>d+u,0)/a.length:0}case"min":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.min(...a):null}case"max":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.max(...a):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let a=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(a.length===0)return null;let d=Math.floor(a.length/2);return a.length%2===0?(a[d-1]+a[d])/2:a[d]}case"mode":{let a=new Map;for(let p of o){let c=String(p);a.set(c,(a.get(c)||0)+1)}let d=0,u=null;for(let[p,c]of a)c>d&&(d=c,u=p);return u}case"cardinality":return new Set(o.map(d=>String(d))).size;case"values":return o.map(a=>String(a)).join("|");case"distinct_values":return[...new Set(o.map(d=>String(d)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let a of e)if(!Q(a,r,t))return!1;return!0}case"any":{for(let a of e)if(Q(a,r,t))return!0;return!1}default:return null}}function Ge(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,te(e,r,t));return s}async function ne(e,n){let t="",s=[];for(let c of e)c.startsWith("-")||(t?s.push(c):t=c);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression diff --git a/packages/just-bash/dist/bin/chunks/expansion-PCODPDNZ.js b/packages/just-bash/dist/bin/chunks/expansion-PCODPDNZ.js deleted file mode 100644 index 3317f47d..00000000 --- a/packages/just-bash/dist/bin/chunks/expansion-PCODPDNZ.js +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{A as c,B as d,C as e,I as f,J as g,K as h,L as i,M as j,N as k,O as l,y as a,z as b}from"./chunk-PDS5TEMS.js";import"./chunk-52FZYTIX.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-LNVSXNT7.js";export{d as escapeGlobChars,e as escapeRegexChars,l as expandRedirectTarget,g as expandWord,i as expandWordForPattern,h as expandWordForRegex,j as expandWordWithGlob,a as getArrayElements,c as getVariable,k as hasQuotedMultiValueAt,b as isArray,f as isWordFullyQuoted}; diff --git a/packages/just-bash/dist/bin/chunks/flag-coverage-DFXMJJWX.js b/packages/just-bash/dist/bin/chunks/flag-coverage-K737BGC5.js similarity index 94% rename from packages/just-bash/dist/bin/chunks/flag-coverage-DFXMJJWX.js rename to packages/just-bash/dist/bin/chunks/flag-coverage-K737BGC5.js index f5d2b8c5..888b18db 100644 --- a/packages/just-bash/dist/bin/chunks/flag-coverage-DFXMJJWX.js +++ b/packages/just-bash/dist/bin/chunks/flag-coverage-K737BGC5.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{b as yr}from"./chunk-Y5OWCEDV.js";import{b as Ar}from"./chunk-J7XTZ47D.js";import{b as $r}from"./chunk-FJABJBIW.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import{c as Sr}from"./chunk-BTZKLEUT.js";import{b as wr}from"./chunk-WHUKZ3K3.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-MP77TJMM.js";import{d as Ir,e as Mr,f as jr}from"./chunk-BPZJYOUA.js";import{b as tr}from"./chunk-TKYWUEON.js";import{b as lr}from"./chunk-ZFUVUYWG.js";import{b as ur}from"./chunk-XPTYN6UE.js";import{b as pr}from"./chunk-W5OBQVJ2.js";import{b as er}from"./chunk-PKE7GKU5.js";import{b as dr}from"./chunk-JSZBZ2XU.js";import{b as cr}from"./chunk-7HK63L6Y.js";import"./chunk-HWNCK5BB.js";import{b as hr}from"./chunk-BZP56QBM.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-OVVMB2JI.js";import{b as mr}from"./chunk-4J4UC7OD.js";import"./chunk-LMA4D2KK.js";import{b as Fr}from"./chunk-6WJQNLR2.js";import{b as zr}from"./chunk-R36DS2UF.js";import{b as fr}from"./chunk-7NDRU2ZN.js";import{b as nr}from"./chunk-CX5CEEGI.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-WDWNEHHE.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-FYCT4DWY.js";import{b as G}from"./chunk-KMZUSEWI.js";import{b as H}from"./chunk-MTK7VLZG.js";import{b as J}from"./chunk-7VCQWCSH.js";import{b as K}from"./chunk-6JKLDBRW.js";import{b as L}from"./chunk-2ZAK22BG.js";import{b as O}from"./chunk-IX7LKVVH.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-JDFKEXLG.js";import{b as y}from"./chunk-PSJORJRS.js";import{b as A}from"./chunk-NMMVECGD.js";import{b as $}from"./chunk-RKBWTGBZ.js";import{b as S}from"./chunk-G7ZWT7BT.js";import{b as T}from"./chunk-C6JOQKE2.js";import{b as B}from"./chunk-AFAD5U2A.js";import{b as D}from"./chunk-FEENTUVZ.js";import{b as E}from"./chunk-JJC4ENJL.js";import{b as w}from"./chunk-RVGYO2OU.js";import{b as x}from"./chunk-OXZSG3ZZ.js";import{b as v}from"./chunk-UOMNSQEZ.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-Y2IUEWQD.js";import"./chunk-DWECIBLJ.js";import{b}from"./chunk-GXX3QUMM.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import{b as I}from"./chunk-TIRU5FOD.js";import{b as M}from"./chunk-D7YFPDMV.js";import{b as j}from"./chunk-KWCO3YXP.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-2AIXTPH2.js";import{b as u}from"./chunk-3WIMLJM7.js";import{b as p}from"./chunk-2GG3NVC4.js";import{b as e}from"./chunk-XHCCSVP6.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-XRUDFQG5.js";import{b as h}from"./chunk-6FYCU7QB.js";import"./chunk-N3FQJLPZ.js";import"./chunk-NYIPFY36.js";import"./chunk-UNWZQG7U.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import{b as i}from"./chunk-XBB73LFB.js";import{b as g}from"./chunk-GTO74SFS.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import{b as m}from"./chunk-HMCRB24D.js";import"./chunk-4BNS566Q.js";import"./chunk-JXLDT4KX.js";import"./chunk-47WZ2U6M.js";import{b as F}from"./chunk-N6YW4W3Z.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import"./chunk-PBOVSFTJ.js";import{b as f}from"./chunk-5XSZHUEI.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage}; +import{b as yr}from"./chunk-Y5OWCEDV.js";import{b as Ar}from"./chunk-HZR3FOJM.js";import{b as $r}from"./chunk-RO3XCUVQ.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import{c as Sr}from"./chunk-BTZKLEUT.js";import{b as wr}from"./chunk-WHUKZ3K3.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-MP77TJMM.js";import{d as Ir,e as Mr,f as jr}from"./chunk-BPZJYOUA.js";import{b as tr}from"./chunk-TKYWUEON.js";import{b as lr}from"./chunk-ZFUVUYWG.js";import{b as ur}from"./chunk-XPTYN6UE.js";import{b as pr}from"./chunk-W5OBQVJ2.js";import{b as er}from"./chunk-PKE7GKU5.js";import{b as dr}from"./chunk-JSZBZ2XU.js";import{b as cr}from"./chunk-7HK63L6Y.js";import"./chunk-HWNCK5BB.js";import{b as hr}from"./chunk-BZP56QBM.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-OVVMB2JI.js";import{b as mr}from"./chunk-63LSI3D6.js";import"./chunk-ISLENKSH.js";import{b as Fr}from"./chunk-6WJQNLR2.js";import{b as zr}from"./chunk-R36DS2UF.js";import{b as fr}from"./chunk-7NDRU2ZN.js";import{b as nr}from"./chunk-CX5CEEGI.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-WDWNEHHE.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-FYCT4DWY.js";import{b as G}from"./chunk-KMZUSEWI.js";import{b as H}from"./chunk-MTK7VLZG.js";import{b as J}from"./chunk-7VCQWCSH.js";import{b as K}from"./chunk-6JKLDBRW.js";import{b as L}from"./chunk-2ZAK22BG.js";import{b as O}from"./chunk-IX7LKVVH.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-JDFKEXLG.js";import{b as y}from"./chunk-PSJORJRS.js";import{b as A}from"./chunk-NMMVECGD.js";import{b as $}from"./chunk-RKBWTGBZ.js";import{b as S}from"./chunk-G7ZWT7BT.js";import{b as T}from"./chunk-C6JOQKE2.js";import{b as B}from"./chunk-AFAD5U2A.js";import{b as D}from"./chunk-FEENTUVZ.js";import{b as E}from"./chunk-JJC4ENJL.js";import{b as w}from"./chunk-RVGYO2OU.js";import{b as x}from"./chunk-OXZSG3ZZ.js";import{b as v}from"./chunk-UOMNSQEZ.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-Y2IUEWQD.js";import"./chunk-DWECIBLJ.js";import{b}from"./chunk-BKQLXMS6.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import{b as I}from"./chunk-TIRU5FOD.js";import{b as M}from"./chunk-D7YFPDMV.js";import{b as j}from"./chunk-KWCO3YXP.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-2AIXTPH2.js";import{b as u}from"./chunk-3WIMLJM7.js";import{b as p}from"./chunk-2GG3NVC4.js";import{b as e}from"./chunk-XHCCSVP6.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-XRUDFQG5.js";import{b as h}from"./chunk-6FYCU7QB.js";import"./chunk-N3FQJLPZ.js";import"./chunk-NYIPFY36.js";import"./chunk-UNWZQG7U.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import{b as i}from"./chunk-XBB73LFB.js";import{b as g}from"./chunk-GTO74SFS.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import{b as m}from"./chunk-HMCRB24D.js";import"./chunk-4BNS566Q.js";import"./chunk-JXLDT4KX.js";import"./chunk-47WZ2U6M.js";import{b as F}from"./chunk-N6YW4W3Z.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import"./chunk-PBOVSFTJ.js";import{b as f}from"./chunk-5XSZHUEI.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage}; diff --git a/packages/just-bash/dist/bin/chunks/jq-33GJJXTL.js b/packages/just-bash/dist/bin/chunks/jq-3V5HDGLJ.js similarity index 88% rename from packages/just-bash/dist/bin/chunks/jq-33GJJXTL.js rename to packages/just-bash/dist/bin/chunks/jq-3V5HDGLJ.js index 97bbc75f..f1fc9fd5 100644 --- a/packages/just-bash/dist/bin/chunks/jq-33GJJXTL.js +++ b/packages/just-bash/dist/bin/chunks/jq-3V5HDGLJ.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-4J4UC7OD.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as jqCommand}; +import{a,b}from"./chunk-63LSI3D6.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as jqCommand}; diff --git a/packages/just-bash/dist/bin/shell/chunks/rg-2YWJS6TE.js b/packages/just-bash/dist/bin/chunks/rg-DZKA632H.js similarity index 83% rename from packages/just-bash/dist/bin/shell/chunks/rg-2YWJS6TE.js rename to packages/just-bash/dist/bin/chunks/rg-DZKA632H.js index fd2f6b21..3f7b0b10 100644 --- a/packages/just-bash/dist/bin/shell/chunks/rg-2YWJS6TE.js +++ b/packages/just-bash/dist/bin/chunks/rg-DZKA632H.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-GXX3QUMM.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as rgCommand}; +import{a,b}from"./chunk-BKQLXMS6.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as rgCommand}; diff --git a/packages/just-bash/dist/bin/shell/chunks/xan-TSDTZVY3.js b/packages/just-bash/dist/bin/chunks/xan-TCTFON2Q.js similarity index 77% rename from packages/just-bash/dist/bin/shell/chunks/xan-TSDTZVY3.js rename to packages/just-bash/dist/bin/chunks/xan-TCTFON2Q.js index bc0e6eb0..787fa2df 100644 --- a/packages/just-bash/dist/bin/shell/chunks/xan-TSDTZVY3.js +++ b/packages/just-bash/dist/bin/chunks/xan-TCTFON2Q.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-FJABJBIW.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as xanCommand}; +import{a,b}from"./chunk-RO3XCUVQ.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as xanCommand}; diff --git a/packages/just-bash/dist/bin/chunks/yq-KU5YTNAK.js b/packages/just-bash/dist/bin/chunks/yq-OB6PB5GY.js similarity index 75% rename from packages/just-bash/dist/bin/chunks/yq-KU5YTNAK.js rename to packages/just-bash/dist/bin/chunks/yq-OB6PB5GY.js index 8c307a62..321fab36 100644 --- a/packages/just-bash/dist/bin/chunks/yq-KU5YTNAK.js +++ b/packages/just-bash/dist/bin/chunks/yq-OB6PB5GY.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-J7XTZ47D.js";import"./chunk-MNWK4UIM.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as yqCommand}; +import{a,b}from"./chunk-HZR3FOJM.js";import"./chunk-MNWK4UIM.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as yqCommand}; diff --git a/packages/just-bash/dist/bin/just-bash.js b/packages/just-bash/dist/bin/just-bash.js index a3a20e4d..7cc8846a 100644 --- a/packages/just-bash/dist/bin/just-bash.js +++ b/packages/just-bash/dist/bin/just-bash.js @@ -1,159 +1,233 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{B as Zn,C as qn,D as ce,E as Ue,F as ee,G as Se,H as Ft,I as Gn,J as x,K as Kn,L as Xn,M as Ce,N as Cs,O as Wt,P as j,a as Wn,b as bs,c as Mn,d as Rt,e as Q,f as V,g as $e,h as se,i as _e,j as Fe,k as $s,l as Lt,m as zn,n as Es,o as Vn,p as ge,q as Te,r as Bn,s as jn,t as Ss,u as As,v as We,w as Hn,x as Un,y as Ee,z as _s}from"./chunks/chunk-PDS5TEMS.js";import{a as Je,b as et,c as Le}from"./chunks/chunk-O2BCKSMK.js";import{c as vs}from"./chunks/chunk-NYIPFY36.js";import{a as Tn,b as xn}from"./chunks/chunk-UNWZQG7U.js";import{a as Re,b as ye,c as ws}from"./chunks/chunk-MROECM42.js";import{a as yt,b as Fn}from"./chunks/chunk-AZH64XMJ.js";import{a as Qe,b as be}from"./chunks/chunk-LX2H4DPL.js";import{a as mt}from"./chunks/chunk-52FZYTIX.js";import{b as je,d as In,e as ys,f as gs}from"./chunks/chunk-DHIKZU63.js";import{a as fe,b as de,c as le,d as pe,e as Rn,f as B,g as He,h as Dt,i as Tt,j as Ln,k as Y,l as xt,m as Ie,n as It,o as me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as he}from"./chunks/chunk-PBOVSFTJ.js";import{a as De}from"./chunks/chunk-I4IRHQDW.js";import{a as Dn}from"./chunks/chunk-LNVSXNT7.js";import{resolve as Zi}from"node:path";var tt=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-2YWJS6TE.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-33GJJXTL.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(tt.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),tt.push({name:"yq",load:async()=>(await import("./chunks/yq-KU5YTNAK.js")).yqCommand}),tt.push({name:"xan",load:async()=>(await import("./chunks/xan-TSDTZVY3.js")).xanCommand}),tt.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-2ZD7O55W.js")).sqlite3Command}));var Ps=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ps.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),Ps.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var ks=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(ks.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),ks.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var Yi=[{name:"curl",load:async()=>(await import("./chunks/curl-VWGTXT4F.js")).curlCommand}],Yn=new Map;function Mt(e){return{name:e.name,async execute(t,s){let n=Yn.get(e.name);if(n||(n=await be.runTrustedAsync(()=>e.load()),Yn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-DFXMJJWX.js");r(s.coverage,e.name,t)}return n.execute(t,s)}}}function Qn(e){return(e?tt.filter(s=>e.includes(s.name)):tt).map(Mt)}function Jn(){return Yi.map(Mt)}function er(){return Ps.map(Mt)}function tr(){return ks.map(Mt)}function sr(e){return"load"in e&&typeof e.load=="function"}function nr(e){let t=null;return{name:e.name,trusted:!0,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}function L(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(r=>r&&r!=="."),n=[];for(let r of s)r===".."?n.pop():n.push(r);return`/${n.join("/")}`||"/"}function M(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function Ze(e){let t=L(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function zt(e,t){if(t.startsWith("/"))return L(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return L(s)}function gt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function st(e,t){if(t.startsWith("/"))return L(t);let s=Ze(e);return L(gt(s,t))}var nt=new TextEncoder;function Qi(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var wt=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))typeof n=="function"?this.writeFileLazy(s,n):Qi(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}ensureParentDirs(t){let s=Ze(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){M(t,"write");let i=L(t);this.ensureParentDirs(i);let a=Le(n),o=Je(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}writeFileLazy(t,s,n){M(t,"write");let r=L(t);this.ensureParentDirs(r),this.data.set(r,{type:"file",lazy:s,mode:n?.mode??420,mtime:n?.mtime??new Date})}async materializeLazy(t,s){let n=await s.lazy(),i={type:"file",content:typeof n=="string"?nt.encode(n):n,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let n=await this.readFileBuffer(t),r=Le(s);return et(n,r)}async readFileBytes(t){let s=await this.readFileBuffer(t);return et(s,"binary")}async readFileBuffer(t){M(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in n){let r=await this.materializeLazy(s,n);return r.content instanceof Uint8Array?r.content:nt.encode(r.content)}return n.content instanceof Uint8Array?n.content:nt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){M(t,"append");let r=L(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=Le(n),o=Je(s,a);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(r,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:nt.encode("content"in l?l.content:""),c=new Uint8Array(u.length+o.length);c.set(u),c.set(o,u.length),this.data.set(r,{type:"file",content:c,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){M(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=nt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){M(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=nt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveIntermediateSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),l=0,u=40;for(;o&&o.type==="symlink"&&l=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){M(t,"mkdir");let n=L(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=Ze(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){M(t,"scandir");let s=L(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=st(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==s&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.namel.name?1:0)}async rm(t,s){M(t,"rm");let n=L(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=gt(n,a);await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){M(t,"cp"),M(s,"cp");let r=L(t),i=L(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let o=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:o})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let l of o){let u=gt(r,l),c=gt(i,l);await this.cp(u,c,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return zt(t,s)}async chmod(t,s){M(t,"chmod");let n=L(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){M(s,"symlink");let n=L(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){M(t,"link"),M(s,"link");let n=L(t),r=L(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(n,a)),this.ensureParentDirs(r),this.data.set(r,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){M(t,"readlink");let s=L(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){M(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){M(t,"utimes");let r=L(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function Ji(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function ea(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function ta(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function sa(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Wn} +import{a as Ct,b as xt,c as dt}from"./chunks/chunk-O2BCKSMK.js";import{c as Sn}from"./chunks/chunk-NYIPFY36.js";import{a as fi,b as di}from"./chunks/chunk-UNWZQG7U.js";import{a as ft,b as Fe,c as vn}from"./chunks/chunk-MROECM42.js";import{a as Xt,b as pi}from"./chunks/chunk-AZH64XMJ.js";import{a as It,b as Be}from"./chunks/chunk-LX2H4DPL.js";import{a as ae}from"./chunks/chunk-52FZYTIX.js";import{b as St,d as hi,e as En,f as bn}from"./chunks/chunk-DHIKZU63.js";import{a as De,b as Ie,c as $e,d as We,e as Ce,f as j,g as te,h as xe,i as ct,j as ws,k as Q,l as Es,m as ut,n as bs,o as Me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as Re}from"./chunks/chunk-PBOVSFTJ.js";import{a as it}from"./chunks/chunk-I4IRHQDW.js";import{a as ui}from"./chunks/chunk-LNVSXNT7.js";import{resolve as hc}from"node:path";var Rt=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-DZKA632H.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-3V5HDGLJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Rt.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),Rt.push({name:"yq",load:async()=>(await import("./chunks/yq-OB6PB5GY.js")).yqCommand}),Rt.push({name:"xan",load:async()=>(await import("./chunks/xan-TCTFON2Q.js")).xanCommand}),Rt.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-2ZD7O55W.js")).sqlite3Command}));var An=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(An.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),An.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var $n=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&($n.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),$n.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var wc=[{name:"curl",load:async()=>(await import("./chunks/curl-VWGTXT4F.js")).curlCommand}],mi=new Map;function vs(e){return{name:e.name,async execute(t,s){let r=mi.get(e.name);if(r||(r=await Be.runTrustedAsync(()=>e.load()),mi.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-K737BGC5.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function gi(e){return(e?Rt.filter(s=>e.includes(s.name)):Rt).map(vs)}function yi(){return wc.map(vs)}function wi(){return An.map(vs)}function Ei(){return $n.map(vs)}function bi(e){return"load"in e&&typeof e.load=="function"}function vi(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}function B(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(n=>n&&n!=="."),r=[];for(let n of s)n===".."?r.pop():r.push(n);return`/${r.join("/")}`||"/"}function K(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function At(e){let t=B(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function Ss(e,t){if(t.startsWith("/"))return B(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return B(s)}function Yt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function Ot(e,t){if(t.startsWith("/"))return B(t);let s=At(e);return B(Yt(s,t))}var Lt=new TextEncoder;function Ec(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Jt=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):Ec(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=At(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){K(t,"write");let i=B(t);this.ensureParentDirs(i);let a=dt(r),l=Ct(s,a);this.data.set(i,{type:"file",content:l,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){K(t,"write");let n=B(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?Lt.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=dt(s);return xt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return xt(s,"binary")}async readFileBuffer(t){K(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:Lt.encode(n.content)}return r.content instanceof Uint8Array?r.content:Lt.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){K(t,"append");let n=B(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=dt(r),l=Ct(s,a);if(i?.type==="file"){let o=i;"lazy"in o&&(o=await this.materializeLazy(n,o));let u="content"in o&&o.content instanceof Uint8Array?o.content:Lt.encode("content"in o?o.content:""),c=new Uint8Array(u.length+l.length);c.set(u),c.set(l,u.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){K(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){K(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let a=0;a=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let a of r){n=`${n}/${a}`;let l=this.data.get(n),o=0,u=40;for(;l&&l.type==="symlink"&&o=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){K(t,"mkdir");let r=B(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=At(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){K(t,"scandir");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=Ot(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[l,o]of this.data.entries())if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}return Array.from(a.values()).sort((l,o)=>l.nameo.name?1:0)}async rm(t,s){K(t,"rm");let r=B(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let l=Yt(r,a);await this.rm(l,s)}}}this.data.delete(r)}async cp(t,s,r){K(t,"cp"),K(s,"cp");let n=B(t),i=B(s),a=this.data.get(n);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let l=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:l})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(n);for(let o of l){let u=Yt(n,o),c=Yt(i,o);await this.cp(u,c,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Ss(t,s)}async chmod(t,s){K(t,"chmod");let r=B(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){K(s,"symlink");let r=B(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){K(t,"link"),K(s,"link");let r=B(t),n=B(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(r,a)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){K(t,"readlink");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){K(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){K(t,"utimes");let n=B(t),i=this.resolvePathWithSymlinks(n),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var Ai="5.1.0(1)-release",$i="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function kn(e){let{pid:t,ppid:s,uid:r,gid:n}=e;return`Name: bash +State: R (running) +Pid: ${t} +PPid: ${s} +Uid: ${r} ${r} ${r} ${r} +Gid: ${n} ${n} ${n} ${n} +`}function bc(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function vc(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Sc(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Ac(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${$i} `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash -`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>bs(t)):e.writeFileSync("/proc/self/status",bs(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function ir(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){Ji(e)&&(ea(e,t),ta(e),sa(e,s))}var na=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],ra=["braceexpand","hashall","interactive-comments"];function Os(e){let t=[],s=[...ra.map(n=>({name:n,enabled:!0})),...na.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function it(e){e.state.env.set("SHELLOPTS",Os(e.state.options))}var ia=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ds(e){let t=[];for(let s of ia)e[s]&&t.push(s);return t.join(":")}function Ts(e){e.state.env.set("BASHOPTS",Ds(e.state.shoptOptions))}var aa="BASH_ALIAS_";function ar(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function or(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function lr(e,t){return e.env.get(`${aa}${t}`)}function xs(e,t,s){if(!t.name||!ar(t.name))return t;let n=or(t.name);if(!n)return t;let r=lr(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new V,a=r,o=r.endsWith(" ");if(!o)for(let f of t.args){let d=ur(f);a+=` ${d}`}let l;try{l=i.parse(a)}catch(f){if(f instanceof Rt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return cr(t,r);let u=l.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return cr(t,r);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(ar(f)){let d=or(f);if(d&&lr(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},y=xs(e,h,s);y!==h&&(c={...c,name:y.name,args:[...y.args]})}}}return c}catch(i){throw s.delete(n),i}}function cr(e,t){let s=t;for(let a of e.args){let o=ur(a);s+=` ${o}`}let n=new V,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function ur(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function fr(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",l=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||l)&&(i.push(o),o="",l=!1):h&&(o+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=Lt({type:"Word",parts:[c]});else{(o||l)&&(i.push(o),o="",l=!1);let d=await Ce(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(l=!0);let f=await x(e,{type:"Word",parts:[c]});o+=f}(o||l)&&i.push(o);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${r}=(${u.join(" ")})`}async function dr(e,t){let s=-1,n=-1,r=!1;for(let p=0;p0?await x(e,d):"";return`${f}${r?"+=":"="}${h}`}var oa=["tar","yq","xan","sqlite3","python3","python"];function hr(e){return oa.includes(e)}var W=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function X(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Pe(e,t,s="",n=""){throw new Y(e,t,s,n)}function ie(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Y(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Is(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ie;return W}if(t.length>1)throw new B(1,"",`bash: break: too many arguments -`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(128,"",`bash: break: ${t[0]}: numeric argument required -`);s=n}throw new fe(s)}async function Rs(e,t){let s,n=!1,r=!1,i=0;for(;ih);for(let h of d){let y=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(y)).isDirectory){s=y,n=!0;break}}catch{}}}}let l=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${s}: Not a directory +`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>kn(t)):e.writeFileSync("/proc/self/status",kn(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Ni(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){bc(e)&&(vc(e,t),Sc(e),Ac(e,s))}var $c=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Nc=["braceexpand","hashall","interactive-comments"];function _n(e){let t=[],s=[...Nc.map(r=>({name:r,enabled:!0})),...$c.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function Wt(e){e.state.env.set("SHELLOPTS",_n(e.state.options))}var kc=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Pn(e){let t=[];for(let s of kc)e[s]&&t.push(s);return t.join(":")}function Dn(e){e.state.env.set("BASHOPTS",Pn(e.state.shoptOptions))}var R={script(e){return{type:"Script",statements:e}},statement(e,t=[],s=!1,r,n){let i={type:"Statement",pipelines:e,operators:t,background:s};return r&&(i.deferredError=r),n!==void 0&&(i.sourceText=n),i},pipeline(e,t=!1,s=!1,r=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:s,timePosix:r,pipeStderr:n}},simpleCommand(e,t=[],s=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:s,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,s=!1,r=null){return{type:"Assignment",name:e,value:t,append:s,array:r}},redirection(e,t,s=null,r){let n={type:"Redirection",fd:s,operator:e,target:t};return r&&(n.fdVariable=r),n},hereDoc(e,t,s=!1,r=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:s,quoted:r}},ifNode(e,t=null,s=[]){return{type:"If",clauses:e,elseBody:t,redirections:s}},forNode(e,t,s,r=[]){return{type:"For",variable:e,words:t,body:s,redirections:r}},whileNode(e,t,s=[]){return{type:"While",condition:e,body:t,redirections:s}},untilNode(e,t,s=[]){return{type:"Until",condition:e,body:t,redirections:s}},caseNode(e,t,s=[]){return{type:"Case",word:e,items:t,redirections:s}},caseItem(e,t,s=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:s}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,s=[],r){return{type:"FunctionDef",name:e,body:t,redirections:s,sourceFile:r}},conditionalCommand(e,t=[],s){return{type:"ConditionalCommand",expression:e,redirections:t,line:s}},arithmeticCommand(e,t=[],s){return{type:"ArithmeticCommand",expression:e,redirections:t,line:s}}};function ki(e,t){let s=e.length,r=t+3,n=2,i=!1,a=!1;for(;r0;){let l=e[r];if(i){l==="'"&&(i=!1),r++;continue}if(a){if(l==="\\"){r+=2;continue}l==='"'&&(a=!1),r++;continue}if(l==="'"){i=!0,r++;continue}if(l==='"'){a=!0,r++;continue}if(l==="\\"){r+=2;continue}if(l==="("){n++,r++;continue}if(l===")"){if(n--,n===1){let o=r+1;return!(oi===" "||i===" "||i===` +`||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r=e.length)return e.length;let a=e.indexOf(` +`,r);a===-1&&(a=e.length);let l=e.slice(r,a);if(i&&(l=l.replace(/^\t+/,"")),l===n){r=a+1;break}if(a>=e.length)return e.length;r=a+1}return Math.min(r,e.length)}function _i(e,t,s,r){let n=t+2,i=1,a=n,l=!1,o=!1,u=0,c=!1,f="",d=[],h=0;for(;a0;){let b=e[a];if(l)b==="'"&&(l=!1);else if(o)b==="\\"&&a+10&&h--,h===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let v=a+2,E=!1;for(e[v]==="-"&&(E=!0,v++);e[v]===" "||e[v]===" ";)v++;let{delim:w,endPos:S}=In(e,v);if(w.length>0){d.push({delim:w,stripTabs:E}),f="",a=S;continue}}if(b===` +`&&d.length>0){let v=_c(e,a,d);d.length=0,f="",a=v;continue}b==="'"?(l=!0,f=""):b==='"'?(o=!0,f=""):b==="\\"&&a+10?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:c||i++:b===")"?c?c=!1:i--:b===";"&&u>0&&a+10&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let p=e.slice(n,a),y=s().parse(p);return{part:R.commandSubstitution(y,!1),endIndex:a+1}}function Pi(e,t,s,r,n){let a=t+1,l="";for(;a=e.length&&n("unexpected EOF while looking for matching ``'");let u=r().parse(l);return{part:R.commandSubstitution(u,!0),endIndex:a+1}}var Pc=10485760,g;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(g||(g={}));var ht=class extends Error{line;column;constructor(t,s,r){super(`line ${s}: ${t}`),this.line=s,this.column=r,this.name="LexerError"}},Di=new Map([["if",g.IF],["then",g.THEN],["else",g.ELSE],["elif",g.ELIF],["fi",g.FI],["for",g.FOR],["while",g.WHILE],["until",g.UNTIL],["do",g.DO],["done",g.DONE],["case",g.CASE],["esac",g.ESAC],["in",g.IN],["function",g.FUNCTION],["select",g.SELECT],["time",g.TIME],["coproc",g.COPROC]]);function Ii(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let s=e.slice(t[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n=s.length)return!1;let i=s.slice(n+1);return i===""||i==="+"}return!1}function Ci(e){let t=0;for(let s=0;s",">",g.AND_DGREAT]],Ic=[["[","[",g.DBRACK_START],["]","]",g.DBRACK_END],["(","(",g.DPAREN_START],[")",")",g.DPAREN_END],["&","&",g.AND_AND],["|","|",g.OR_OR],[";",";",g.DSEMI],[";","&",g.SEMI_AND],["|","&",g.PIPE_AMP],[">",">",g.DGREAT],["<","&",g.LESSAND],[">","&",g.GREATAND],["<",">",g.LESSGREAT],[">","|",g.CLOBBER],["&",">",g.AND_GREAT]],Cc=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function xc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function xi(e){return e===" "||e===" "||e===` +`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var $s=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,s){this.input=t,this.maxHeredocSize=s?.maxHeredocSize??Pc}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=s)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,s=t.length,r=this.pos,n=this.column,i=this.line;for(;r0?(this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n)):this.looksLikeNestedSubshells(s+2)||this.dparenClosesWithSpacedParens(s+2)?(this.pos=s+1,this.column=n+1,this.makeToken(g.LPAREN,"(",s,r,n)):(this.pos=s+2,this.column=n+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",s,r,n));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=s+2,this.column=n+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",s,r,n)):this.dparenDepth>1?(this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.RPAREN,")",s,r,n));for(let[u,c,f]of Ic)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===g.DSEMI||f===g.SEMI_AND||f===g.SEMI_SEMI_AND))&&i===u&&a===c){if(f===g.DBRACK_START||f===g.DBRACK_END){let d=t[s+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==` +`&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=s+2,this.column=n+2,this.makeToken(f,u+c,s,r,n)}if(i==="("&&this.dparenDepth>0)return this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n);if(i===")"&&this.dparenDepth>1)return this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n);let o=Cc.get(i);if(o!==void 0)return this.pos=s+1,this.column=n+1,this.makeToken(o,i,s,r,n);if(i==="{"){let u=this.scanFdVariable(s);return u!==null?(this.pos=u.end,this.column=n+(u.end-s),{type:g.FD_VARIABLE,value:u.varname,start:s,end:u.end,line:r,column:n}):a==="}"?(this.pos=s+2,this.column=n+2,{type:g.WORD,value:"{}",start:s,end:s+2,line:r,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(s)!==null?this.readWordWithBraceExpansion(s,r,n):this.scanLiteralBraceWord(s)!==null?this.readWordWithBraceExpansion(s,r,n):a!==void 0&&a!==" "&&a!==" "&&a!==` +`?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.LBRACE,"{",s,r,n))}return i==="}"?this.isWordCharFollowing(s+1)?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.RBRACE,"}",s,r,n)):i==="!"?a==="="?(this.pos=s+2,this.column=n+2,this.makeToken(g.WORD,"!=",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.BANG,"!",s,r,n)):this.readWord(s,r,n)}looksLikeNestedSubshells(t){let s=this.input,r=s.length,n=t;for(;n=r)return!1;let i=s[n];if(i==="(")return this.looksLikeNestedSubshells(n+1);let a=/[a-zA-Z_]/.test(i),l=i==="!"||i==="[";if(!a&&!l)return!1;let o=n;for(;o=r)return!1;let c=s[u];if(c==="="&&s[u+1]!=="="||c===` +`||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&s[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;a++}if(a>l){let E=n[a];if(!(E==="("&&a>l&&"@*+?!".includes(n[a-1]))){if(a>=i||E===" "||E===" "||E===` +`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let w=n.slice(l,a);this.pos=a,this.column=r+(a-l);let S=Di.get(w);if(S!==void 0)return{type:S,value:w,start:t,end:a,line:s,column:r};let A=Ci(w);return A>0&&Ii(w.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:w,start:t,end:a,line:s,column:r}:/^[0-9]+$/.test(w)?{type:g.NUMBER,value:w,start:t,end:a,line:s,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:g.NAME,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let o=this.column,u=this.line,c="",f=!1,d=!1,h=!1,p=!1,m=n[a]==='"'||n[a]==="'",y=!1,b=0;for(;a0&&"@*+?!".includes(c[c.length-1])){let w=this.scanExtglobPattern(a);if(w!==null){c+=w.content,a=w.end,o+=w.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let w=a+10){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=E,a++,o++;continue}else if(E==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=E,a++,o++;continue}if(b>0){if(E===` +`)break;c+=E,a++,o++;continue}if(E===" "||E===" "||E===` +`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&a+10&&a0&&D--,D===0&&C==="<"&&n[a+1]==="<"&&n[a+2]!=="<"){let N=a+2,O=!1;for(n[N]==="-"&&(O=!0,N++);n[N]===" "||n[N]===" ";)N++;let{delim:M,endPos:q}=In(n,N);if(M.length>0){c+=n.slice(a+1,q),o+=q-a,T.push({delim:M,stripTabs:O}),a=q;continue}}if(C===` +`&&T.length>0){u++,o=0;let N=a+1;for(let{delim:O,stripTabs:M}of T)for(;!(N>=i);){let q=n.indexOf(` +`,N);q===-1&&(q=i);let J=n.slice(N,q),ce=M?J.replace(/^\t+/,""):J;c+=n.slice(N,Math.min(q+1,i)),q=i;if(N=q+1,ce===O||pe)break}T.length=0,o=0,a=Math.min(N,i);continue}if(C==="'")S=!0,I="";else if(C==='"')A=!0,I="";else if(C==="\\"&&a+10&&a0?x=!0:I==="esac"&&$>0&&($--,x=!1),I="",C==="("?a>0&&n[a-1]==="$"?w++:x||w++:C===")"?x?x=!1:w--:C===";"&&$>0&&(a+10&&a0&&a="0"&&w<="9"){c+=E+w,a+=2,o+=2;continue}}if(E==="`"&&!h){for(c+=E,a++,o++;a=2){if(c[0]==="'"&&c[c.length-1]==="'"){let E=c.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(c=E,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let E=c.slice(1,-1),w=!1;for(let S=0;S0&&Ii(c.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:g.NUMBER,value:c,start:t,end:a,line:s,column:r}:xc(c)?{type:g.NAME,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let s=this.pos,r=this.line,n=this.column,i="";for(;this.posthis.maxHeredocSize)throw new ht(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,n);this.pos&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let l=a;for(this.pos++,this.column++;this.pos=this.input.length)return!1;let s=this.input[t];return!(s===" "||s===" "||s===` +`||s===";"||s==="&"||s==="|"||s==="("||s===")"||s==="<"||s===">")}readWordWithBraceExpansion(t,s,r){let n=this.input,i=n.length,a=t,l=r;for(;a")break;if(u==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,l++;a0;)n[a]==="{"?f++:n[a]==="}"&&f--,a++,l++;continue}a++,l++;continue}if(u==="}"){a++,l++;continue}if(u==="$"&&a+10&&a0&&a0;){let o=s[n];if(o==="{")i++,n++;else if(o==="}")i--,n++;else if(o===","&&i===1)a=!0,n++;else if(o==="."&&n+10;){let a=s[n];if(a==="{")i++,n++;else if(a==="}"){if(i--,i===0)return s.slice(t,n+1);n++}else{if(a===" "||a===" "||a===` +`||a===";"||a==="&"||a==="|")return null;n++}}return null}scanExtglobPattern(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n0;){let a=s[n];if(a==="\\"&&n+1="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===i)return null;let a=s.slice(i,n);if(n>=r||s[n]!=="}"||(n++,n>=r))return null;let l=s[n],o=n+1"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:a,end:n}:null}dollarDparenIsSubshell(t){let s=this.input,r=s.length,n=t+1,i=2,a=!1,l=!1,o=!1;for(;n0;){let u=s[n];if(a){u==="'"&&(a=!1),u===` +`&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===` +`&&(o=!0),n++;continue}if(u==="'"){a=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===` +`&&(o=!0),u==="("){i++,n++;continue}if(u===")"){if(i--,i===1){let c=n+1;if(c0;){let o=s[n];if(a){o==="'"&&(a=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){a=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){i++,n++;continue}if(o===")"){if(i--,i===1){let u=n+1;if(u>=","&=","|=","^="];function es(e){if(e.includes("#")){let[s,r]=e.split("#"),n=Number.parseInt(s,10);if(n<2||n>64)return Number.NaN;if(n<=36){let a=Number.parseInt(r,n);return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:a}let i=0;for(let a of r){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+36;else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(i=i*n+l,i>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return i}if(e.startsWith("0x")||e.startsWith("0X")){let s=Number.parseInt(e.slice(2),16);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let s=Number.parseInt(e,8);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function Wi(e,t,s,r){if(s.slice(r,r+3)!=="$((")return null;let n=r+3,i=1,a=n;for(;n0;)s[n]==="("&&s[n+1]==="("?(i++,n+=2):s[n]===")"&&s[n+1]===")"?(i--,i>0&&(n+=2)):n++;let l=s.slice(a,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Mi(e,t){if(e.slice(t,t+2)!=="$'")return null;let s=t+2,r="";for(;s=e.length}function Oe(e,t,s){return Oc(e,t,s)}function Oc(e,t,s){let{expr:r,pos:n}=ts(e,t,s);for(n=oe(t,n);t[n]===",";){if(n++,ke(t,n))return Ne(",",n);let{expr:a,pos:l}=ts(e,t,n);r={type:"ArithBinary",operator:",",left:r,right:a},n=oe(t,l)}return{expr:r,pos:n}}function ts(e,t,s){let{expr:r,pos:n}=Lc(e,t,s);if(n=oe(t,n),t[n]==="?"){n++;let{expr:i,pos:a}=Oe(e,t,n);if(n=oe(t,a),t[n]===":"){n++;let{expr:l,pos:o}=Oe(e,t,n);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:l},pos:o}}}return{expr:r,pos:n}}function Lc(e,t,s){let{expr:r,pos:n}=Vi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="||";){if(n+=2,ke(t,n))return Ne("||",n);let{expr:a,pos:l}=Vi(e,t,n);r={type:"ArithBinary",operator:"||",left:r,right:a},n=l}return{expr:r,pos:n}}function Vi(e,t,s){let{expr:r,pos:n}=zi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="&&";){if(n+=2,ke(t,n))return Ne("&&",n);let{expr:a,pos:l}=zi(e,t,n);r={type:"ArithBinary",operator:"&&",left:r,right:a},n=l}return{expr:r,pos:n}}function zi(e,t,s){let{expr:r,pos:n}=Bi(e,t,s);for(;n=oe(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,ke(t,n))return Ne("|",n);let{expr:a,pos:l}=Bi(e,t,n);r={type:"ArithBinary",operator:"|",left:r,right:a},n=l}return{expr:r,pos:n}}function Bi(e,t,s){let{expr:r,pos:n}=qi(e,t,s);for(;n=oe(t,n),t[n]==="^";){if(n++,ke(t,n))return Ne("^",n);let{expr:a,pos:l}=qi(e,t,n);r={type:"ArithBinary",operator:"^",left:r,right:a},n=l}return{expr:r,pos:n}}function qi(e,t,s){let{expr:r,pos:n}=ji(e,t,s);for(;n=oe(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,ke(t,n))return Ne("&",n);let{expr:a,pos:l}=ji(e,t,n);r={type:"ArithBinary",operator:"&",left:r,right:a},n=l}return{expr:r,pos:n}}function ji(e,t,s){let{expr:r,pos:n}=Ui(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let i=t.slice(n,n+2);if(n+=2,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=Ui(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Ui(e,t,s){let{expr:r,pos:n}=On(e,t,s);for(;;)if(n=oe(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let i=t.slice(n,n+2);if(n+=2,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=On(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else if(t[n]==="<"||t[n]===">"){let i=t[n];if(n++,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=On(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function On(e,t,s){let{expr:r,pos:n}=Zi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let i=t.slice(n,n+2);if(n+=2,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=Zi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Zi(e,t,s){let{expr:r,pos:n}=Hi(e,t,s);for(;n=oe(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let i=t[n];if(n++,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=Hi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Hi(e,t,s){let{expr:r,pos:n}=ks(e,t,s);for(;;)if(n=oe(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,ke(t,n))return Ne("*",n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:"*",left:r,right:a},n=l}else if(t[n]==="/"||t[n]==="%"){let i=t[n];if(n++,ke(t,n))return Ne(i,n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function ks(e,t,s){let{expr:r,pos:n}=Ln(e,t,s),i=oe(t,n);if(t.slice(i,i+2)==="**"){if(i+=2,ke(t,i))return Ne("**",i);let{expr:l,pos:o}=ks(e,t,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:l},pos:o}}return{expr:r,pos:n}}function Ln(e,t,s){let r=oe(t,s);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let n=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let n=t[r];r++;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}return Wc(e,t,r)}function Tc(e,t){let s=e[t];return s==="$"||s==="`"}function Wc(e,t,s){let{expr:r,pos:n}=Gi(e,t,s,!1),i=[r];for(;Tc(t,n);){let{expr:l,pos:o}=Gi(e,t,n,!0);i.push(l),n=o}i.length>1&&(r={type:"ArithConcat",parts:i});let a;if(t[n]==="["&&r.type==="ArithConcat"){n++;let{expr:l,pos:o}=Oe(e,t,n);a=l,n=o,t[n]==="]"&&n++}if(a&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:a},a=void 0),n=oe(t,n),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let l of Ns)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=ts(e,t,n);return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r.nameExpr,subscript:r.subscript,value:o},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:r.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Gi(e,t,s,r=!1){let n=oe(t,s),i=Wi(Oe,e,t,n);if(i)return i;let a=Mi(t,n);if(a)return a;let l=Fi(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p=194){let n=(r&31)<<6|e[s+1]&63;t+=String.fromCharCode(n),s+=2;continue}t+=String.fromCharCode(r),s++;continue}if((r&240)===224){if(s+2=55296&&n<=57343){t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(n),s+=3;continue}t+=String.fromCharCode(r),s++;continue}if((r&248)===240&&r<=244){if(s+31114111){t+=String.fromCharCode(r),s++;continue}t+=String.fromCodePoint(n),s+=4;continue}t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(r),s++}return t}function Xi(e,t,s){let r=s+1;for(;r0;)t[a]===r?i++:t[a]===n&&i--,i>0&&a++;return i===0?a:-1}function $t(e,t,s){let r=s,n=1;for(;r0;){let i=t[r];if(i==="\\"&&r+10&&r++}return r}function Yi(e,t,s){let r=s,n=!1;for(;r0)l.push(c),o+=2+u.length;else break}l.length>0?(r+=Mc(l),n=o):(r+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(r+="\\u",n+=2):(r+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2({type:"Word",word:R.word(r(e,c,!1,!1,!1))}))},endIndex:n+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Ki(i).map(c=>({type:"Word",word:R.word([R.literal(c)])}))},endIndex:n+1}:null}function Mn(e,t){let s="";for(let r of t.parts)switch(r.type){case"Literal":s+=r.value;break;case"SingleQuoted":s+=`'${r.value}'`;break;case"Escaped":s+=r.value;break;case"DoubleQuoted":s+='"';for(let n of r.parts)n.type==="Literal"||n.type==="Escaped"?s+=n.value:n.type==="ParameterExpansion"&&(s+=`\${${n.parameter}}`);s+='"';break;case"ParameterExpansion":s+=`\${${r.parameter}}`;break;case"Glob":s+=r.pattern;break;case"TildeExpansion":s+="~",r.user&&(s+=r.user);break;case"BraceExpansion":{s+="{";let n=[];for(let i of r.items)if(i.type==="Range"){let a=i.startStr??String(i.start),l=i.endStr??String(i.end);i.step!==void 0?n.push(`${a}..${l}..${i.step}`):n.push(`${a}..${l}`)}else n.push(Mn(e,i.word));n.length===1&&r.items[0].type==="Range"?s+=n[0]:s+=n.join(","),s+="}";break}default:s+=r.type}return s}function sa(e,t){return{[g.LESS]:"<",[g.GREAT]:">",[g.DGREAT]:">>",[g.LESSAND]:"<&",[g.GREATAND]:">&",[g.LESSGREAT]:"<>",[g.CLOBBER]:">|",[g.TLESS]:"<<<",[g.AND_GREAT]:"&>",[g.AND_DGREAT]:"&>>",[g.DLESS]:"<",[g.DLESSDASH]:"<"}[t]||">"}function _s(e){let t=e.current(),s=t.type;if(s===g.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:Li.has(r.type)}if(s===g.FD_VARIABLE){let r=e.peek(1);return Ti.has(r.type)}return Oi.has(s)}function Ps(e){let t=null,s;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(s=e.advance().value);let r=e.advance(),n=sa(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return Vc(e,n,t,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return R.redirection(n,i,t,s)}function Vc(e,t,s,r){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),i=n.value,a=n.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let l=R.redirection(r?"<<-":"<<",R.hereDoc(i,R.word([]),r,a),s);return e.addPendingHeredoc(l,i,r,a),l}function ra(e){let t=e.current().line,s=[],r=null,n=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||_s(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?s.push(zc(e)):i.push(Ps(e));if(e.isWord())r=e.parseWord();else if(s.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let l=e.advance();r=R.word([R.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),_s(e))i.push(Ps(e));else if(e.check(g.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(g.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(g.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(g.LPAREN);let d=Fn(e);e.expect(g.RPAREN);let h=d.map(m=>Mn(e,m)),p=`${f}=(${h.join(" ")})`;n.push(e.parseWordFromString(p,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=R.simpleCommand(r,n,s,i);return a.line=t,a}function zc(e){let t=e.expect(g.ASSIGNMENT_WORD),s=t.value,r=s.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${s}`);let n=r[0],i,a=n.length;if(s[a]==="["){let f=0,d=a+1;for(;a2)break}else f.value==="("&&o++,f.value===")"&&o--,a[l]+=f.value}e.expect(g.DPAREN_END),a[0].trim()&&(r=X(e,a[0].trim())),a[1].trim()&&(n=X(e,a[1].trim())),a[2].trim()&&(i=X(e,a[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(g.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),u=e.parseCompoundList(),e.expect(g.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:n,update:i,body:u,redirections:c,line:s}}function Bn(e,t){e.expect(g.WHILE);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return R.whileNode(s,r,n)}function qn(e,t){e.expect(g.UNTIL);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return R.untilNode(s,r,n)}function jn(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let s=e.parseWord();e.skipNewlines(),e.expect(g.IN),e.skipNewlines();let r=[];for(;!e.check(g.ESAC,g.EOF);){e.checkIterationLimit();let i=e.getPos(),a=Uc(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(g.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return R.caseNode(s,r,n)}function Uc(e){e.check(g.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(g.PIPE));)e.advance();if(t.length===0)return null;e.expect(g.RPAREN),e.skipNewlines();let s=[];for(;!e.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND,g.ESAC,g.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===g.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(g.LPAREN)&&e.peek(1).type===g.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),i=e.parseStatement();if(i&&s.push(i),e.skipSeparators(!1),e.getPos()===n&&!i)break}let r=";;";return e.check(g.DSEMI)?(e.advance(),r=";;"):e.check(g.SEMI_AND)?(e.advance(),r=";&"):e.check(g.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),R.caseItem(t,s,r)}function Un(e,t){e.expect(g.LPAREN);let s=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return R.subshell(s,r)}function Zn(e,t){e.expect(g.LBRACE);let s=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return R.group(s,r)}var Hc=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Gc=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function ia(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function aa(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,s="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,s+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(s+=")"),e.advance();else if(e.isWord())s+=e.advance().value;else if(e.check(g.PIPE))s+="|",e.advance();else break;return s+=")",e.parseWordFromString(s,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function Gn(e){return e.skipNewlines(),Qc(e)}function Qc(e){let t=oa(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let s=oa(e);t={type:"CondOr",left:t,right:s},e.skipNewlines()}return t}function oa(e){let t=Hn(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let s=Hn(e);t={type:"CondAnd",left:t,right:s},e.skipNewlines()}return t}function Hn(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:Hn(e)}):Kc(e)}function Kc(e){if(e.check(g.LPAREN)){e.advance();let t=Gn(e);return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(ia(e)){let t=e.current(),s=t.value;if(Hc.includes(s)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${s}`),ia(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:s,operand:i}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&Gc.includes(e.current().value)){let n=e.advance().value,i;return n==="=~"?i=Xc(e):n==="=="||n==="!="?i=aa(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:r,right:i}}if(e.check(g.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:n}}if(e.check(g.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=aa(e);return{type:"CondBinary",operator:"==",left:r,right:n}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Xc(e){let t=[],s=0,r=-1,n=e.getInput(),i=()=>e.check(g.DBRACK_END)||e.check(g.AND_AND)||e.check(g.OR_OR)||e.check(g.NEWLINE)||e.check(g.EOF);for(;!i();){let a=e.current(),l=r>=0&&a.start>r;if(s===0&&l)break;if(s>0&&l){let o=n.slice(r,a.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),s++,r=o.end}else if(e.check(g.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),s+=2,r=o.end}else if(e.check(g.DPAREN_END))if(s>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),s-=2,r=o.end}else{if(s===1)break;break}else if(e.check(g.RPAREN))if(s>0){let o=e.advance();t.push({type:"Literal",value:")"}),s--,r=o.end}else break;else if(e.check(g.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),r=o.end}else if(e.check(g.SEMICOLON))if(s>0){let o=e.advance();t.push({type:"Literal",value:";"}),r=o.end}else break;else if(s>0&&e.check(g.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),r=o.end}else if(s>0&&e.check(g.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),r=o.end}else if(s>0&&e.check(g.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),r=o.end}else if(s>0&&e.check(g.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),r=o.end}else if(s>0&&e.check(g.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),r=o.end}else if(s>0&&e.check(g.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),r=o.end}else if(s>0&&e.check(g.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),r=o.end}else if(s>0&&e.check(g.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),r=o.end}else if(s>0&&e.check(g.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),r=o.end}else if(s>0&&e.check(g.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),r=o.end}else if(s>0&&e.check(g.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),r=o.end}else if(s>0&&e.check(g.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),r=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function ss(e){return e.length>0?e:[R.literal("")]}function Jc(e,t){let s=1,r=t+1;for(;r0;){let n=e[r];if(n==="\\"){r+=2;continue}if("@*+?!".includes(n)&&r+10;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(s+2,d);return{part:R.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(l===""&&!i&&!a&&t[n]!=="}"){let c=1,f=n;for(;f0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new ye("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(s+2,f);return{part:R.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n=t.length)throw new ye("unexpected EOF while looking for matching '}'",0,0);return{part:R.parameterExpansion(l,u),endIndex:n+1}}function Qn(e,t,s,r,n=!1){let i=s,a=t[i],l=t[i+1]||"";if(a===":"){let o=l;if("-=?+".includes(o)){i+=2;let b=$t(e,t,i),v=t.slice(i,b),E=pt(e,v,!1,!1,!0,!1,n,!1,!1,!0),w=R.word(ss(E));if(o==="-")return{operation:{type:"DefaultValue",word:w,checkEmpty:!0},endIndex:b};if(o==="=")return{operation:{type:"AssignDefault",word:w,checkEmpty:!0},endIndex:b};if(o==="?")return{operation:{type:"ErrorIfUnset",word:w,checkEmpty:!0},endIndex:b};if(o==="+")return{operation:{type:"UseAlternative",word:w,checkEmpty:!0},endIndex:b}}i++;let u=$t(e,t,i),c=t.slice(i,u),f=-1,d=0,h=0;for(let y=0;y0)h--;else{f=y;break}}let p=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Wn(e,p),length:m!==null?Wn(e,m):null},endIndex:u}}if("-=?+".includes(a)){i++;let o=$t(e,t,i),u=t.slice(i,o),c=pt(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=R.word(ss(c));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(a==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(a==="#"||a==="%"){let o=l===a,u=a==="#"?"prefix":"suffix";i+=o?2:1;let c=$t(e,t,i),f=t.slice(i,c),d=pt(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:R.word(ss(d)),side:u,greedy:o},endIndex:c}}if(a==="/"){let o=l==="/";i+=o?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=Yi(e,t,i);let f=t.slice(i,c),d=pt(e,f,!1,!1,!1),h=R.word(ss(d)),p=null,m=c;if(t[c]==="/"){let y=c+1,b=$t(e,t,y),v=t.slice(y,b),E=pt(e,v,!1,!1,!1);p=R.word(ss(E)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:o,anchor:u},endIndex:m}}if(a==="^"||a===","){let o=l===a,u=a==="^"?"upper":"lower";i+=o?2:1;let c=$t(e,t,i),f=t.slice(i,c),d=f?R.word([R.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:i+2}:{operation:null,endIndex:i}}function Kn(e,t,s,r=!1){let n=s+1;if(n>=t.length)return{part:R.literal("$"),endIndex:n};let i=t[n];if(i==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,s)?e.parseCommandSubstitution(t,s):e.parseArithmeticExpansion(t,s);if(i==="["){let a=1,l=n+1;for(;l0;)t[l]==="["?a++:t[l]==="]"&&a--,a>0&&l++;if(a===0){let o=t.slice(n+1,l),u=X(e,o);return{part:R.arithmeticExpansion(u),endIndex:l+1}}}return i==="("?e.parseCommandSubstitution(t,s):i==="{"?tu(e,t,s,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?eu(e,t,s):{part:R.literal("$"),endIndex:n}}function la(e,t){let s=[],r=0,n="",i=()=>{n&&(s.push(R.literal(n)),n="")};for(;r{i&&(r.push(R.literal(i)),i="")};for(;n=2&&t[0]==='"'&&t[t.length-1]==='"'){let p=t.slice(1,-1),m=!1;for(let y=0;y{d&&(c.push(R.literal(d)),d="")};for(;f0?t[f-1]:"";if(f===0||m==="="||n&&m===":"){let b=Xi(e,t,f),v=t[b];if(v===void 0||v==="/"||v===":"){h();let E=t.slice(f+1,b)||null;c.push({type:"TildeExpansion",user:E}),f=b;continue}}}if("@*+?!".includes(p)&&f+1Ri)throw new ye("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Rn)throw new ye(`Maximum parser nesting depth exceeded (${Rn})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,s){if(t.length>Cn)throw new ye(`Input too large: ${t.length} bytes exceeds limit of ${Cn}`,1,1);this._input=t;let r=new $s(t,s);if(this.tokens=r.tokenize(),this.tokens.length>xn)throw new ye(`Too many tokens: ${this.tokens.length} exceeds limit of ${xn}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos0?i.includes(a):!1}expect(t,s){if(this.check(t))return this.advance();let r=this.current();throw new ye(s||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let s=this.current();throw new ye(t,s.line,s.column,s)}skipNewlines(){for(;this.check(g.NEWLINE,g.COMMENT);)this.check(g.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(g.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(g.SEMICOLON,g.COMMENT)){this.advance();continue}if(t&&this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,s,r,n){this.pendingHeredocs.push({redirect:t,delimiter:s,stripTabs:r,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let s=this.advance(),r;t.quoted?r=R.word([R.literal(s.value)]):r=this.parseWordFromString(s.value,!1,!1,!1,!0),t.redirect.target=R.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(g.EOF,g.NEWLINE,g.SEMICOLON,g.AMP,g.AND_AND,g.OR_OR,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.ASSIGNMENT_WORD||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||t===g.FUNCTION||t===g.BANG||t===g.TIME||t===g.IN||t===g.LESS||t===g.GREAT||t===g.DLESS||t===g.DGREAT||t===g.LESSAND||t===g.GREATAND||t===g.LESSGREAT||t===g.DLESSDASH||t===g.CLOBBER||t===g.TLESS||t===g.AND_GREAT||t===g.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.skipSeparators(!1),this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(g.EOF)&&this.advance()}return R.script(t)}checkUnexpectedToken(){let t=this.current().type,s=this.current().value;if((t===g.DO||t===g.DONE||t===g.THEN||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.ESAC)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${s}'`;return this.advance(),R.statement([R.pipeline([R.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:s})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${s}'`),(t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${s}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,s=[],r=[],n=!1,i=this.parsePipeline();for(s.push(i);this.check(g.AND_AND,g.OR_OR);){let o=this.advance();r.push(o.type===g.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();s.push(u)}this.check(g.AMP)&&(this.advance(),n=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,a);return R.statement(s,r,n,void 0,l)}parsePipeline(){let t=!1,s=!1;this.check(g.TIME)&&(this.advance(),t=!0,this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),s=!0));let r=0;for(;this.check(g.BANG);)this.advance(),r++;let n=r%2===1,i=[],a=[],l=this.parseCommand();for(i.push(l);this.check(g.PIPE,g.PIPE_AMP);){let o=this.advance();this.skipNewlines(),a.push(o.type===g.PIPE_AMP);let u=this.parseCommand();i.push(u)}return R.pipeline(i,n,t,s,a.length>0?a:void 0)}parseCommand(){return this.check(g.IF)?Vn(this):this.check(g.FOR)?zn(this):this.check(g.WHILE)?Bn(this):this.check(g.UNTIL)?qn(this):this.check(g.CASE)?jn(this):this.check(g.LPAREN)?Un(this):this.check(g.LBRACE)?Zn(this):this.check(g.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(g.DBRACK_START)?this.parseConditionalCommand():this.check(g.FUNCTION)?this.parseFunctionDef():this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():ra(this)}dparenClosesWithSpacedParens(){let t=1,s=1;for(;snew e,r=>this.error(r))}parseBacktickSubstitution(t,s,r=!1){return Pi(t,s,r,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,s){return ki(t,s)}parseArithmeticExpansion(t,s){let r=s+3,n=1,i=0,a=r;for(;a0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(n++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(n++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(n--,n>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let l=t.slice(r,a),o=this.parseArithmeticExpression(l);return{part:R.arithmeticExpansion(o),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),s="",r=1,n=0,i=!1,a=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,n>0){n--,s+=")";continue}if(this.check(g.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,a=!0;continue}s+=")";continue}if(this.check(g.DPAREN_START))r++,s+="((",this.advance();else if(this.check(g.DPAREN_END))n>=2?(n-=2,s+="))",this.advance()):n===1?(n--,s+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(s+="))"),this.advance());else if(this.check(g.LPAREN))n++,s+="(",this.advance();else if(this.check(g.RPAREN))n>0&&n--,s+=")",this.advance();else{let u=this.current().value,c=s.length>0?s[s.length-1]:"";s.length>0&&!s.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(s))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(s+=" "),s+=u,this.advance()}}a||this.expect(g.DPAREN_END);let l=this.parseArithmeticExpression(s.trim()),o=this.parseOptionalRedirections();return R.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),s=Gn(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return R.conditionalCommand(s,r,t.line)}parseFunctionDef(){let t;if(this.check(g.FUNCTION)){if(this.advance(),this.check(g.NAME)||this.check(g.WORD))t=this.advance().value;else{let n=this.current();throw new ye("Expected function name",n.line,n.column,n)}this.check(g.LPAREN)&&(this.advance(),this.expect(g.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(g.LPAREN),this.expect(g.RPAREN);this.skipNewlines();let s=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return R.functionDef(t,s,r)}parseCompoundCommandBody(t){let s=t?.forFunctionBody;if(this.check(g.LBRACE))return Zn(this,{skipRedirections:s});if(this.check(g.LPAREN))return Un(this,{skipRedirections:s});if(this.check(g.IF))return Vn(this,{skipRedirections:s});if(this.check(g.FOR))return zn(this,{skipRedirections:s});if(this.check(g.WHILE))return Bn(this,{skipRedirections:s});if(this.check(g.UNTIL))return qn(this,{skipRedirections:s});if(this.check(g.CASE))return jn(this,{skipRedirections:s});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),s=[];for(this.skipNewlines();!this.check(g.EOF,g.FI,g.ELSE,g.ELIF,g.THEN,g.DO,g.DONE,g.ESAC,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,n=this.parseStatement();if(n&&s.push(n),this.skipSeparators(),this.pos===r&&!n)break}return t(),s}parseOptionalRedirections(){let t=[];for(;_s(this);){this.checkIterationLimit();let s=this.pos;if(t.push(Ps(this)),this.pos===s)break}return t}parseArithmeticExpression(t){return X(this,t)}};function qe(e,t){return new V().parse(e,t)}var ru="BASH_ALIAS_";function ca(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function ua(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function fa(e,t){return e.env.get(`${ru}${t}`)}function Xn(e,t,s){if(!t.name||!ca(t.name))return t;let r=ua(t.name);if(!r)return t;let n=fa(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new V,a=n,l=n.endsWith(" ");if(!l)for(let f of t.args){let d=ha(f);a+=` ${d}`}let o;try{o=i.parse(a)}catch(f){if(f instanceof ye)throw f;return t}if(o.statements.length!==1||o.statements[0].pipelines.length!==1||o.statements[0].pipelines[0].commands.length!==1)return da(t,n);let u=o.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return da(t,n);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(l&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(ca(f)){let d=ua(f);if(d&&fa(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},p=Xn(e,h,s);p!==h&&(c={...c,name:p.name,args:[...p.args]})}}}return c}catch(i){throw s.delete(r),i}}function da(e,t){let s=t;for(let a of e.args){let l=ha(a);s+=` ${l}`}let r=new V,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function ha(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}var iu=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Yn(e){return iu.get(e)??""}function pa(e){let t=[],s="",r=0;for(;r0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function er(e){let t=[],s="",r=0,n=!1,i=0;for(;ithis.maxOps)throw new Q(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(s=>{let r=s.split("/").pop()||s;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(s,n))return!1}return!0})}matchGlobignorePattern(t,s){return ma(s).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,s){let r=t.map((a,l)=>(s?.[l]??!1)||!this.isGlobPattern(a)?null:this.expand(a)),n=await Promise.all(r.map(a=>a||Promise.resolve(null))),i=[];for(let a=0;a0?i.push(...l):i.push(t[a])}return i}async expand(t){if(this.globstar){let r=t.split("/"),n=0;for(let i of r)if(i==="**"&&(n++,n>ga))throw new Q(`Glob pattern has too many ** segments (max ${ga})`,"glob_operations")}let s;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))s=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");s=await this.expandSimple(r)}return this.filterGlobignore(s)}isGlobstarValid(t){let s=t.split("/");for(let r of s)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let s=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;up.name==="."),h=l.some(p=>p.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d.name,n)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;s===""?p=d.name:s==="/"?p=`/${d.name}`:p=`${s}/${d.name}`,i.length===0?o.push(Promise.resolve([p])):d.isDirectory&&o.push(this.expandSegments(h,p,i))}let f=await Promise.all(o);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d,n)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;s===""?p=d:s==="/"?p=`/${d}`:p=`${s}/${d}`,i.length===0?o.push(Promise.resolve([p])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof Q)throw m}return[]})())}let f=await Promise.all(o);for(let d of f)a.push(...d)}}catch(l){if(l instanceof Q)throw l}return a}async expandRecursive(t){let s=[],r=t.indexOf("**"),n=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(n,a,s),[...new Set(s)].sort()):(await this.walkDirectory(n,a,s),s.sort())}async walkDirectoryMultiGlobstar(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(i){let a=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let l=t==="."?s:`${t}/${s}`,o=await this.expandRecursive(l);r.push(...o);for(let u=0;uthis.walkDirectoryMultiGlobstar(f,s,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),l=[];for(let c of a){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&l.push(f)}catch(h){if(h instanceof Q)throw h}}let o=t==="."?s:`${t}/${s}`,u=await this.expandRecursive(o);r.push(...u);for(let c=0;cthis.walkDirectoryMultiGlobstar(d,s,r)))}}}catch(i){if(i instanceof Q)throw i}}async walkDirectory(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(n),a=[],l=[];for(let o of i){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):s&&this.matchPattern(o.name,s)&&a.push(u)}r.push(...a);for(let o=0;othis.walkDirectory(c,s,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),a=[];for(let o=0;o{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof Q)throw p;return null}}));a.push(...c.filter(f=>f!==null))}for(let o of a)!o.isDirectory&&s&&this.matchPattern(o.name,s)&&r.push(o.path);let l=a.filter(o=>o.isDirectory);for(let o=0;othis.walkDirectory(c.path,s,r)))}}}catch(i){if(i instanceof Q)throw i}}matchPattern(t,s){return this.patternToRegex(s).test(t)}patternToRegex(t){let s=this.patternToRegexStr(t);return ae(`^${s}$`)}patternToRegexStr(t){let s="",r=!1;for(let n=0;nthis.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")s+=`(?:${c})`;else if(i==="*")s+=`(?:${c})*`;else if(i==="+")s+=`(?:${c})+`;else if(i==="?")s+=`(?:${c})?`;else if(i==="!")if(athis.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)s+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${c})).{${p}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=a;continue}}if(i==="*")s+=".*";else if(i==="?")s+=".";else if(i==="["){let a=n+1,l="[";athis.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){s+=u[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){s+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){s+=1,r=a+1;continue}s+=1,r++;continue}if(i==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}};function tr(e){for(let t=0;tn-i)}function Ke(e,t){let s=`${t}_`;for(let r of e.state.env.keys())r.startsWith(s)&&e.state.env.delete(r)}function je(e,t){let s=`${t}_`,r=`${t}__length`,n=[];for(let i of e.state.env.keys())if(i!==r&&i.startsWith(s)){let a=i.slice(s.length);if(a.startsWith("_length"))continue;n.push(a)}return n.sort()}function Ds(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function sr(e){if(e.parts.length<2)return null;let t=e.parts[0],s=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,n=s,i=1;if(s.type==="Literal"&&s.value.startsWith("]")){let f=s.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),n=d,i=2}else return null}else if(t.pattern==="["&&(s.type==="DoubleQuoted"||s.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(s.type==="SingleQuoted")r=s.value;else{r="";for(let d of s.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}n=f,i=2}else if(t.pattern.endsWith("]")){if(s.type!=="Literal"||!s.value.startsWith("=")&&!s.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Ds(r);let a;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?a=n.value.slice(1):a=n.value;let l=a.startsWith("+=");if(!l&&!a.startsWith("="))return null;let o=[],u=l?2:1,c=a.slice(u);c&&o.push({type:"Literal",value:c});for(let f=i+1;f{if(s.type==="Range"){let r=s.startStr??String(s.start),n=s.endStr??String(s.end),i=`${r}..${n}`;return s.step&&(i+=`..${s.step}`),i}return Mt(s.word)}).join(",")}}`}function Mt(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value;break;case"Glob":t+=s.pattern;break;case"SingleQuoted":t+=s.value;break;case"DoubleQuoted":for(let r of s.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=s.value;break;case"BraceExpansion":t+="{",t+=s.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Mt(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",s.user&&(t+=s.user);break}return t}function he(e){return e.get("IFS")??` +`}function we(e){return e.get("IFS")===""}function Is(e){let t=he(e);if(t==="")return!0;for(let s of t)if(s!==" "&&s!==" "&&s!==` +`)return!1;return!0}function wa(e){let t=!1,s=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?s.push(`\\${r}`):r===" "?s.push("\\t"):r===` +`?s.push("\\n"):s.push(r);return t&&s.push("\\-"),s.join("")}function z(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var lu=` +`;function cu(e){return lu.includes(e)}function nr(e){let t=new Set,s=new Set;for(let r of e)cu(r)?t.add(r):s.add(r);return{whitespace:t,nonWhitespace:s}}function rr(e,t,s,r){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:i}=nr(t),a=[],l=[],o=0;for(;o=e.length)return{words:[],wordStarts:[]};if(i.has(e[o]))for(a.push(""),l.push(o),o++;o=s);){let u=o;for(l.push(u);o=e.length)break;for(;o=s);)for(a.push(""),l.push(o),o++;oo&&(a=!0),i>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(r.has(e[i]))for(n.push(""),i++;i=e.length){l=!1;break}let c=i;for(;i=e.length&&i>c&&(l=!0)}return{words:n,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function se(e,t){return Cs(e,t).words}function uu(e,t){for(let s of e)if(t.has(s))return!0;return!1}function Ea(e,t,s){if(t==="")return e;let{whitespace:r,nonWhitespace:n}=nr(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!s&&i>=2){let l=0,o=i-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&n.has(a[a.length-1])){if(!s&&a.length>=2){let o=0,u=a.length-2;for(;u>=0&&a[u]==="\\";)o++,u--;if(o%2===1)return a}let l=a.substring(0,a.length-1);if(!uu(l,n))return l}return a}function ee(e,t){return e.state.namerefs?.has(t)??!1}function ot(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function ba(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function va(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Sa(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ir(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function xs(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],i=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),a=e.state.associativeArrays?.has(n)??!1;return i||a}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function ve(e,t,s=100){if(!ee(e,t)||Sa(e,t))return t;let r=new Set,n=t;for(;s-- >0;){if(r.has(n))return;if(r.add(n),!ee(e,n))return n;let i=e.state.env.get(n);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return n;n=i}}function Nt(e,t){if(ee(e,t))return e.state.env.get(t)}function Aa(e,t,s,r=100){if(!ee(e,t)||Sa(e,t))return t;let n=new Set,i=t;for(;r-- >0;){if(n.has(i))return;if(n.add(i),!ee(e,i))return i;let a=e.state.env.get(i);if(a===void 0||a==="")return s!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&xs(e,s)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function fu(e,t){let s=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,n)=>e.state.env.get(n)??"");return s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,n)=>e.state.env.get(n)??""),s}function F(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,a)=>[a,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,a)=>[a,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,a)=>[a,i]):e.state.associativeArrays?.has(t)?je(e,t).map(i=>[i,e.state.env.get(`${t}_${i}`)??""]):fe(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function Ue(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?je(e,t).length>0:fe(e,t).length>0}async function Y(e,t,s=!0,r=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let a="";return a+="h",e.state.options.errexit&&(a+="e"),e.state.options.noglob&&(a+="f"),e.state.options.nounset&&(a+="u"),e.state.options.verbose&&(a+="v"),e.state.options.xtrace&&(a+="x"),a+="B",e.state.options.noclobber&&(a+="C"),a+="s",a}case"*":{let a=Number.parseInt(e.state.env.get("#")||"0",10);if(a===0)return"";let l=[];for(let o=1;o<=a;o++)l.push(e.state.env.get(String(o))||"");return l.join(z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Ai;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let a=e.state.funcNameStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Ce("FUNCNAME");return""}case"BASH_LINENO":{let a=e.state.callLineStack?.[0];if(a!==void 0)return String(a);if(s&&e.state.options.nounset)throw new Ce("BASH_LINENO");return""}case"BASH_SOURCE":{let a=e.state.sourceStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Ce("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new xe(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let a=n[1],l=n[2];if(ee(e,a)){let f=ve(e,a);if(f&&f!==a){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";a=f}}if(l==="@"||l==="*"){let f=F(e,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=e.state.env.get(a);return d!==void 0?d:""}if(a==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(a==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(a==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(a)){let f=Ds(l);f=fu(e,f);let d=e.state.env.get(`${a}_${f}`);if(d===void 0&&s&&e.state.options.nounset)throw new Ce(`${a}[${l}]`);return d||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new V,d=X(f,l);u=await L(e,d.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=F(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript +`,"";let p=Math.max(...f.map(([y])=>typeof y=="number"?y:0))+1+u;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript +`,""):e.state.env.get(`${a}_${p}`)||""}let c=e.state.env.get(`${a}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(s&&e.state.options.nounset)throw new Ce(`${a}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&s&&e.state.options.nounset)throw new Ce(t);return a||""}if(ee(e,t)){let a=ve(e,t);if(a===void 0)return"";if(a!==t)return await Y(e,a,s,r);let l=e.state.env.get(t);if((l===void 0||l==="")&&s&&e.state.options.nounset)throw new Ce(t);return l||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(a=>a.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(Ue(e,t)){let a=e.state.env.get(`${t}_0`);return a!==void 0?a:""}if(s&&e.state.options.nounset)throw new Ce(t);return""}async function Xe(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],i=r[2];if(ee(e,n)){let o=ve(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(i==="@"||i==="*")return F(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=Ds(i);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(i))l=Number.parseInt(i,10);else try{let o=new V,u=X(o,i);l=await L(e,u.expression)}catch{let o=e.state.env.get(i);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=F(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(ee(e,t)){let n=ve(e,t);return n===void 0||n===t?e.state.env.has(t):Xe(e,n)}return!!(e.state.env.has(t)||Ue(e,t))}async function $a(e,t){let s="",r=0;for(;r0;)t[i]==="{"?n++:t[i]==="}"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let n=1,i=r+2;for(;i0;)t[i]==="("?n++:t[i]===")"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n0;)s[o]==="("&&s[o-1]==="$"||s[o]==="("?l++:s[o]===")"&&l--,o++;let u=s.slice(a+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}a=o}else if(s[a+1]==="{"){let l=1,o=a+2;for(;o0;)s[o]==="{"?l++:s[o]==="}"&&l--,o++;let u=s.slice(a+2,o-1),c=await Y(e,u);i+=c,a=o}else if(/[a-zA-Z_]/.test(s[a+1]||"")){let l=a+1;for(;l{if(o>0){let f=c<0,d=String(Math.abs(c)).padStart(o,"0");return f?`-${d}`:d}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f=t&&f="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let d=s!==void 0?`..${s}`:"";throw new ws(`{${e}..${t}${d}}: invalid sequence`)}let f=[];if(n<=i)for(let d=n,h=0;d<=i&&h=i&&hU(f,t,s)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),n=a+1;continue}}if(i==="\\")if(n+10;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function mu(e){let t=[],s="",r=0,n=0;for(;n0&&s=0;i--){let a=e.slice(i);if(n.test(a))return e.slice(0,i)}return e}function Ft(e,t){let s=Array.from(e.state.env.keys()),r=new Set,n=e.state.associativeArrays??new Set,i=new Set;for(let l of s){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&i.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&i.add(u[1])}let a=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of s)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&r.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&r.add(o[1])}else a(l)||r.add(l);return[...r].sort()}function bu(e,t){let s=(i,a=2)=>String(i).padStart(a,"0");if(e===""){let i=s(t.getHours()),a=s(t.getMinutes()),l=s(t.getSeconds());return`${i}:${a}:${l}`}let r="",n=0;for(;n=e.length){r+="%",n++;continue}let i=e[n+1];switch(i){case"H":r+=s(t.getHours());break;case"M":r+=s(t.getMinutes());break;case"S":r+=s(t.getSeconds());break;case"d":r+=s(t.getDate());break;case"m":r+=s(t.getMonth()+1);break;case"Y":r+=t.getFullYear();break;case"y":r+=s(t.getFullYear()%100);break;case"I":{let a=t.getHours()%12;a===0&&(a=12),r+=s(a);break}case"p":r+=t.getHours()<12?"AM":"PM";break;case"P":r+=t.getHours()<12?"am":"pm";break;case"%":r+="%";break;case"a":{r+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{r+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:r+=`%${i}`}n+=2}else r+=e[n],n++;return r}function is(e,t){let s="",r=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r=t.length){s+="\\",r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",v=r+1;for(;v="0"&&t[v]<="7";)b+=t[v],v++;let E=Number.parseInt(b,8)%256;s+=String.fromCharCode(E),r=v;continue}switch(y){case"\\":s+="\\",r+=2;break;case"a":s+="\x07",r+=2;break;case"e":s+="\x1B",r+=2;break;case"n":s+=` +`,r+=2;break;case"r":s+="\r",r+=2;break;case"$":s+="$",r+=2;break;case"[":case"]":r+=2;break;case"u":s+=n,r+=2;break;case"h":s+=a,r+=2;break;case"H":s+=i,r+=2;break;case"w":s+=u,r+=2;break;case"W":s+=c,r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");s+=`${d[f.getDay()]} ${h[f.getMonth()]} ${b}`,r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");s+=`${b}:${v}:${E}`,r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");s+=`${v}:${E}:${w}`,r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=f.getHours()<12?"AM":"PM";s+=`${v}:${E} ${w}`,r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0");s+=`${b}:${v}`,r+=2;break}case"D":if(r+20&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!s){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.lengthi.startsWith(`${t}_`)&&/^[0-9]+$/.test(i.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return r&&!n&&(s+="a"),n&&(s+="A"),e.state.integerVars?.has(t)&&(s+="i"),ee(e,t)&&(s+="n"),Je(e,t)&&(s+="r"),e.state.exportedVars?.has(t)&&(s+="x"),s}async function ka(e,t,s,r){return e.coverage?.hit("bash:expansion:default_value"),(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):s.effectiveValue}async function _a(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||s.checkEmpty&&r.isEmpty)&&s.word){let a=await n(e,s.word.parts,r.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let d=new V,h=X(d,u);c=await L(e,h.expression)}catch{let d=e.state.env.get(u);c=d?Number.parseInt(d,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,a);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,a);return a}return r.effectiveValue}async function Pa(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||s.checkEmpty&&r.isEmpty){let a=s.word?await n(e,s.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new j(1,"",`bash: ${a} +`)}return r.effectiveValue}async function Da(e,t,s,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):""}async function Ia(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_removal");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let o of s.pattern.parts)if(o.type==="Glob")i+=U(o.pattern,s.greedy,a);else if(o.type==="Literal")i+=U(o.value,s.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=H(o.value);else if(o.type==="DoubleQuoted"){let u=await r(e,o.parts);i+=H(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);i+=U(u,s.greedy,a)}else{let u=await n(e,o);i+=H(u)}if(s.side==="prefix")return ae(`^${i}`,"s").replace(t,"");let l=ae(`${i}$`,"s");if(s.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function Ca(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let u of s.pattern.parts)if(u.type==="Glob")i+=U(u.pattern,!0,a);else if(u.type==="Literal")i+=U(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=H(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=H(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);i+=U(c,!0,a)}else{let c=await n(e,u);i+=H(c)}let l=s.replacement?await r(e,s.replacement.parts):"";if(s.anchor==="start"?i=`^${i}`:s.anchor==="end"&&(i=`${i}$`),i==="")return t;let o=s.all?"gs":"s";try{let u=ae(i,o);if(s.all){let c="",f=0,d=0,h=e.limits.maxStringLength,p=u.exec(t);for(;p!==null&&!(p[0].length===0&&p.index===t.length);){if(c+=t.slice(f,p.index)+l,f=p.index+p[0].length,p[0].length===0&&f++,d++,d%100===0&&c.length>h)throw new Q(`pattern replacement: string length limit exceeded (${h} bytes)`,"string_length");p=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof Q)throw u;return t}}function xa(e,t,s){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let n=r[1],i=F(e,n);return i.length>0?String(i.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&Ue(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...s].length)}async function Ra(e,t,s,r){e.coverage?.hit("bash:expansion:substring");let n=await L(e,r.offset.expression),i=r.length?await L(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let p=1;p<=u;p++)c.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(n<=0)if(d=[f,...c],n<0){if(h=d.length+n,h<0)return""}else h=0;else d=c,h=n-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new j(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution +`);let c=F(e,u),f=0;if(n<0){if(c.length>0){let d=c[c.length-1][0],p=(typeof d=="number"?d:0)+1+n;if(p<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=n),f<0)return"";if(i!==void 0){if(i<0)throw new te(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let l=[...s],o=n;if(o<0&&(o=Math.max(0,l.length+o)),i!==void 0){if(i<0){let u=l.length+i;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+i).join("")}return l.slice(o).join("")}async function Oa(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:case_modification"),s.pattern){let i=e.state.shoptOptions.extglob,a="";for(let f of s.pattern.parts)if(f.type==="Glob")a+=U(f.pattern,!0,i);else if(f.type==="Literal")a+=U(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=H(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=H(d)}else if(f.type==="ParameterExpansion"){let d=await n(e,f);a+=U(d,!0,i)}let l=ae(`^(?:${a})$`),o=s.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!s.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return s.direction==="upper"?s.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):s.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function La(e,t,s,r,n){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&n.operator==="Q")return F(e,i[1]).map(([,u])=>gt(u)).join(" ");if(i&&n.operator==="a")return yt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&n.operator==="a")return yt(e,a[1]);switch(n.operator){case"Q":return r?"":gt(s);case"P":return is(e,s);case"a":return yt(e,t);case"A":return r?"":`${t}=${gt(s)}`;case"E":return s.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return` +`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return r?"":gt(s);case"u":return s.charAt(0).toUpperCase()+s.slice(1);case"U":return s.toUpperCase();case"L":return s.toLowerCase();default:return s}}async function Ta(e,t,s,r,n,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),ee(e,t))return Nt(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(n.innerOp?.type==="UseAlternative")return"";throw new xe(`\${!${t}}`)}let o=s;if(l&&(o===""||o.includes(" ")))throw new xe(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new xe(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return i(e,c,a)}return await Y(e,o)}function Wa(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=F(e,t.array).map(([n])=>String(n));return t.star?r.join(z(e.state.env)):r.join(" ")}function Ma(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let s=Ft(e,t.prefix);return t.star?s.join(z(e.state.env)):s.join(" ")}function Fa(e,t,s,r){let n=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:s};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:s};if(i){let[,a,l]=i,o=F(e,a);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=z(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:r?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:s==="",effectiveValue:s}}function Va(e){let t=0;for(;t0;){let a=e[r];if(a==="\\"&&!n&&r+1y);if(c.length===0){let y=e.state.env.get(l);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await Au(e,u.pattern,s,r));let h=u.replacement?await s(e,u.replacement.parts):"",p=d;u.anchor==="start"?p=`^${d}`:u.anchor==="end"&&(p=`${d}$`);let m=[];try{let y=ae(p,u.all?"g":"");for(let b of f)m.push(y.replace(b,h))}catch{m.push(...f)}if(o){let y=z(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function Ua(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=F(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let d="",h=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")d+=U(m.pattern,u.greedy,h);else if(m.type==="Literal")d+=U(m.value,u.greedy,h);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=H(m.value);else if(m.type==="DoubleQuoted"){let y=await s(e,m.parts);d+=H(y)}else if(m.type==="ParameterExpansion"){let y=await r(e,m);d+=U(y,u.greedy,h)}else{let y=await r(e,m);d+=H(y)}let p=[];for(let m of f)p.push(lt(m,d,u.side,u.greedy));if(o){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}async function Za(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="DefaultValue"&&s.parts[0].operation?.type!=="UseAlternative"&&s.parts[0].operation?.type!=="AssignDefault")return null;let r=s.parts[0],n=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,l=!1;if(i){let o=i[1];l=i[2]==="*";let u=F(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,h])=>h===""),d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let p=u.map(([,m])=>m);if(l){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(o);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let o=r.parameter,u=await Xe(e,o),c=await Y(e,o),f=c==="",d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(a&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=F(e,u);if(f.length>0){let h=f.map(([,p])=>p);if(c||l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Ha(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,l="",o=!1,u=null;for(let m=0;mm);if(d.length===0){let m=e.state.env.get(l);if(m!==void 0)h=[m];else{if(o)return{values:[c+f],quoted:!0};let y=c+f;return{values:y?[y]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,y="",b=e.state.shoptOptions.extglob;if(m.pattern)for(let v of m.pattern.parts)if(v.type==="Glob")y+=U(v.pattern,m.greedy,b);else if(v.type==="Literal")y+=U(v.value,m.greedy,b);else if(v.type==="SingleQuoted"||v.type==="Escaped")y+=H(v.value);else if(v.type==="DoubleQuoted"){let E=await n(e,v.parts);y+=H(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);y+=U(E,m.greedy,b)}else{let E=await r(e,v);y+=H(E)}h=h.map(v=>lt(v,y,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=U(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=U(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=H(E.value);else if(E.type==="DoubleQuoted"){let w=await n(e,E.parts);y+=H(w)}else if(E.type==="ParameterExpansion"){let w=await r(e,E);y+=U(w,!0,e.state.shoptOptions.extglob)}else{let w=await r(e,E);y+=H(w)}let b=m.replacement?await n(e,m.replacement.parts):"",v=y;m.anchor==="start"?v=`^${y}`:m.anchor==="end"&&(v=`${y}$`);try{let E=ae(v,m.all?"g":"");h=h.map(w=>E.replace(w,b))}catch{}}if(o){let m=z(e.state.env);return{values:[c+h.join(m)+f],quoted:!0}}return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function Ga(e,t,s,r){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a="",l=!1;for(let h=0;hh);if(c.length===0){let h=e.state.env.get(a);if(h!==void 0)return{values:[o+h+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let p=o+u;return{values:p?[p]:[],quoted:!0}}if(l){let h=z(e.state.env);return{values:[o+f.join(h)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Qa(e,t,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let n=r.parts[0],i=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let a=i[1],l=i[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(a))throw new j(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution +`);let u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=F(e,a),d=0;if(u<0){if(f.length>0){let p=f[f.length-1][0],y=(typeof p=="number"?p:0)+1+u;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([p])=>typeof p=="number"&&p>=u),d<0&&(d=f.length);let h;if(c!==void 0){if(c<0)throw new te(`${a}[@]: substring expression < 0`);h=f.slice(d,d+c).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Ka(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Transform")return null;let r=s.parts[0],n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let i=n[1],a=n[2]==="*",l=r.operation,o=F(e,i);if(o.length===0){let f=e.state.env.get(i);if(f!==void 0){let d;switch(l.operator){case"a":d="";break;case"P":d=is(e,f);break;case"Q":d=gt(f);break;default:d=f}return{values:[d],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=yt(e,i),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>is(e,f));break;case"Q":c=o.map(([,f])=>gt(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(a){let f=z(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Xa(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion")return null;let r=s.parts[0];if(r.operation)return null;let n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let i=n[1];if(ee(e,i)){let o=Nt(e,i);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let a=F(e,i);if(a.length>0)return{values:a.map(([,o])=>o),quoted:!0};let l=e.state.env.get(i);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Ya(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation)return null;let n=s.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!ee(e,n))return null;let i=Nt(e,n);if(!i)return null;let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!a)return null;let l=a[1],o=F(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function Ja(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],l=a.operation,o=await Y(e,a.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=p;y++)m.push(e.state.env.get(String(y))||"");return o==="*"?{values:[m.join(z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=F(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return $u(e,d,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Nu(e,d,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=yt(e,c),y=d.map(()=>m);return f?{values:[y.join(z(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let p=[];for(let[,m]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let v=await r(e,y,!0);p.push(v)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function $u(e,t,s,r,n){let i=n.offset?await L(e,n.offset.expression):0,a=n.length?await L(e,n.length.expression):void 0,l=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(l=t.findIndex(([h])=>typeof h=="number"&&h>=d),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=i),l<0)return{values:[],quoted:!0};let o;if(a!==void 0){if(a<0)throw new te(`${s}[@]: substring expression < 0`);o=t.slice(l,l+a)}else o=t.slice(l);let u=o.map(([,c])=>c);return r?{values:[u.join(z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function Nu(e,t,s,r,n,i){let a=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||a&&o)&&n.word){let f=await i(e,n.word.parts,!0);return e.state.env.set(`${s}_0`,f),e.state.env.set(`${s}__length`,"1"),{values:[f],quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function eo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let s=t[0],r=s.operation,n=r?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let i=n.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],o=(await Y(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await Xe(e,s.parameter),c=await Y(e,s.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let h=o[1],p=o[2]==="*",m=F(e,h);if(m.length>0){let b=m.map(([,v])=>v);return p?{values:[b.join(z(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(h);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function to(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let s=t[0],n=s.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let i=n.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let l=a.parts[0],u=(await Y(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await Y(e,s.parameter),f=await Xe(e,s.parameter),d=c==="",h=n.checkEmpty??!1,p;if(n.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=u[1],y=u[2]==="*",b=F(e,m);if(b.length>0){let E=b.map(([,w])=>w);return y?{values:[E.join(z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let v=e.state.env.get(m);return v!==void 0?{values:[v],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function so(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),s=[];for(let r=1;r<=t;r++)s.push(e.state.env.get(String(r))||"");return s}async function no(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let v=0;v=d.length)p=[];else if(c!==void 0){let E=c<0?d.length+c:v+c;p=d.slice(v,Math.max(v,E))}else p=d.slice(v)}let m="";for(let v=0;v0)r.push(...i);else{if(s.hasFailglob())throw new ct(n);s.hasNullglob()||r.push(n)}}else r.push(n);return r}async function oo(e,t,s,r){let n=-1,i="",a=!1;for(let v=0;vv);if(u.length===0){let v=e.state.env.get(i);v!==void 0&&(c=[v])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let v of o.pattern.parts)if(v.type==="Glob")f+=U(v.pattern,!0,e.state.shoptOptions.extglob);else if(v.type==="Literal")f+=U(v.value,!0,e.state.shoptOptions.extglob);else if(v.type==="SingleQuoted"||v.type==="Escaped")f+=H(v.value);else if(v.type==="DoubleQuoted"){let E=await s(e,v.parts);f+=H(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);f+=U(E,!0,e.state.shoptOptions.extglob)}else{let E=await r(e,v);f+=H(E)}let d=o.replacement?await s(e,o.replacement.parts):"",h=f;o.anchor==="start"?h=`^${f}`:o.anchor==="end"&&(h=`${f}$`);let p=[];try{let v=ae(h,o.all?"g":"");for(let E of c)p.push(v.replace(E,d))}catch{p.push(...c)}let m=he(e.state.env),y=we(e.state.env);if(a){let v=z(e.state.env),E=p.join(v);return y?{values:E?[E]:[],quoted:!1}:{values:se(E,m),quoted:!1}}if(y)return{values:p,quoted:!1};let b=[];for(let v of p)v===""?b.push(""):b.push(...se(v,m));return{values:b,quoted:!1}}async function lo(e,t,s,r){let n=-1,i="",a=!1;for(let b=0;bb);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")f+=U(b.pattern,o.greedy,d);else if(b.type==="Literal")f+=U(b.value,o.greedy,d);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=H(b.value);else if(b.type==="DoubleQuoted"){let v=await s(e,b.parts);f+=H(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=U(v,o.greedy,d)}else{let v=await r(e,b);f+=H(v)}let h=[];for(let b of c)h.push(lt(b,f,o.side,o.greedy));let p=he(e.state.env),m=we(e.state.env);if(a){let b=z(e.state.env),v=h.join(b);return m?{values:v?[v]:[],quoted:!1}:{values:se(v,p),quoted:!1}}if(m)return{values:h,quoted:!1};let y=[];for(let b of h)b===""?y.push(""):y.push(...se(b,p));return{values:y,quoted:!1}}async function co(e,t,s,r){let n=-1,i=!1;for(let y=0;y=f.length)h=[];else if(u!==void 0){let w=u<0?f.length+u:E+u;h=f.slice(E,Math.max(E,w))}else h=f.slice(E)}let p="";for(let E=0;Eu!=="");else{let u=z(e.state.env),c=n.join(u);o=se(c,i)}else if(a)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=se(u,i);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=se(u,i);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Ts(e,o),quoted:!1}}async function ho(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let s=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let r=s[1],n=s[2]==="*",i=F(e,r),a;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)a=[f];else return{values:[],quoted:!1}}else a=i.map(([,f])=>f);let l=he(e.state.env),o=we(e.state.env),u=Is(e.state.env),c;if(n)if(o)c=a.filter(f=>f!=="");else{let f=z(e.state.env),d=a.join(f);c=se(d,l)}else if(o)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=se(f,l);c.push(...d)}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=se(f,l);c.push(...d)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ts(e,c),quoted:!1}}function po(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let s=t[0].operation,r=Ft(e,s.prefix);if(r.length===0)return{values:[],quoted:!1};let n=he(e.state.env),i=we(e.state.env),a;if(s.star)if(i)a=r;else{let l=z(e.state.env),o=r.join(l);a=se(o,n)}else if(i)a=r;else{a=[];for(let l of r){let o=se(l,n);a.push(...o)}}return{values:a,quoted:!1}}function mo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let s=t[0].operation,n=F(e,s.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let i=he(e.state.env),a=we(e.state.env),l;if(s.star)if(a)l=n;else{let o=z(e.state.env),u=n.join(o);l=se(u,i)}else if(a)l=n;else{l=[];for(let o of n){let u=se(o,i);l.push(...u)}}return{values:l,quoted:!1}}async function go(e,t,s){let r=-1;for(let d=0;dh!=="");else if(c){f=[];for(let h of d){if(h==="")continue;let p=se(h,o);f.push(...p)}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=se(h,o);f.push(...p)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ts(e,f),quoted:!1}}async function Eo(e,t,s){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:n,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ns(r),d=s.hasBraceExpansion(r)?await s.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return _u(e,d,n);let h=await Pu(e,r,l,u,c,s);if(h!==null)return h;let p=await Iu(e,r,s);if(p!==null)return p;let m=await Cu(e,r,s);if(m!==null)return m;let y=await Ru(e,r,s.expandPart);if(y!==null)return wo(e,y);if((i||a||o)&&!we(e.state.env)){let v=he(e.state.env),E=s.buildIfsCharClassPattern(v),w=await s.smartWordSplit(e,r,v,E,s.expandPart);return wo(e,w)}let b=await s.expandWordAsync(e,t);return Ou(e,t,r,b,n,s.expandWordForGlobbing)}async function _u(e,t,s){let r=[];for(let n of t)if(!(!s&&n===""))if(!s&&!e.state.options.noglob&&Ye(n,e.state.shoptOptions.extglob)){let i=await Ws(e,n);r.push(...i)}else r.push(n);return{values:r,quoted:!1}}async function Pu(e,t,s,r,n,i){if(s){let a=Xa(e,t);if(a!==null)return a}{let a=Ya(e,t);if(a!==null)return a}{let a=await Za(e,t);if(a!==null)return a}{let a=await Ha(e,t,s,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Ga(e,t,s,i.expandPart);if(a!==null)return a}{let a=await Qa(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=Ka(e,t);if(a!==null)return a}{let a=await ja(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await Ua(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=Du(e,t);if(a!==null)return a}{let a=await Ja(e,t,n,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await eo(e,t);if(a!==null)return a}{let a=await to(e,t);if(a!==null)return a}return null}function Du(e,t){let s=t[0];if(s.type!=="DoubleQuoted")return null;if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="VarNamePrefix"){let r=s.parts[0].operation,n=Ft(e,r.prefix);return r.star?{values:[n.join(z(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="ArrayKeys"){let r=s.parts[0].operation,i=F(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Iu(e,t,s){{let r=await no(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await ro(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await io(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await ao(e,t,s.expandPart);if(r!==null)return r}return null}async function Cu(e,t,s){{let r=await oo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await lo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await co(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await uo(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await fo(e,t);if(r!==null)return r}{let r=await ho(e,t);if(r!==null)return r}{let r=po(e,t);if(r!==null)return r}{let r=mo(e,t);if(r!==null)return r}{let r=await go(e,t,s.expandPart);if(r!==null)return r}return null}function yo(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;to),a.length===0){let o=e.state.env.get(s.name);o!==void 0&&(a=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let o=1;o<=l;o++)a.push(e.state.env.get(String(o))||"")}if(s.isStar){let l=z(e.state.env),o=a.join(l);return[n+o+i]}if(a.length===0){let l=n+i;return l?[l]:[]}return a.length===1?[n+a[0]+i]:[n+a[0],...a.slice(1,-1),a[a.length-1]+i]}async function Ru(e,t,s){if(t.length<2)return null;let r=!1;for(let o of t)if(yo(o)){r=!0;break}if(!r)return null;let n=he(e.state.env),i=we(e.state.env),a=[];for(let o of t){let u=yo(o);if(u&&o.type==="DoubleQuoted"){let c=await xu(e,o,u,s);a.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await s(e,o);a.push([c])}else if(o.type==="Literal")a.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}else{let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}}let l=[];for(let o of a)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c0)return r;if(s.hasFailglob())throw new ct(t);return s.hasNullglob()?[]:[t]}async function Ou(e,t,s,r,n,i){let a=s.some(l=>l.type==="Glob");if(!e.state.options.noglob&&a){let l=await i(e,t);if(Ye(l,e.state.shoptOptions.extglob)){let u=await Ws(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=lr(r);if(!we(e.state.env)){let u=he(e.state.env);return{values:se(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&Ye(r,e.state.shoptOptions.extglob)){let l=await i(e,t);if(Ye(l,e.state.shoptOptions.extglob)){let o=await Ws(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(r===""&&!n)return{values:[],quoted:!1};if(a&&!n){let l=lr(r);if(!we(e.state.env)){let o=he(e.state.env);return{values:se(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[r],quoted:n}}async function vo(e,t){let s=t.operation;if(!s||s.type!=="DefaultValue"&&s.type!=="AssignDefault"&&s.type!=="UseAlternative")return null;let r=s.word;if(!r||r.parts.length===0)return null;let n=await Xe(e,t.parameter),a=await Y(e,t.parameter,!1)==="",l=s.checkEmpty??!1,o;return s.type==="UseAlternative"?o=n&&!(l&&a):o=!n||l&&a,o?r.parts:null}function Lu(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(s=>s.type==="Literal"):!1}async function Tu(e,t){if(t.type!=="ParameterExpansion")return null;let s=await vo(e,t);if(!s||s.length<=1)return null;let r=s.some(i=>Lu(i)),n=s.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&n?s:null}function Wu(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?tr(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&ya(e))}async function So(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await vo(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return bo(e,h,s,r,n)}let i=[],a=!1;for(let d of t){let h=Wu(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Tu(e,d):null,y=await n(e,d);i.push({value:y,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(a=!0)}if(!a){let d=i.map(h=>h.value).join("");return d?[d]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):d.value!==""?(o!==""&&l.push(o),o=d.value,c=!1,f=!1):(o+=d.value,f=!1):(o+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await bo(e,d.mixedDefaultParts,s,r,n);if(h.length!==0)if(h.length===1)o+=h[0],u=!0;else{o+=h[0],l.push(o),u=!0;for(let p=1;p0&&t.includes(e[0])}async function bo(e,t,s,r,n){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),h=await n(e,c);i.push({value:h,isSplittable:d})}let a=[],l="",o=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(l!==""&&a.push(l),l=c.value,u=!1):l+=c.value;else{Mu(c.value,s)&&l!==""&&(a.push(l),l="",o=!0);let{words:d,hadTrailingDelimiter:h}=Cs(c.value,s);if(d.length===0)h&&(u=!0);else if(d.length===1)l+=d[0],o=!0,u=h;else{l+=d[0],a.push(l),o=!0;for(let p=1;pt)throw new Q(`${s}: string length limit exceeded (${t} bytes)`,"string_length")}async function He(e,t,s=!1){let r=[];for(let n of t)r.push(await Te(e,n,s));return r.join("")}function Fu(e){return $o(e)}function No(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Fu(t))return!1;return!0}function Vu(e,t,s=!1){let r=Ao(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return s?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return cr(e,t.pattern);default:return null}}async function W(e,t){return fr(e,t)}async function ko(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped")s.push(`\\${r.value}`);else if(r.type==="SingleQuoted")s.push(r.value);else if(r.type==="DoubleQuoted"){let n=await He(e,r.parts);s.push(n)}else if(r.type==="TildeExpansion"){let n=await Te(e,r);s.push(rs(n))}else s.push(await Te(e,r));return s.join("")}async function _o(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped"){let n=r.value;"()|*?[]".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="SingleQuoted")s.push(Le(r.value));else if(r.type==="DoubleQuoted"){let n=await He(e,r.parts);s.push(Le(n))}else s.push(await Te(e,r));return s.join("")}async function Po(e,t){let s=[];for(let r of t.parts)if(r.type==="SingleQuoted")s.push(Le(r.value));else if(r.type==="Escaped"){let n=r.value;"*?[]\\()|".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="DoubleQuoted"){let n=await He(e,r.parts);s.push(Le(n))}else r.type==="Glob"?Va(r.pattern)?s.push(await Ba(e,r.pattern)):s.push(cr(e,r.pattern)):r.type==="Literal"?s.push(r.value):s.push(await Te(e,r));return s.join("")}function Fs(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Fs(t.parts))return!0;return!1}var ur=1e5;async function Do(e,t,s={count:0}){if(s.count>ur)return[[]];let r=[[]];for(let n of t)if(n.type==="BraceExpansion"){let i=[],a=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=or(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let d of f.expanded)s.count++,i.push(d);else{a=!0,l=f.literal;break}}else{let f=await Do(e,c.word.parts,s);for(let d of f){s.count++;let h=[];for(let p of d)typeof p=="string"?h.push(p):h.push(await Te(e,p));i.push(h.join(""))}}if(a){for(let c of r)s.count++,c.push(l);continue}if(r.length*i.length>e.limits.maxBraceExpansionResults||s.count>ur)return r;let u=[];for(let c of r)for(let f of i){if(s.count++,s.count>ur)return u.length>0?u:r;u.push([...c,f])}r=u}else for(let i of r)s.count++,i.push(n);return r}async function Io(e,t){let s=t.parts;if(!Fs(s))return[await W(e,t)];let r=await Do(e,s),n=[];for(let i of r){let a=[];for(let l of i)typeof l=="string"?a.push(l):a.push(await Te(e,l));n.push(qa(e,a.join("")))}return n}function zu(){return{expandWordAsync:fr,expandWordForGlobbing:Po,expandWordWithBracesAsync:Io,expandWordPartsAsync:He,expandPart:Te,expandParameterAsync:Ms,hasBraceExpansion:Fs,evaluateArithmetic:L,buildIfsCharClassPattern:wa,smartWordSplit:So}}async function et(e,t){return Eo(e,t,zu())}function Bu(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Vs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(n){for(let i of n)if(i.type==="DoubleQuoted"){for(let a of i.parts)if(a.type==="ParameterExpansion"&&a.parameter==="@"&&!a.operation)return!0}return!1}return r(t.parts)}async function zs(e,t){if(Vs(e,t))return{error:`bash: $@: ambiguous redirect +`};let s=t.parts,{hasQuoted:r}=ns(s);if(Fs(s)&&(await Io(e,t)).length>1)return{error:`bash: ${s.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.items.map(m=>{if(m.type==="Range"){let y=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${y}`}return m.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect +`};let n=await fr(e,t),{hasParamExpansion:i,hasCommandSub:a}=ns(s);if((i||a)&&!r&&!we(e.state.env)){let f=he(e.state.env);if(se(n,f).length>1)return{error:`bash: $${Bu(s)}: ambiguous redirect +`}}if(r||e.state.options.noglob)return{target:n};let o=await Po(e,t);if(!Ye(o,e.state.shoptOptions.extglob))return{target:n};let u=new mt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n} +`}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect +`}}async function fr(e,t){let s=t.parts,r=s.length;if(r===1){let a=await Te(e,s[0]);return wt(a,e.limits.maxStringLength,"word expansion"),a}let n=[];for(let a=0;a=a)throw new Q(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=i+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let d=await e.executeScript(t.body),h=d.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=h,e.state.env.set("?",String(h)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr),e.state.bashPid=o,e.substitutionDepth=l;let p=d.stdout.replace(/\n+$/,"");return wt(p,e.limits.maxStringLength,"command substitution"),p}catch(d){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,d instanceof Q)throw d;if(d instanceof j){e.state.lastExitCode=d.exitCode,e.state.env.set("?",String(d.exitCode)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr);let h=d.stdout.replace(/\n+$/,"");return wt(h,e.limits.maxStringLength,"command substitution"),h}throw d}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let a=await $a(e,n),l=new V,o=X(l,a);return String(await L(e,o.expression,!0))}return String(await L(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let i of t.items)if(i.type==="Range"){let a=or(i.start,i.end,i.step,i.startStr,i.endStr);if(a.expanded)n.push(...a.expanded);else return a.literal}else n.push(await W(e,i.word));return n.join(" ")}default:return""}}async function Ms(e,t,s=!1){let{parameter:r}=t,{operation:n}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await ar(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ee(e,r)){let d=ve(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await ar(e,m);r=`${p}[${b}]`}}}}let a=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await Y(e,r,!a);if(!n)return l;let o=!await Xe(e,r),{isEmpty:u,effectiveValue:c}=Fa(e,r,l,s),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:s};switch(n.type){case"DefaultValue":return ka(e,n,f,He);case"AssignDefault":return _a(e,r,n,f,He);case"ErrorIfUnset":return Pa(e,r,n,f,He);case"UseAlternative":return Da(e,n,f,He);case"PatternRemoval":{let d=await Ia(e,l,n,He,Te);return wt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await Ca(e,l,n,He,Te);return wt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return xa(e,r,l);case"LengthSliceError":throw new xe(r);case"BadSubstitution":throw new xe(n.text);case"Substring":return Ra(e,r,l,n);case"CaseModification":{let d=await Oa(e,l,n,He,Ms);return wt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return La(e,r,l,o,n);case"Indirection":return Ta(e,r,l,o,n,Ms,s);case"ArrayKeys":return Wa(e,n);case"VarNamePrefix":return Ma(e,n);default:return l}}function qu(e,t,s){switch(s){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new te("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new te("division by 0");return e%t;case"**":if(t<0)throw new te("exponent less than 0");return e**t;case"<<":return e<>":return e>>t;case"<":return e":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function Co(e,t,s){switch(s){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function ju(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Uu(e,t){let s=e.state.env.get(t);if(s!==void 0)return s;let r=e.state.env.get(`${t}_0`);return r!==void 0?r:await Y(e,t)}function Zu(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let s=e.trim();if(!s)return 0;try{let r=new V,{expr:n,pos:i}=Oe(r,s,0);if(i100)throw new te("maximum variable indirection depth exceeded");if(s.has(t))return 0;s.add(t);let n=await Uu(e,t);if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n.trim()))return i;let a=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await hr(e,a,s,r+1);let l=new V,{expr:o,pos:u}=Oe(l,a,0);if(u0&&(r===-1||d64)return 0;let i=`${n}#${t.value}`;return es(i)}case"ArithDynamicNumber":{let n=await Bs(e,t.prefix)+t.suffix;return es(n)}case"ArithArrayElement":{let r=e.state.associativeArrays?.has(t.array),n=async i=>{let a=e.state.env.get(i);return a!==void 0?await dr(e,a):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(r&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(r&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let i=await Y(e,t.index.name);return await n(`${t.array}_${i}`)}if(t.index){let i=await L(e,t.index,s);if(i<0){let o=F(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript +`,0;let f=Math.max(...o.map(([d])=>typeof d=="number"?d:0))+1+i;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript +`,0;i=f}let a=`${t.array}_${i}`,l=e.state.env.get(a);if(l!==void 0)return dr(e,l);if(i===0){let o=e.state.env.get(t.array);if(o!==void 0)return dr(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new Ce(`${t.array}[${i}]`);return 0}return 0}case"ArithDoubleSubscript":throw new te("double subscript","","");case"ArithNumberSubscript":throw new te(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new te(t.message,"","",!0);case"ArithSingleQuote":{if(s)throw new te(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await L(e,t.left,s)||await L(e,t.right,s)?1:0;if(t.operator==="&&")return await L(e,t.left,s)&&await L(e,t.right,s)?1:0;let r=await L(e,t.left,s),n=await L(e,t.right,s);return qu(r,n,t.operator)}case"ArithUnary":{let r=await L(e,t.operand,s);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,i=Number.parseInt(await Y(e,n),10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,i=e.state.associativeArrays?.has(n),a;if(t.operand.stringKey!==void 0)a=`${n}_${t.operand.stringKey}`;else if(i&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)a=`${n}_${t.operand.index.name}`;else if(i&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await Y(e,t.operand.index.name);a=`${n}_${u}`}else if(t.operand.index){let u=await L(e,t.operand.index,s);a=`${n}_${u}`}else return r;let l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let i of t.operand.parts)n+=await Vt(e,i,s);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let i of t.operand.nameExpr.parts)n+=await Vt(e,i,s);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await Y(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=await L(e,t.operand.subscript,s),a=`${n}_${i}`,l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}}return r}return ju(r,t.operator)}case"ArithTernary":return await L(e,t.condition,s)?await L(e,t.consequent,s):await L(e,t.alternate,s);case"ArithAssignment":{let r=t.variable,n=r;if(t.stringKey!==void 0)n=`${r}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(r);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${r}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await Y(e,t.subscript.name);n=`${r}_${u||"\\"}`}else if(o){let u=await L(e,t.subscript,s);n=`${r}_${u}`}else{let u=await L(e,t.subscript,s);if(u<0){let c=F(e,r);c.length>0&&(u=Math.max(...c.map(([d])=>typeof d=="number"?d:0))+1+u)}n=`${r}_${u}`}}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await L(e,t.value,s),l=Co(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await L(e,t.expression,s);case"ArithConcat":{let r="";for(let n of t.parts)r+=await Vt(e,n,s);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?await hr(e,r):Number.parseInt(r,10)||0}case"ArithDynamicAssignment":{let r="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)r+=await Vt(e,o,s);else t.target.type==="ArithVariable"&&(r=t.target.hasDollarPrefix?await Y(e,t.target.name):t.target.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=r;if(t.subscript){let o=await L(e,t.subscript,s);n=`${r}_${o}`}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await L(e,t.value,s),l=Co(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let r="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)r+=await Vt(e,l,s);else t.nameExpr.type==="ArithVariable"&&(r=t.nameExpr.hasDollarPrefix?await Y(e,t.nameExpr.name):t.nameExpr.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=await L(e,t.subscript,s),i=`${r}_${n}`,a=e.state.env.get(i);return a!==void 0?Zu(a):0}default:return 0}}async function Vt(e,t,s=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await L(e,t,s));case"ArithVariable":return t.hasDollarPrefix?await Y(e,t.name):t.name;case"ArithSpecialVar":return await Y(e,t.name);case"ArithBracedExpansion":return await Bs(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let r="";for(let n of t.parts)r+=await Vt(e,n,s);return r}default:return String(await L(e,t,s))}}async function xo(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],a=!1,l="",o=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(l||o)&&(i.push(l),l="",o=!1):h&&(l+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(l))l+=Mt({type:"Word",parts:[c]});else{(l||o)&&(i.push(l),l="",o=!1);let d=await et(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(o=!0);let f=await W(e,{type:"Word",parts:[c]});l+=f}(l||o)&&i.push(l);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${n}=(${u.join(" ")})`}async function Ro(e,t){let s=-1,r=-1,n=!1;for(let m=0;m0?await W(e,d):"";return`${f}${n?"+=":"="}${h}`}var Hu=["tar","yq","xan","sqlite3","python3","python"];function Oo(e){return Hu.includes(e)}var G=Object.freeze({stdout:"",stderr:"",exitCode:0});function Z(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function de(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function tt(e,t,s="",r=""){throw new Q(e,t,s,r)}function be(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Q(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function pr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ut;return G}if(t.length>1)throw new j(1,"",`bash: break: too many arguments +`);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(128,"",`bash: break: ${t[0]}: numeric argument required +`);s=r}throw new De(s)}async function mr(e,t){let s,r=!1,n=!1,i=0;for(;ih);for(let h of d){let p=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(p)).isDirectory){s=p,r=!0;break}}catch{}}}}let o=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of o)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${s}: Not a directory `)}catch{return _(`bash: cd: ${s}: No such file or directory -`)}}let c=u||"/";if(r)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),F(n?`${c} -`:"")}function Ls(e,t){return e.fs.resolvePath(e.state.cwd,t)}var la=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Bt(e){return la.includes(e)}async function jt(e,t,s){let n=Ls(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(n);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var ca=["-nt","-ot","-ef"];function Ht(e){return ca.includes(e)}async function Ut(e,t,s,n){let r=Ls(e,s),i=Ls(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtimes;case"-ge":return t>=s}}function vt(e){return e==="="||e==="=="||e==="!="}function Gt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=at(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var fa=new Set(["-z","-n"]);function Kt(e){return fa.has(e)}function Xt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Yt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,u)=>e.state.env.get(u)||""),e.state.env.has(`${n}_${o}`)}let a;try{let o=new V,l=Q(o,r);a=await j(e,l.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env.get(r);a=o?Number.parseInt(o,10):0}}if(a<0){let o=se(e,n),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript -`,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript -`,!1}return e.state.env.has(`${n}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Fe(e,t).length>0:se(e,t).length>0}async function Me(e,t){switch(t.type){case"CondBinary":{let s=await x(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await x(e,t.right);r=qn(i)}else r=await Kn(e,t.right);else vt(t.operator)&&!n?r=await Xn(e,t.right):r=await x(e,t.right);if(vt(t.operator)){let i=e.state.shoptOptions.nocasematch;return Gt(t.operator,s,r,!n,i,!0)}if(Zt(t.operator))return qt(t.operator,await mr(e,s),await mr(e,r));if(Ht(t.operator))return Ut(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=ma(r),l=mt(a,i?"i":"").match(s);if(_e(e,"BASH_REMATCH"),l)for(let u=0;u":return s>r;default:return!1}}case"CondUnary":{let s=await x(e,t.operand);return Bt(t.operator)?jt(e,t.operator,s):Kt(t.operator)?Xt(t.operator,s):t.operator==="-v"?await Yt(e,s):t.operator==="-o"?Ws(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await x(e,t.operand.expression.word)})`!=="":!await Me(e,t.operand);case"CondAnd":return await Me(e,t.left)?await Me(e,t.right):!1;case"CondOr":return await Me(e,t.left)?!0:await Me(e,t.right);case"CondGroup":return await Me(e,t.expression);case"CondWord":return await x(e,t.word)!=="";default:return!1}}async function bt(e,t){if(t.length===0)return P("","",1);if(t.length===1)return X(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?_(`test: '(' without matching ')' -`,2):Bt(n)?X(await jt(e,n,r)):Kt(n)?X(Xt(n,r)):n==="!"?X(!r):n==="-v"?X(await Yt(e,r)):n==="-o"?X(Ws(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?_(`test: ${n}: unary operator expected -`,2):P("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(vt(r))return X(Gt(r,n,i));if(Zt(r)){let a=Qt(n),o=Qt(i);return!a.valid||!o.valid?P("","",2):X(qt(r,a.value,o.value))}if(Ht(r))return X(await Ut(e,r,n,i));switch(r){case"-a":return X(n!==""&&i!=="");case"-o":return X(n!==""||i!=="");case">":return X(n>i);case"<":return X(nwr(c,t)),u=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${u})`;else if(r==="*")s+=`(?:${u})*`;else if(r==="+")s+=`(?:${u})+`;else if(r==="?")s+=`(?:${u})?`;else if(r==="!")if(i$r(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let y=[];h>0&&y.push(`.{0,${h-1}}`),y.push(`.{${h+1},}`),y.push(`(?!(?:${u})).{${h}}`),s+=`(?:${y.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;n=i;continue}}if(r==="\\")if(n+10;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function br(e){let t=[],s="",n=0,r=0;for(;r$r(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){s+=l[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Ws(e,t){let n=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return n?n():!1}async function mr(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return yr(t);try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{return yr(t)}}function pa(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function yr(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=pa(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function Qt(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ma(e){let t="",s=0;for(;s=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s=f&&e.state.env.set(`${n}__length`,String(c+1))}else a!==void 0&&e.state.env.set(n,a);return l&&ce(e,n),null}function ze(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function ot(e,t){return e.state.localVarDepth?.get(t)}function es(e,t){e.state.localVarDepth?.delete(t)}function Ar(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function ts(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function _r(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var Ms=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Cr(e){return Ms.has(e)}var zs=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),lt=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function qe(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory -`;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file -`}catch{}return null}function Ve(e){let s=Math.min(e.length,8192);for(let n=0;n127)return"utf8";return"binary"}function va(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let u=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(u)||u<0)return null;let c=o.slice(l+1);return{path:i,position:u,content:c}}async function Pr(e,t){let s=new Map;for(let n=0;n&"||r.operator==="<&"){if(Cs(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect -`};s.set(n,await x(e,r.target))}else{let a=await Wt(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function ba(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function ss(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await x(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=ba(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await x(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(ie(e),e.state.fileDescriptors.set(n,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),ie(e),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")ie(e),e.state.fileDescriptors.set(n,`${r} -`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);ie(e),e.state.fileDescriptors.set(n,a)}catch{return P("",`bash: ${r}: No such file or directory -`,1)}}}return null}async function Ne(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await x(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await Wt(e,s.target);if("error"in o)return P("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";if(i.includes("\0"))return P("",`bash: ${r}: No such file or directory -`,1);try{let o=await e.fs.stat(i);if(o.isDirectory)return P("",`bash: ${r}: Is a directory -`,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return P("",`bash: ${r}: cannot overwrite existing file -`,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return P("",`bash: /dev/full: No space left on device -`,1)}return null}async function q(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t,l=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=h=>l;for(let h=0;h&"||y.operator==="<&"){if(Cs(e,y.target)){i+=`bash: $@: ambiguous redirect -`,a=1,r="";continue}p=await x(e,y.target)}else{let g=await Wt(e,y.target);if("error"in g){i+=g.error,a=1,r="";continue}p=g.target}if(!y.fdVariable){if(p.includes("\0")){i+=`bash: ${p.replace(/\0/g,"")}: No such file or directory -`,a=1,r="";continue}switch(y.operator){case">":case">|":{let $=y.fd??1,g=y.operator===">|";if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1,r="";break}let b=e.fs.resolvePath(e.state.cwd,p),m=await qe(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1,r="";break}await e.fs.writeFile(b,r,u(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1;break}if(p==="/dev/null")i="";else{let b=e.fs.resolvePath(e.state.cwd,p),m=await qe(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1;break}await e.fs.writeFile(b,i,Ve(i)),i=""}}break}case">>":{let $=y.fd??1;if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1,r="";break}let g=e.fs.resolvePath(e.state.cwd,p),b=await qe(e,g,p,{});if(b){i+=b,a=1,r="";break}await e.fs.appendFile(g,r,u(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1;break}let g=e.fs.resolvePath(e.state.cwd,p),b=await qe(e,g,p,{});if(b){i+=b,a=1;break}await e.fs.appendFile(g,i,Ve(i)),i=""}break}case">&":case"<&":{let $=y.fd??1;if(p==="-")break;if(p.endsWith("-")){let g=p.slice(0,-1),b=Number.parseInt(g,10);if(!Number.isNaN(b)){let m=e.state.fileDescriptors?.get(b);m!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,m),b>=3&&e.state.fileDescriptors?.delete(b)):b===1||b===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupout__:${b}`)):b===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupin__:${b}`)):b>=3&&(i+=`bash: ${b}: Bad file descriptor -`,a=1)}break}if(p==="2"||p==="&2")$===1&&(i+=r,r="");else if(p==="1"||p==="&1")r+=i,i="";else{let g=Number.parseInt(p,10);if(Number.isNaN(g)){if(y.operator===">&"){let b=e.fs.resolvePath(e.state.cwd,p),m=await qe(e,b,p,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}if(y.fd==null){let v=r+i;await e.fs.writeFile(b,v,u(v)),r="",i=""}else $===1?(await e.fs.writeFile(b,r,u(r)),r=""):$===2&&(await e.fs.writeFile(b,i,Ve(i)),i="")}}else{let b=e.state.fileDescriptors?.get(g);if(b?.startsWith("__file__:")){let m=b.slice(9);$===1?(await e.fs.appendFile(m,r,u(r)),r=""):$===2&&(await e.fs.appendFile(m,i,Ve(i)),i="")}else if(b?.startsWith("__rw__:")){let m=va(b);m&&($===1?(await e.fs.appendFile(m.path,r,u(r)),r=""):$===2&&(await e.fs.appendFile(m.path,i,Ve(i)),i=""))}else if(b?.startsWith("__dupout__:")){let m=Number.parseInt(b.slice(11),10);if(m!==1)if(m===2)$===1&&(i+=r,r="");else{let v=e.state.fileDescriptors?.get(m);if(v?.startsWith("__file__:")){let E=v.slice(9);$===1?(await e.fs.appendFile(E,r,u(r)),r=""):$===2&&(await e.fs.appendFile(E,i,Ve(i)),i="")}}}else b?.startsWith("__dupin__:")?(i+=`bash: ${g}: Bad file descriptor -`,a=1,r=""):g>=3&&(i+=`bash: ${g}: Bad file descriptor -`,a=1,r="")}}break}case"&>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device -`,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await qe(e,$,p,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.writeFile($,b,u(b)),r="",i="";break}case"&>>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device -`,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await qe(e,$,p,{});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.appendFile($,b,u(b)),r="",i="";break}}}}let c=e.state.fileDescriptors?.get(1);if(c){if(c==="__dupout__:2")i+=r,r="";else if(c.startsWith("__file__:")){let h=c.slice(9);await e.fs.appendFile(h,r,u(r)),r=""}else if(c.startsWith("__file_append__:")){let h=c.slice(16);await e.fs.appendFile(h,r,u(r)),r=""}}let f=e.state.fileDescriptors?.get(2);if(f){if(f==="__dupout__:1")r+=i,i="";else if(f.startsWith("__file__:")){let h=f.slice(9);await e.fs.appendFile(h,i,Ve(i)),i=""}else if(f.startsWith("__file_append__:")){let h=f.slice(16);await e.fs.appendFile(h,i,Ve(i)),i=""}}let d=P(r,i,a);return t.stdoutKind&&(d.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(d.stdoutEncoding="binary"),d}function kr(e,t){if(e.state.options.posix&&Ms.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin -`;throw new B(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),W}async function $a(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await x(e,r.content);r.stripTabs&&(i=i.split(` -`).map(o=>o.replace(/^\t+/,"")).join(` -`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await x(e,n.target)} -`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await x(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function ns(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Pe(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(_r(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:o,error:l}=await Pr(e,t.redirections);if(l)return a(),P("",l,1);try{let u=await $a(e,t.redirections),c=n||u,f=await e.executeCommand(t.body,c);return a(),q(e,f,t.redirections,o)}catch(u){if(a(),u instanceof le){let c=P(u.stdout,u.stderr,u.exitCode);return q(e,c,t.redirections,o)}throw u}}var Or=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Bs=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],Ea=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],Sa=Bs;async function js(e,t){let s=[],n=null,r="",i="",a=null,o=!1,l=!1,u=!1,c=null,f=null,d=null,h=[],y=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let m=0;m=t.length)return _(`compgen: -A: option requires an argument -`,2);let E=t[m];if(!y.includes(E))return _(`compgen: ${E}: invalid action name -`,2);s.push(E)}else if(v==="-W"){if(m++,m>=t.length)return _(`compgen: -W: option requires an argument -`,2);n=t[m]}else if(v==="-P"){if(m++,m>=t.length)return _(`compgen: -P: option requires an argument -`,2);r=t[m]}else if(v==="-S"){if(m++,m>=t.length)return _(`compgen: -S: option requires an argument -`,2);i=t[m]}else if(v==="-o"){if(m++,m>=t.length)return _(`compgen: -o: option requires an argument -`,2);let E=t[m];if(E==="plusdirs")o=!0;else if(E==="dirnames")l=!0;else if(E==="default")u=!0;else if(!(E==="filenames"||E==="nospace"||E==="bashdefault"||E==="noquote"))return _(`compgen: ${E}: invalid option name -`,2)}else if(v==="-F"){if(m++,m>=t.length)return _(`compgen: -F: option requires an argument -`,2);f=t[m]}else if(v==="-C"){if(m++,m>=t.length)return _(`compgen: -C: option requires an argument -`,2);d=t[m]}else if(v==="-X"){if(m++,m>=t.length)return _(`compgen: -X: option requires an argument -`,2);c=t[m]}else if(v==="-G"){if(m++,m>=t.length)return _(`compgen: -G: option requires an argument -`,2)}else if(v==="--"){h.push(...t.slice(m+1));break}else v.startsWith("-")||h.push(v)}a=h[0]??null;let p=[];if(l){let m=await Vs(e,a);p.push(...m)}if(u){let m=await Nr(e,a);p.push(...m)}for(let m of s)if(m==="variable"){let v=Aa(e,a);p.push(...v)}else if(m==="export"){let v=_a(e,a);p.push(...v)}else if(m==="function"){let v=Ca(e,a);p.push(...v)}else if(m==="builtin"){let v=Pa(a);p.push(...v)}else if(m==="keyword"){let v=ka(a);p.push(...v)}else if(m==="alias"){let v=Na(e,a);p.push(...v)}else if(m==="shopt"){let v=Oa(a);p.push(...v)}else if(m==="helptopic"){let v=Da(a);p.push(...v)}else if(m==="directory"){let v=await Vs(e,a);p.push(...v)}else if(m==="file"){let v=await Nr(e,a);p.push(...v)}else if(m==="user"){let v=Ta(a);p.push(...v)}else if(m==="command"){let v=await xa(e,a);p.push(...v)}if(n!==null)try{let m=await Ia(e,n),v=Ra(e,m);for(let E of v)(a===null||E.startsWith(a))&&p.push(E)}catch{return P("","",1)}if(o){let m=await Vs(e,a);for(let v of m)p.includes(v)||p.push(v)}let w="";if(f!==null){let m=e.state.functions.get(f);if(m){let v=new Map;v.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),v.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),v.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),v.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let E=new Map;for(let O of e.state.env.keys())(O==="COMPREPLY"||O.startsWith("COMPREPLY_")||O==="COMPREPLY__length")&&(E.set(O,e.state.env.get(O)),e.state.env.delete(O));let S=["compgen",h[0]??"",""];try{let O=await ns(e,m,S,"");if(O.exitCode!==0)return ct(e,v),ct(e,E),P("",O.stderr,1);w=O.stdout;let N=La(e);p.push(...N)}catch{return ct(e,v),ct(e,E),P("","",1)}ct(e,v),ct(e,E)}}if(d!==null)try{let m=$e(d),v=await e.executeScript(m);if(v.exitCode!==0)return P("",v.stderr,v.exitCode);if(v.stdout){let E=v.stdout.split(` -`);for(let S of E)S.length>0&&p.push(S)}}catch(m){if(m.name==="ParseException")return _(`compgen: -C: ${m.message} -`,2);throw m}let $=p;if(c!==null){let m=c.startsWith("!"),v=m?c.slice(1):c;$=p.filter(E=>{let S=at(E,v,!1,!0);return m?S:!S})}if($.length===0&&a!==null)return P(w,"",1);let g=$.map(m=>`${r}${m}${i}`).join(` -`),b=w+(g?`${g} -`:"");return F(b)}function Aa(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function _a(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function Ca(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function Pa(e){let t=[...Bs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function ka(e){let t=[...Or];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Na(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Oa(e){let t=[...Ea];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Da(e){let t=[...Sa];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Vs(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Nr(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),l=t.slice(0,o+1);s.push(l+a)}else s.push(a)}catch{}return s.sort()}function Ta(e){return["root","nobody"]}async function xa(e,t){let s=new Set;for(let i of Bs)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Or)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Ia(e,t){let n=new V().parseWordFromString(t,!1,!1);return await x(e,n)}function Ra(e,t){let s=e.state.env.get("IFS")??` -`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function ct(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function La(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=Ee(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else{let r=e.state.env.get("COMPREPLY");r!==void 0&&t.push(r)}return t}var Fa=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Us(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,l=[],u=[],c=[];for(let f=0;f=t.length)return _(`complete: -W: option requires an argument +`)}}let c=u||"/";if(n)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),Z(r?`${c} +`:"")}function gr(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Gu=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function qs(e){return Gu.includes(e)}async function js(e,t,s){let r=gr(e,s);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Qu=["-nt","-ot","-ef"];function Us(e){return Qu.includes(e)}async function Zs(e,t,s,r){let n=gr(e,s),i=gr(e,r);switch(t){case"-nt":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime>l.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtimes;case"-ge":return t>=s}}function as(e){return e==="="||e==="=="||e==="!="}function Qs(e,t,s,r=!1,n=!1,i=!1){if(r){let l=zt(t,s,n,i);return e==="!="?!l:l}if(n){let l=t.toLowerCase()===s.toLowerCase();return e==="!="?!l:l}let a=t===s;return e==="!="?!a:a}var Xu=new Set(["-z","-n"]);function Ks(e){return Xu.has(e)}function Xs(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ys(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let r=s[1],n=s[2];if(e.state.associativeArrays?.has(r)){let l=n;return(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))&&(l=l.slice(1,-1)),l=l.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(o,u)=>e.state.env.get(u)||""),e.state.env.has(`${r}_${l}`)}let a;try{let l=new V,o=X(l,n);a=await L(e,o.expression)}catch{if(/^-?\d+$/.test(n))a=Number.parseInt(n,10);else{let l=e.state.env.get(n);a=l?Number.parseInt(l,10):0}}if(a<0){let l=fe(e,r),o=e.state.currentLine;if(l.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript +`,!1;if(a=Math.max(...l)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript +`,!1}return e.state.env.has(`${r}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?je(e,t).length>0:fe(e,t).length>0}async function Et(e,t){switch(t.type){case"CondBinary":{let s=await W(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),n;if(t.operator==="=~")if(r){let i=await W(e,t.right);n=rs(i)}else n=await ko(e,t.right);else as(t.operator)&&!r?n=await _o(e,t.right):n=await W(e,t.right);if(as(t.operator)){let i=e.state.shoptOptions.nocasematch;return Qs(t.operator,s,n,!r,i,!0)}if(Hs(t.operator))return Gs(t.operator,await To(e,s),await To(e,n));if(Us(t.operator))return Zs(e,t.operator,s,n);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=tf(n),o=ae(a,i?"i":"").match(s);if(Ke(e,"BASH_REMATCH"),o)for(let u=0;u":return s>n;default:return!1}}case"CondUnary":{let s=await W(e,t.operand);return qs(t.operator)?js(e,t.operator,s):Ks(t.operator)?Xs(t.operator,s):t.operator==="-v"?await Ys(e,s):t.operator==="-o"?wr(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await W(e,t.operand.expression.word)})`!=="":!await Et(e,t.operand);case"CondAnd":return await Et(e,t.left)?await Et(e,t.right):!1;case"CondOr":return await Et(e,t.left)?!0:await Et(e,t.right);case"CondGroup":return await Et(e,t.expression);case"CondWord":return await W(e,t.word)!=="";default:return!1}}async function os(e,t){if(t.length===0)return P("","",1);if(t.length===1)return de(!!t[0]);if(t.length===2){let r=t[0],n=t[1];return r==="("?_(`test: '(' without matching ')' +`,2):qs(r)?de(await js(e,r,n)):Ks(r)?de(Xs(r,n)):r==="!"?de(!n):r==="-v"?de(await Ys(e,n)):r==="-o"?de(wr(e,n)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?_(`test: ${r}: unary operator expected +`,2):P("","",1)}if(t.length===3){let r=t[0],n=t[1],i=t[2];if(as(n))return de(Qs(n,r,i));if(Hs(n)){let a=Js(r),l=Js(i);return!a.valid||!l.valid?P("","",2):de(Gs(n,a.value,l.value))}if(Us(n))return de(await Zs(e,n,r,i));switch(n){case"-a":return de(r!==""&&i!=="");case"-o":return de(r!==""||i!=="");case">":return de(r>i);case"<":return de(rFo(c,t)),u=o.length>0?o.join("|"):"(?:)";if(n==="@")s+=`(?:${u})`;else if(n==="*")s+=`(?:${u})*`;else if(n==="+")s+=`(?:${u})+`;else if(n==="?")s+=`(?:${u})?`;else if(n==="!")if(iBo(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${u})).{${h}}`),s+=`(?:${p.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;r=i;continue}}if(n==="\\")if(r+10;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function zo(e){let t=[],s="",r=0,n=0;for(;nBo(u,t));if(o.every(u=>u!==null)&&o.every(u=>u===o[0])){s+=o[0],r=i+1;continue}return null}return null}}if(n==="*")return null;if(n==="?"){s+=1,r++;continue}if(n==="["){let i=e.indexOf("]",r+1);if(i!==-1){s+=1,r=i+1;continue}s+=1,r++;continue}if(n==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}function wr(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function To(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return Wo(t);try{let s=new V,r=X(s,t);return await L(e,r.expression)}catch{return Wo(t)}}function ef(e,t){let s=0;for(let r of e){let n;if(r>="0"&&r<="9")n=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")n=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")n=r.charCodeAt(0)-65+36;else if(r==="@")n=62;else if(r==="_")n=63;else return Number.NaN;if(n>=t)return Number.NaN;s=s*t+n}return s}function Wo(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let n=Number.parseInt(r[1],10);n>=2&&n<=64?s=ef(r[2],n):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function Js(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function tf(e){let t="",s=0;for(;s=e.length)break;if(e[s]!=="["){s++;continue}s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s=f&&e.state.env.set(`${r}__length`,String(c+1))}else a!==void 0&&e.state.env.set(r,a);return o&&_e(e,r),null}function bt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Bt(e,t){return e.state.localVarDepth?.get(t)}function tn(e,t){e.state.localVarDepth?.delete(t)}function Uo(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function sn(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Zo(e,t){if(e.state.localVarStack)for(let[s,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(s)}}var Er=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Ho(e){return Er.has(e)}var br=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),qt=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function nn(e,t,s,r){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory +`;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file +`}catch{}return null}function jt(e){let s=Math.min(e.length,8192);for(let r=0;r127)return"utf8";return"binary"}function af(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}async function Go(e,t){let s=new Map;for(let r=0;r&"||n.operator==="<&"){if(Vs(e,n.target))return{targets:s,error:`bash: $@: ambiguous redirect +`};s.set(r,await W(e,n.target))}else{let a=await zs(e,n.target);if("error"in a)return{targets:s,error:a.error};s.set(r,a.target)}}return{targets:s}}function of(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function rn(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await W(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let r=of(e);if(e.state.env.set(s.fdVariable,String(r)),s.target.type==="Word"){let n=await W(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(n,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(be(e),e.state.fileDescriptors.set(r,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,n);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),be(e),e.state.fileDescriptors.set(r,`__file__:${i}`)}else if(s.operator==="<<<")be(e),e.state.fileDescriptors.set(r,`${n} +`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,n),a=await e.fs.readFile(i);be(e),e.state.fileDescriptors.set(r,a)}catch{return P("",`bash: ${n}: No such file or directory +`,1)}}}return null}async function nt(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let r=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!r)continue;let n;if(r){if(n=await W(e,s.target),n==="-"||!Number.isNaN(Number.parseInt(n,10))||s.fd!=null)continue}else{let l=await zs(e,s.target);if("error"in l)return P("",l.error,1);n=l.target}let i=e.fs.resolvePath(e.state.cwd,n),a=s.operator===">|";if(i.includes("\0"))return P("",`bash: ${n}: No such file or directory +`,1);try{let l=await e.fs.stat(i);if(l.isDirectory)return P("",`bash: ${n}: Is a directory +`,1);if(e.state.options.noclobber&&!a&&!l.isDirectory&&n!=="/dev/null")return P("",`bash: ${n}: cannot overwrite existing file +`,1)}catch{}if(n!=="/dev/null"&&n!=="/dev/stdout"&&n!=="/dev/stderr"&&n!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),n==="/dev/full")return P("",`bash: /dev/full: No space left on device +`,1)}return null}async function le(e,t,s,r){let{stdout:n,stderr:i,exitCode:a}=t,o=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=m=>o,c={kind:"live-stdout"},f={kind:"live-stderr"};for(let m=0;m&"||y.operator==="<&"){if(Vs(e,y.target)){i+=`bash: $@: ambiguous redirect +`,a=1,n="";continue}b=await W(e,y.target)}else{let w=await zs(e,y.target);if("error"in w){i+=w.error,a=1,n="";continue}b=w.target}if(!y.fdVariable){if(b.includes("\0")){i+=`bash: ${b.replace(/\0/g,"")}: No such file or directory +`,a=1,n="";continue}switch(y.operator){case">":case">|":case">>":{let E=y.fd??1;if(E!==1&&E!==2)break;let w=y.operator===">>",S=y.operator===">|";if(b==="/dev/stdout"){E===2&&(f=c);break}if(b==="/dev/stderr"){E===1&&(c=f);break}if(b==="/dev/full"){i+=`bash: echo: write error: No space left on device +`,a=1,E===1&&(n="");break}if(b==="/dev/null"&&E===2){f={kind:"discard"};break}let A=e.fs.resolvePath(e.state.cwd,b),$=await nn(e,A,b,{...w?{}:{checkNoclobber:!0,isClobber:S}});if($){i+=$,a=1,E===1&&(n="");break}w?await e.fs.appendFile(A,"","binary"):await e.fs.writeFile(A,"","binary"),E===1?c={kind:"file",path:A,append:w}:f={kind:"file",path:A,append:w};break}case">&":case"<&":{let E=y.fd??1;if(b==="-")break;if(b.endsWith("-")){let w=b.slice(0,-1),S=Number.parseInt(w,10);if(!Number.isNaN(S)){let A=e.state.fileDescriptors?.get(S);A!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,A),S>=3&&e.state.fileDescriptors?.delete(S)):S===1||S===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupout__:${S}`)):S===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupin__:${S}`)):S>=3&&(i+=`bash: ${S}: Bad file descriptor +`,a=1)}break}if(b==="2"||b==="&2")E===1&&(c=f);else if(b==="1"||b==="&1")E===2?f=c:(n+=i,i="");else{let w=Number.parseInt(b,10);if(Number.isNaN(w)){if(y.operator===">&"){let S=e.fs.resolvePath(e.state.cwd,b),A=await nn(e,S,b,{checkNoclobber:!0});if(A){i=A,a=1,n="";break}await e.fs.writeFile(S,"","binary"),y.fd==null?(c={kind:"file",path:S,append:!1},f=c):E===1?c={kind:"file",path:S,append:!1}:E===2&&(f={kind:"file",path:S,append:!1})}}else{let S=e.state.fileDescriptors?.get(w);if(S?.startsWith("__file__:")){let A=S.slice(9);E===1?(await e.fs.appendFile(A,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A,i,jt(i)),i="")}else if(S?.startsWith("__rw__:")){let A=af(S);A&&(E===1?(await e.fs.appendFile(A.path,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A.path,i,jt(i)),i=""))}else if(S?.startsWith("__dupout__:")){let A=Number.parseInt(S.slice(11),10);if(A!==1)if(A===2)E===1&&(i+=n,n="");else{let $=e.state.fileDescriptors?.get(A);if($?.startsWith("__file__:")){let x=$.slice(9);E===1?(await e.fs.appendFile(x,n,u(n)),n=""):E===2&&(await e.fs.appendFile(x,i,jt(i)),i="")}}}else S?.startsWith("__dupin__:")?(i+=`bash: ${w}: Bad file descriptor +`,a=1,n=""):w>=3&&(i+=`bash: ${w}: Bad file descriptor +`,a=1,n="")}}break}case"&>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device +`,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{checkNoclobber:!0});if(w){i=w,a=1,n="";break}await e.fs.writeFile(E,"","binary"),c={kind:"file",path:E,append:!1},f=c;break}case"&>>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device +`,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{});if(w){i=w,a=1,n="";break}await e.fs.appendFile(E,"","binary"),c={kind:"file",path:E,append:!0},f=c;break}}}}if(n!==""||i!==""){let m=n,y=i;n="",i="";let b=async(v,E,w)=>{v.append?await e.fs.appendFile(v.path,E,w):await e.fs.writeFile(v.path,E,w)};if(c===f&&c.kind==="file"){let v=m+y;v!==""&&await b(c,v,u(v))}else for(let[v,E,w]of[[m,c,!0],[y,f,!1]])if(v!=="")switch(E.kind){case"live-stdout":n+=v;break;case"live-stderr":i+=v;break;case"file":await b(E,v,w?u(v):jt(v));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=n,n="";else if(d.startsWith("__file__:")){let m=d.slice(9);await e.fs.appendFile(m,n,u(n)),n=""}else if(d.startsWith("__file_append__:")){let m=d.slice(16);await e.fs.appendFile(m,n,u(n)),n=""}}let h=e.state.fileDescriptors?.get(2);if(h){if(h==="__dupout__:1")n+=i,i="";else if(h.startsWith("__file__:")){let m=h.slice(9);await e.fs.appendFile(m,i,jt(i)),i=""}else if(h.startsWith("__file_append__:")){let m=h.slice(16);await e.fs.appendFile(m,i,jt(i)),i=""}}let p=P(n,i,a);return t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),p}function Qo(e,t){if(e.state.options.posix&&Er.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin +`;throw new j(2,"",r)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),G}async function lf(e,t){let s="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let n=r.target,i=await W(e,n.content);n.stripTabs&&(i=i.split(` +`).map(l=>l.replace(/^\t+/,"")).join(` +`)),(r.fd??0)===0&&(s=i)}else if(r.operator==="<<<"&&r.target.type==="Word")s=`${await W(e,r.target)} +`;else if(r.operator==="<"&&r.target.type==="Word"){let n=await W(e,r.target),i=e.fs.resolvePath(e.state.cwd,n);try{s=await e.fs.readFile(i)}catch{}}return s}async function an(e,t,s,r="",n){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,tt(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(n??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(Zo(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:l,error:o}=await Go(e,t.redirections);if(o)return a(),P("",o,1);try{let u=await lf(e,t.redirections),c=r||u,f=await e.executeCommand(t.body,c);return a(),le(e,f,t.redirections,l)}catch(u){if(a(),u instanceof $e){let c=P(u.stdout,u.stderr,u.exitCode);return le(e,c,t.redirections,l)}throw u}}var Xo=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Sr=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],cf=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],uf=Sr;async function Ar(e,t){let s=[],r=null,n="",i="",a=null,l=!1,o=!1,u=!1,c=null,f=null,d=null,h=[],p=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let w=0;w=t.length)return _(`compgen: -A: option requires an argument +`,2);let A=t[w];if(!p.includes(A))return _(`compgen: ${A}: invalid action name +`,2);s.push(A)}else if(S==="-W"){if(w++,w>=t.length)return _(`compgen: -W: option requires an argument +`,2);r=t[w]}else if(S==="-P"){if(w++,w>=t.length)return _(`compgen: -P: option requires an argument +`,2);n=t[w]}else if(S==="-S"){if(w++,w>=t.length)return _(`compgen: -S: option requires an argument +`,2);i=t[w]}else if(S==="-o"){if(w++,w>=t.length)return _(`compgen: -o: option requires an argument +`,2);let A=t[w];if(A==="plusdirs")l=!0;else if(A==="dirnames")o=!0;else if(A==="default")u=!0;else if(!(A==="filenames"||A==="nospace"||A==="bashdefault"||A==="noquote"))return _(`compgen: ${A}: invalid option name +`,2)}else if(S==="-F"){if(w++,w>=t.length)return _(`compgen: -F: option requires an argument +`,2);f=t[w]}else if(S==="-C"){if(w++,w>=t.length)return _(`compgen: -C: option requires an argument +`,2);d=t[w]}else if(S==="-X"){if(w++,w>=t.length)return _(`compgen: -X: option requires an argument +`,2);c=t[w]}else if(S==="-G"){if(w++,w>=t.length)return _(`compgen: -G: option requires an argument +`,2)}else if(S==="--"){h.push(...t.slice(w+1));break}else S.startsWith("-")||h.push(S)}a=h[0]??null;let m=[];if(o){let w=await vr(e,a);m.push(...w)}if(u){let w=await Ko(e,a);m.push(...w)}for(let w of s)if(w==="variable"){let S=ff(e,a);m.push(...S)}else if(w==="export"){let S=df(e,a);m.push(...S)}else if(w==="function"){let S=hf(e,a);m.push(...S)}else if(w==="builtin"){let S=pf(a);m.push(...S)}else if(w==="keyword"){let S=mf(a);m.push(...S)}else if(w==="alias"){let S=gf(e,a);m.push(...S)}else if(w==="shopt"){let S=yf(a);m.push(...S)}else if(w==="helptopic"){let S=wf(a);m.push(...S)}else if(w==="directory"){let S=await vr(e,a);m.push(...S)}else if(w==="file"){let S=await Ko(e,a);m.push(...S)}else if(w==="user"){let S=Ef(a);m.push(...S)}else if(w==="command"){let S=await bf(e,a);m.push(...S)}if(r!==null)try{let w=await vf(e,r),S=Sf(e,w);for(let A of S)(a===null||A.startsWith(a))&&m.push(A)}catch{return P("","",1)}if(l){let w=await vr(e,a);for(let S of w)m.includes(S)||m.push(S)}let y="";if(f!==null){let w=e.state.functions.get(f);if(w){let S=new Map;S.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),S.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),S.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),S.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let A=new Map;for(let x of e.state.env.keys())(x==="COMPREPLY"||x.startsWith("COMPREPLY_")||x==="COMPREPLY__length")&&(A.set(x,e.state.env.get(x)),e.state.env.delete(x));let $=["compgen",h[0]??"",""];try{let x=await an(e,w,$,"");if(x.exitCode!==0)return Ut(e,S),Ut(e,A),P("",x.stderr,1);y=x.stdout;let I=Af(e);m.push(...I)}catch{return Ut(e,S),Ut(e,A),P("","",1)}Ut(e,S),Ut(e,A)}}if(d!==null)try{let w=qe(d),S=await e.executeScript(w);if(S.exitCode!==0)return P("",S.stderr,S.exitCode);if(S.stdout){let A=S.stdout.split(` +`);for(let $ of A)$.length>0&&m.push($)}}catch(w){if(w.name==="ParseException")return _(`compgen: -C: ${w.message} +`,2);throw w}let b=m;if(c!==null){let w=c.startsWith("!"),S=w?c.slice(1):c;b=m.filter(A=>{let $=zt(A,S,!1,!0);return w?$:!$})}if(b.length===0&&a!==null)return P(y,"",1);let v=b.map(w=>`${n}${w}${i}`).join(` +`),E=y+(v?`${v} +`:"");return Z(E)}function ff(e,t){let s=new Set;for(let n of e.state.env.keys()){if(n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length"))continue;let i=n.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)?s.add(n):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function df(e,t){let s=e.state.exportedVars??new Set,r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r=r.filter(n=>n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length")?!1:e.state.env.has(n)),r.sort()}function hf(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(r=>r.startsWith(t))),s.sort()}function pf(e){let t=[...Sr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function mf(e){let t=[...Xo];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function gf(e,t){let s=[];for(let n of e.state.env.keys())if(n.startsWith("BASH_ALIAS_")){let i=n.slice(11);s.push(i)}let r=s;return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function yf(e){let t=[...cf];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function wf(e){let t=[...uf];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function vr(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i){let l=`${r}/${a}`;try{if((await e.fs.stat(l)).isDirectory&&(!n||a.startsWith(n)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Ko(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i)if(!n||a.startsWith(n))if(t?.includes("/")){let l=t.lastIndexOf("/"),o=t.slice(0,l+1);s.push(o+a)}else s.push(a)}catch{}return s.sort()}function Ef(e){return["root","nobody"]}async function bf(e,t){let s=new Set;for(let i of Sr)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Xo)s.add(i);let r=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of r.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let l of a)s.add(l)}catch{}let n=Array.from(s);return t!==null&&(n=n.filter(i=>i.startsWith(t))),n.sort()}async function vf(e,t){let r=new V().parseWordFromString(t,!1,!1);return await W(e,r)}function Sf(e,t){let s=e.state.env.get("IFS")??` +`;if(s.length===0)return[t];let r=new Set(s.split("")),n=[],i="",a=0;for(;a0&&(n.push(i),i=""),a++):(i+=l,a++)}return i.length>0&&n.push(i),n}function Ut(e,t){for(let[s,r]of t)r===void 0?e.state.env.delete(s):e.state.env.set(s,r)}function Af(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let n=F(e,"COMPREPLY");for(let[,i]of n)t.push(i)}else{let n=e.state.env.get("COMPREPLY");n!==void 0&&t.push(n)}return t}var $f=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Nr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=!1,i,a,l,o=[],u=[],c=[];for(let f=0;f=t.length)return _(`complete: -W: option requires an argument `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return _(`complete: -F: option requires an argument `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return _(`complete: -o: option requires an argument -`,2);let h=t[f];if(!Fa.includes(h))return _(`complete: ${h}: invalid option name -`,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument +`,2);let h=t[f];if(!$f.includes(h))return _(`complete: ${h}: invalid option name +`,2);o.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument -`,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument +`,2);l=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument `,2)}else if(d==="-P"){if(f++,f>=t.length)return _(`complete: -P: option requires an argument `,2)}else if(d==="-S"){if(f++,f>=t.length)return _(`complete: -S: option requires an argument `,2)}else if(d==="-X"){if(f++,f>=t.length)return _(`complete: -X: option requires an argument -`,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(n){if(c.length===0)return e.state.completionSpecs.clear(),F("");for(let f of c)e.state.completionSpecs.delete(f);return F("")}if(s)return c.length===0?Hs(e):Hs(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&l.length===0&&u.length===0&&!r)return Hs(e);if(a&&c.length===0&&!r)return _(`complete: -F: option requires a command name -`,2);if(r){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),F("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return F("")}function Hs(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification -`;return P("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return P(n.join(` -`)+(n.length>0?` +`,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),Z("");for(let f of c)e.state.completionSpecs.delete(f);return Z("")}if(s)return c.length===0?$r(e):$r(e,c);if(t.length===0||c.length===0&&!i&&!a&&!l&&o.length===0&&u.length===0&&!n)return $r(e);if(a&&c.length===0&&!n)return _(`complete: -F: option requires a command name +`,2);if(n){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),l!==void 0&&(f.command=l),o.length>0&&(f.options=o),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),Z("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),l!==void 0&&(d.command=l),o.length>0&&(d.options=o),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Z("")}function $r(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification +`;return P("",i,1)}return Z("")}let r=[],n=t||Array.from(s.keys());for(let i of n){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return P(r.join(` +`)+(r.length>0?` `:""),`complete: ${i}: no completion specification -`,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${l}`;if(a.actions)for(let l of a.actions)o+=` -A ${l}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?F(""):F(`${n.join(` +`,1);continue}let l="complete";if(a.options)for(let o of a.options)l+=` -o ${o}`;if(a.actions)for(let o of a.actions)l+=` -A ${o}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?l+=` -W '${a.wordlist}'`:l+=` -W ${a.wordlist}`),a.function!==void 0&&(l+=` -F ${a.function}`),a.isDefault&&(l+=" -D"),l+=` ${i}`,r.push(l)}return r.length===0?Z(""):Z(`${r.join(` `)} -`)}var Dr=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Zs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o=t.length)return _(`compopt: -o: option requires an argument -`,2);let u=t[o];if(!Dr.includes(u))return _(`compopt: ${u}: invalid option name -`,2);r.push(u)}else if(l==="+o"){if(o++,o>=t.length)return _(`compopt: +o: option requires an argument -`,2);let u=t[o];if(!Dr.includes(u))return _(`compopt: ${u}: invalid option name -`,2);i.push(u)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(o.options??[]);for(let u of r)l.add(u);for(let u of i)l.delete(u);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",o),F("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},l=new Set(o.options??[]);for(let u of r)l.add(u);for(let u of i)l.delete(u);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",o),F("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},u=new Set(l.options??[]);for(let c of r)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(o,l)}return F("")}return _(`compopt: not currently executing completion function -`,1)}function qs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ie;return W}if(t.length>1)throw new B(1,"",`bash: continue: too many arguments -`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(1,"",`bash: continue: ${t[0]}: numeric argument required -`);s=n}throw new de(s)}function G(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Gs(e){for(let t=0;t{let h=e.state.env.get(`${i}_${d}`)??"",y=Ys(h);return`['${d}']=${y}`});s+=`declare -A ${i}=(${f.join(" ")}) -`}continue}let l=se(e,i);if(l.length>0){let c=l.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${Ge(d)}`});s+=`declare -a ${i}=(${c.join(" ")}) +`)}var Yo=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function kr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=[],i=[],a=[];for(let l=0;l=t.length)return _(`compopt: -o: option requires an argument +`,2);let u=t[l];if(!Yo.includes(u))return _(`compopt: ${u}: invalid option name +`,2);n.push(u)}else if(o==="+o"){if(l++,l>=t.length)return _(`compopt: +o: option requires an argument +`,2);let u=t[l];if(!Yo.includes(u))return _(`compopt: ${u}: invalid option name +`,2);i.push(u)}else if(o==="--"){a.push(...t.slice(l+1));break}else!o.startsWith("-")&&!o.startsWith("+")&&a.push(o)}if(s){let l=e.state.completionSpecs.get("__default__")??{isDefault:!0},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__default__",l),Z("")}if(r){let l=e.state.completionSpecs.get("__empty__")??{},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__empty__",l),Z("")}if(a.length>0){for(let l of a){let o=e.state.completionSpecs.get(l)??{},u=new Set(o.options??[]);for(let c of n)u.add(c);for(let c of i)u.delete(c);o.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(l,o)}return Z("")}return _(`compopt: not currently executing completion function +`,1)}function _r(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ut;return G}if(t.length>1)throw new j(1,"",`bash: continue: too many arguments +`);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(1,"",`bash: continue: ${t[0]}: numeric argument required +`);s=r}throw new Ie(s)}function ue(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Pr(e){for(let t=0;t{let h=e.state.env.get(`${i}_${d}`)??"",p=Cr(h);return`['${d}']=${p}`});s+=`declare -A ${i}=(${f.join(" ")}) +`}continue}let o=fe(e,i);if(o.length>0){let c=o.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${kt(d)}`});s+=`declare -a ${i}=(${c.join(" ")}) `;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=() -`;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Xs(u)} +`;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Ir(u)} `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?s+=`declare ${a} ${i} -`:(n+=`bash: declare: ${i}: not found -`,r=!0)}}return P(s,n,r?1:0)}function Ir(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,l="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),y=f.slice(d+1);if(/^\d+$/.test(y)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=Tr(e,f),h=e.state.associativeArrays?.has(f),y=se(e,f),p=!h&&(y.length>0||e.state.env.has(`${f}__length`));if(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!ge(e,f)))continue;if(h){let $=Fe(e,f);if($.length===0)l+=`declare -A ${f}=() -`;else{let g=$.map(b=>{let m=e.state.env.get(`${f}_${b}`)??"",v=Ys(m);return`['${b}']=${v}`});l+=`declare -A ${f}=(${g.join(" ")}) -`}continue}if(y.length>0){let $=y.map(g=>{let b=e.state.env.get(`${f}_${g}`)??"";return`[${g}]=${Ge(b)}`});l+=`declare -a ${f}=(${$.join(" ")}) -`;continue}if(e.state.env.has(`${f}__length`)){l+=`declare -a ${f}=() -`;continue}let w=e.state.env.get(f);w!==void 0&&(l+=`declare ${d} ${f}=${Xs(w)} -`)}return F(l)}function Rr(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Fe(e,n);if(r.length===0)t+=`declare -A ${n}=() -`;else{let i=r.map(a=>{let o=e.state.env.get(`${n}_${a}`)??"",l=Ys(o);return`['${a}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")}) -`}}return F(t)}function Lr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=se(e,r);if(i.length===0)t+=`declare -a ${r}=() -`;else{let a=i.map(o=>{let l=e.state.env.get(`${r}_${o}`)??"";return`[${o}]=${Ge(l)}`});t+=`declare -a ${r}=(${a.join(" ")}) -`}}return F(t)}function Fr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||se(e,r).length>0||e.state.env.has(`${r}__length`))continue;let o=e.state.env.get(r);o!==void 0&&(t+=`${r}=${rs(o)} -`)}return F(t)}function Qs(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function $t(e,t){return e.state.integerVars?.has(t)??!1}function Js(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Wa(e,t){return e.state.lowercaseVars?.has(t)??!1}function en(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Ma(e,t){return e.state.uppercaseVars?.has(t)??!1}function ut(e,t,s){return Wa(e,t)?s.toLowerCase():Ma(e,t)?s.toUpperCase():s}async function Wr(e,t){try{let s=new V,n=Q(s,t),r=await j(e,n.expression);return String(r)}catch{return"0"}}function za(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n0&&!w,m=N=>{if(!b)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N))},v=N=>{if(!b)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N));let C=`${N}_`;for(let D of e.state.env.keys())D.startsWith(C)&&!D.includes("__")&&(I.has(D)||I.set(D,e.state.env.get(D)));let k=`${N}__length`;e.state.env.has(k)&&!I.has(k)&&I.set(k,e.state.env.get(k))},E=N=>{b&&ze(e,N)};if(p){if($.length===0){let C=Array.from(e.state.functions.keys()).sort(),k="";for(let D of C)k+=`declare -f ${D} -`;return F(k)}let N=!0,I="";for(let C of $)e.state.functions.has(C)?I+=`${C} -`:N=!1;return P(I,"",N?0:1)}if(y){if($.length===0){let I="",C=Array.from(e.state.functions.keys()).sort();for(let k of C)I+=`${k} () +`:(r+=`bash: declare: ${i}: not found +`,n=!0)}}return P(s,r,n?1:0)}function tl(e,t){let{filterExport:s,filterReadonly:r,filterNameref:n,filterIndexedArray:i,filterAssocArray:a}=t,l=s||r||n||i||a,o="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),p=f.slice(d+1);if(/^\d+$/.test(p)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=Jo(e,f),h=e.state.associativeArrays?.has(f),p=fe(e,f),m=!h&&(p.length>0||e.state.env.has(`${f}__length`));if(l&&(a&&!h||i&&!m||s&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||n&&!ee(e,f)))continue;if(h){let b=je(e,f);if(b.length===0)o+=`declare -A ${f}=() +`;else{let v=b.map(E=>{let w=e.state.env.get(`${f}_${E}`)??"",S=Cr(w);return`['${E}']=${S}`});o+=`declare -A ${f}=(${v.join(" ")}) +`}continue}if(p.length>0){let b=p.map(v=>{let E=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${kt(E)}`});o+=`declare -a ${f}=(${b.join(" ")}) +`;continue}if(e.state.env.has(`${f}__length`)){o+=`declare -a ${f}=() +`;continue}let y=e.state.env.get(f);y!==void 0&&(o+=`declare ${d} ${f}=${Ir(y)} +`)}return Z(o)}function sl(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let r of s){let n=je(e,r);if(n.length===0)t+=`declare -A ${r}=() +`;else{let i=n.map(a=>{let l=e.state.env.get(`${r}_${a}`)??"",o=Cr(l);return`['${a}']=${o}`});t+=`declare -A ${r}=(${i.join(" ")}) +`}}return Z(t)}function nl(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);/^\d+$/.test(l)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let r=Array.from(s).sort();for(let n of r){let i=fe(e,n);if(i.length===0)t+=`declare -a ${n}=() +`;else{let a=i.map(l=>{let o=e.state.env.get(`${n}_${l}`)??"";return`[${l}]=${kt(o)}`});t+=`declare -a ${n}=(${a.join(" ")}) +`}}return Z(t)}function rl(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);if(/^\d+$/.test(l)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(n)}let r=Array.from(s).sort();for(let n of r){if(e.state.associativeArrays?.has(n)||fe(e,n).length>0||e.state.env.has(`${n}__length`))continue;let l=e.state.env.get(n);l!==void 0&&(t+=`${n}=${on(l)} +`)}return Z(t)}function xr(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ls(e,t){return e.state.integerVars?.has(t)??!1}function Rr(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Nf(e,t){return e.state.lowercaseVars?.has(t)??!1}function Or(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function kf(e,t){return e.state.uppercaseVars?.has(t)??!1}function Zt(e,t,s){return Nf(e,t)?s.toLowerCase():kf(e,t)?s.toUpperCase():s}async function il(e,t){try{let s=new V,r=X(s,t),n=await L(e,r.expression);return String(n)}catch{return"0"}}function _f(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],r=s.length;if(e[r]!=="[")return null;let n=0,i=r+1;for(;r0&&!y,w=I=>{if(!E)return;let T=e.state.localScopes[e.state.localScopes.length-1];T.has(I)||T.set(I,e.state.env.get(I))},S=I=>{if(!E)return;let T=e.state.localScopes[e.state.localScopes.length-1];T.has(I)||T.set(I,e.state.env.get(I));let k=`${I}_`;for(let C of e.state.env.keys())C.startsWith(k)&&!C.includes("__")&&(T.has(C)||T.set(C,e.state.env.get(C)));let D=`${I}__length`;e.state.env.has(D)&&!T.has(D)&&T.set(D,e.state.env.get(D))},A=I=>{E&&bt(e,I)};if(m){if(b.length===0){let k=Array.from(e.state.functions.keys()).sort(),D="";for(let C of k)D+=`declare -f ${C} +`;return Z(D)}let I=!0,T="";for(let k of b)e.state.functions.has(k)?T+=`${k} +`:I=!1;return P(T,"",I?0:1)}if(p){if(b.length===0){let T="",k=Array.from(e.state.functions.keys()).sort();for(let D of k)T+=`${D} () { # function body } -`;return F(I)}let N=!0;for(let I of $)e.state.functions.has(I)||(N=!1);return P("","",N?0:1)}if(a&&$.length>0)return xr(e,$);if(a&&$.length===0)return Ir(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!a)return Rr(e);if($.length===0&&s&&!a)return Lr(e);if($.length===0&&!a)return Fr(e);let S="",O=0;for(let N of $){let I=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(I&&!u){let A=I[1],T=I[2];if(n&&se(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array -`,O=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(A)){S+=`bash: declare: ${A}: cannot convert associative to indexed array -`,O=1;continue}if(v(A),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)),_e(e,A),e.state.env.delete(A),e.state.env.delete(`${A}__length`),n&&T.includes("[")){let R=Jt(T);for(let[J,z]of R){let K=G(e,z);e.state.env.set(`${A}_${J}`,K)}}else if(n){let R=ke(T);for(let J=0;J/^\[[^\]]+\]=/.test(z))){let z=0;for(let K of R){let ne=K.match(/^\[([^\]]+)\]=(.*)$/);if(ne){let ue=ne[1],Ye=ne[2],Gi=G(e,Ye),pt;if(/^-?\d+$/.test(ue))pt=Number.parseInt(ue,10);else try{let Ki=new V,Xi=Q(Ki,ue);pt=await j(e,Xi.expression)}catch{pt=0}e.state.env.set(`${A}_${pt}`,Gi),z=pt+1}else{let ue=G(e,K);e.state.env.set(`${A}_${z}`,ue),z++}}}else{for(let z=0;z=K&&e.state.env.set(`${A}__length`,String(z+1)),E(A),r&&ce(e,A),i&&Se(e,A);continue}let k=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(k&&!u){let A=k[1],T=k[2],R=ee(e,A);if(R)return R;v(A);let J=ke(T);if(e.state.associativeArrays?.has(A)){let z=Jt(T);for(let[K,ne]of z){let ue=G(e,ne);e.state.env.set(`${A}_${K}`,ue)}}else{let z=se(e,A),K=0,ne=e.state.env.get(A);z.length===0&&ne!==void 0?(e.state.env.set(`${A}_0`,ne),e.state.env.delete(A),K=1):z.length>0&&(K=Math.max(...z)+1);for(let Ye=0;Ye0||e.state.associativeArrays?.has(A);if($t(e,A)){let K=e.state.env.get(A)??"0",ne=parseInt(K,10)||0,ue=parseInt(await Wr(e,T),10)||0;T=String(ne+ue),e.state.env.set(A,T)}else if(z){T=ut(e,A,T);let K=`${A}_0`,ne=e.state.env.get(K)??"";e.state.env.set(K,ne+T)}else{T=ut(e,A,T);let K=e.state.env.get(A)??"";e.state.env.set(A,K+T)}E(A),r&&ce(e,A),i&&Se(e,A),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(A));continue}if(N.includes("=")){let A=N.indexOf("="),T=N.slice(0,A),R=N.slice(A+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(T)){S+=`bash: typeset: \`${T}': not a valid identifier -`,O=1;continue}let J=ee(e,T);if(J)return J;if(m(T),o){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){S+=`bash: declare: \`${R}': invalid variable name for name reference -`,O=1;continue}e.state.env.set(T,R),Te(e,T),R!==""&&As(e,R)&&Ss(e,T),E(T),r&&ce(e,T),i&&Se(e,T);continue}if(f&&Qs(e,T),d&&Js(e,T),h&&en(e,T),$t(e,T)&&(R=await Wr(e,R)),R=ut(e,T,R),ge(e,T)){let z=We(e,T);z&&z!==T?e.state.env.set(z,R):e.state.env.set(T,R)}else e.state.env.set(T,R);E(T),r&&ce(e,T),i&&Se(e,T),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(T))}else{let A=N;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)){S+=`bash: typeset: \`${A}': not a valid identifier -`,O=1;continue}if(s||n?v(A):m(A),o){Te(e,A);let R=e.state.env.get(A);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?jn(e,A):R&&As(e,R)&&Ss(e,A),E(A),r&&ce(e,A),i&&Se(e,A);continue}if(f&&Qs(e,A),d&&Js(e,A),h&&en(e,A),n){if(se(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array -`,O=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)}let T=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${A}_`)&&!R.startsWith(`${A}__length`));!e.state.env.has(A)&&!T&&(s||n?e.state.env.set(`${A}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(A))),E(A),r&&ce(e,A),i&&Se(e,A)}}return P("",S,O)}async function sn(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a0&&(w=Math.max(...p)+1);for(let b=0;bn&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function rn(e,t){let s=nn(e),n;for(let o=0;ol);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.get("HOME")||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Va(r);try{if(!(await e.fs.stat(r)).isDirectory)return _(`bash: pushd: ${n}: Not a directory -`,1)}catch{return _(`bash: pushd: ${n}: No such file or directory -`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[r,...s].map(o=>Et(o,i)).join(" ")} -`;return F(a)}function an(e,t){let s=nn(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option +`;return Z(T)}let I=!0;for(let T of b)e.state.functions.has(T)||(I=!1);return P("","",I?0:1)}if(a&&b.length>0)return el(e,b);if(a&&b.length===0)return tl(e,{filterExport:i,filterReadonly:n,filterNameref:l,filterIndexedArray:s,filterAssocArray:r});if(b.length===0&&r&&!a)return sl(e);if(b.length===0&&s&&!a)return nl(e);if(b.length===0&&!a)return rl(e);let $="",x=0;for(let I of b){let T=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(T&&!u){let N=T[1],O=T[2];if(r&&fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array +`,x=1;continue}if((s||!r&&!s)&&e.state.associativeArrays?.has(N)){$+=`bash: declare: ${N}: cannot convert associative to indexed array +`,x=1;continue}if(S(N),r&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)),Ke(e,N),e.state.env.delete(N),e.state.env.delete(`${N}__length`),r&&O.includes("[")){let M=en(O);for(let[q,J]of M){let ce=ue(e,J);e.state.env.set(`${N}_${q}`,ce)}}else if(r){let M=st(O);for(let q=0;q/^\[[^\]]+\]=/.test(J))){let J=0;for(let ce of M){let pe=ce.match(/^\[([^\]]+)\]=(.*)$/);if(pe){let Pe=pe[1],Dt=pe[2],mc=ue(e,Dt),Kt;if(/^-?\d+$/.test(Pe))Kt=Number.parseInt(Pe,10);else try{let gc=new V,yc=X(gc,Pe);Kt=await L(e,yc.expression)}catch{Kt=0}e.state.env.set(`${N}_${Kt}`,mc),J=Kt+1}else{let Pe=ue(e,ce);e.state.env.set(`${N}_${J}`,Pe),J++}}}else{for(let J=0;J=ce&&e.state.env.set(`${N}__length`,String(J+1)),A(N),n&&_e(e,N),i&&Ze(e,N);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(D&&!u){let N=D[1],O=D[2],M=me(e,N);if(M)return M;S(N);let q=st(O);if(e.state.associativeArrays?.has(N)){let J=en(O);for(let[ce,pe]of J){let Pe=ue(e,pe);e.state.env.set(`${N}_${ce}`,Pe)}}else{let J=fe(e,N),ce=0,pe=e.state.env.get(N);J.length===0&&pe!==void 0?(e.state.env.set(`${N}_0`,pe),e.state.env.delete(N),ce=1):J.length>0&&(ce=Math.max(...J)+1);for(let Dt=0;Dt0||e.state.associativeArrays?.has(N);if(ls(e,N)){let ce=e.state.env.get(N)??"0",pe=parseInt(ce,10)||0,Pe=parseInt(await il(e,O),10)||0;O=String(pe+Pe),e.state.env.set(N,O)}else if(J){O=Zt(e,N,O);let ce=`${N}_0`,pe=e.state.env.get(ce)??"";e.state.env.set(ce,pe+O)}else{O=Zt(e,N,O);let ce=e.state.env.get(N)??"";e.state.env.set(N,ce+O)}A(N),n&&_e(e,N),i&&Ze(e,N),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(N));continue}if(I.includes("=")){let N=I.indexOf("="),O=I.slice(0,N),M=I.slice(N+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){$+=`bash: typeset: \`${O}': not a valid identifier +`,x=1;continue}let q=me(e,O);if(q)return q;if(w(O),l){if(M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)){$+=`bash: declare: \`${M}': invalid variable name for name reference +`,x=1;continue}e.state.env.set(O,M),ot(e,O),M!==""&&xs(e,M)&&ir(e,O),A(O),n&&_e(e,O),i&&Ze(e,O);continue}if(f&&xr(e,O),d&&Rr(e,O),h&&Or(e,O),ls(e,O)&&(M=await il(e,M)),M=Zt(e,O,M),ee(e,O)){let J=ve(e,O);J&&J!==O?e.state.env.set(J,M):e.state.env.set(O,M)}else e.state.env.set(O,M);A(O),n&&_e(e,O),i&&Ze(e,O),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let N=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)){$+=`bash: typeset: \`${N}': not a valid identifier +`,x=1;continue}if(s||r?S(N):w(N),l){ot(e,N);let M=e.state.env.get(N);M!==void 0&&M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)?va(e,N):M&&xs(e,M)&&ir(e,N),A(N),n&&_e(e,N),i&&Ze(e,N);continue}if(f&&xr(e,N),d&&Rr(e,N),h&&Or(e,N),r){if(fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array +`,x=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)}let O=Array.from(e.state.env.keys()).some(M=>M.startsWith(`${N}_`)&&!M.startsWith(`${N}__length`));!e.state.env.has(N)&&!O&&(s||r?e.state.env.set(`${N}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(N))),A(N),n&&_e(e,N),i&&Ze(e,N)}}return P("",$,x)}async function Tr(e,t){let s=!1,r=!1,n=!1,i=[];for(let a=0;a0&&(y=Math.max(...m)+1);for(let E=0;Er&&r!=="."),s=[];for(let r of t)r===".."?s.pop():s.push(r);return`/${s.join("/")}`}async function Mr(e,t){let s=Wr(e),r;for(let l=0;lo);l.pop(),n=`/${l.join("/")}`}else r==="."?n=e.state.cwd:r.startsWith("~")?n=(e.state.env.get("HOME")||"/")+r.slice(1):n=`${e.state.cwd}/${r}`;n=Pf(n);try{if(!(await e.fs.stat(n)).isDirectory)return _(`bash: pushd: ${r}: Not a directory +`,1)}catch{return _(`bash: pushd: ${r}: No such file or directory +`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[n,...s].map(l=>cs(l,i)).join(" ")} +`;return Z(a)}function Fr(e,t){let s=Wr(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option `,2):_(`bash: popd: too many arguments `,2);if(s.length===0)return _(`bash: popd: directory stack empty -`,1);let n=s.shift();if(!n)return _(`bash: popd: directory stack empty -`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let r=e.state.env.get("HOME")||"",i=`${[n,...s].map(a=>Et(a,r)).join(" ")} -`;return F(i)}function on(e,t){let s=nn(e),n=!1,r=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")n=!0;else if(f==="l")r=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option +`,1);let r=s.shift();if(!r)return _(`bash: popd: directory stack empty +`,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let n=e.state.env.get("HOME")||"",i=`${[r,...s].map(a=>cs(a,n)).join(" ")} +`;return Z(i)}function Vr(e,t){let s=Wr(e),r=!1,n=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")n=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option `,2);else return _(`bash: dirs: too many arguments -`,1);if(n)return e.state.directoryStack=[],W;let o=[e.state.cwd,...s],l=e.state.env.get("HOME")||"",u;return a?(u=o.map((c,f)=>{let d=r?c:Et(c,l);return` ${f} ${d}`}).join(` +`,1);if(r)return e.state.directoryStack=[],G;let l=[e.state.cwd,...s],o=e.state.env.get("HOME")||"",u;return a?(u=l.map((c,f)=>{let d=n?c:cs(c,o);return` ${f} ${d}`}).join(` `),u+=` -`):i?u=o.map(c=>r?c:Et(c,l)).join(` +`):i?u=l.map(c=>n?c:cs(c,o)).join(` `)+` -`:u=o.map(c=>r?c:Et(c,l)).join(" ")+` -`,F(u)}async function is(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return _(`bash: eval: ${o}: invalid option +`:u=l.map(c=>n?c:cs(c,o)).join(" ")+` +`,Z(u)}async function ln(e,t,s){let r=t;if(r.length>0){let l=r[0];if(l==="--")r=r.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return _(`bash: eval: ${l}: invalid option eval: usage: eval [arg ...] -`,2)}if(n.length===0)return W;let r=n.join(" ");if(r.trim()==="")return W;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=$e(r);return await e.executeScript(o)}catch(o){if(o instanceof fe||o instanceof de||o instanceof le||o instanceof B)throw o;if(o.name==="ParseException")return _(`bash: eval: ${o.message} -`);throw o}finally{e.state.groupStdin=i}}function ln(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required -`,s=2):s=(i%256+256)%256}throw new B(s,"",n)}function cn(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}" -`}}return F(a)}if(s){for(let a of n){let o,l;if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),l=G(e,a.slice(u+1)),e.state.env.set(o,l)}else o=a;Ft(e,o)}return W}let r="",i=0;for(let a of n){let o,l,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],l=G(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=G(e,a.slice(f+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier -`,i=1;continue}if(l!==void 0)if(u){let f=e.state.env.get(o)??"";e.state.env.set(o,f+l)}else e.state.env.set(o,l);else e.state.env.has(o)||e.state.env.set(o,"");Se(e,o)}return P("",r,i)}function as(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...] -`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let w=1;w<=p;w++)o.push(e.state.env.get(String(w))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>o.length)return r||e.state.env.set(n,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:1,stdout:"",stderr:""};let c=o[l-1];if(!c||c==="-"||!c.startsWith("-"))return r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),as(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d} -`,r||e.state.env.set(n,"?"),f+1=o.length){let p="";return i?(e.state.env.set("OPTARG",d),r||e.state.env.set(n,":")):(p=`bash: option requires an argument -- ${d} -`,r||e.state.env.set(n,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",o[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1=t.length)return _(`bash: hash: -p: option requires an argument -`,1);o=t[u],u++}else if(y.startsWith("-")&&y.length>1){for(let p of y.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")a=!0;else return p==="p"?_(`bash: hash: -p: option requires an argument -`,1):_(`bash: hash: -${p}: invalid option -`,1);u++}else l.push(y),u++}if(s)return e.state.hashTable.clear(),W;if(n){if(l.length===0)return _(`bash: hash: -d: option requires an argument -`,1);let y=!1,p="";for(let w of l)e.state.hashTable.has(w)?e.state.hashTable.delete(w):(p+=`bash: hash: ${w}: not found -`,y=!0);return y?_(p,1):W}if(a){if(l.length===0)return _(`bash: hash: -t: option requires an argument -`,1);let y="",p=!1,w="";for(let $ of l){let g=e.state.hashTable.get($);g?l.length>1?y+=`${$} ${g} -`:y+=`${g} -`:(w+=`bash: hash: ${$}: not found -`,p=!0)}return p?{exitCode:1,stdout:y,stderr:w}:F(y)}if(i){if(l.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...] -`,1);let y=l[0];return e.state.hashTable.set(y,o),W}if(l.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty -`);let y="";if(r)for(let[p,w]of e.state.hashTable)y+=`builtin hash -p ${w} ${p} -`;else{y=`hits command -`;for(let[,p]of e.state.hashTable)y+=` 1 ${p} -`}return F(y)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let y of l){if(y.includes("/")){f+=`bash: hash: ${y}: cannot use / in name -`,c=!0;continue}let p=!1;for(let w of h){if(!w)continue;let $=`${w}/${y}`;if(await e.fs.exists($)){e.state.hashTable.set(y,$),p=!0;break}}p||(f+=`bash: hash: ${y}: not found -`,c=!0)}return c?_(f,1):W}var Mr=new Map([[":",[": [arguments]",`Null command. +`,2)}if(r.length===0)return G;let n=r.join(" ");if(n.trim()==="")return G;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let l=qe(n);return await e.executeScript(l)}catch(l){if(l instanceof De||l instanceof Ie||l instanceof $e||l instanceof j)throw l;if(l.name==="ParseException")return _(`bash: eval: ${l.message} +`);throw l}finally{e.state.groupStdin=i}}function zr(e,t){let s,r="";if(t.length===0)s=e.state.lastExitCode;else{let n=t[0],i=Number.parseInt(n,10);n===""||Number.isNaN(i)||!/^-?\d+$/.test(n)?(r=`bash: exit: ${n}: numeric argument required +`,s=2):s=(i%256+256)%256}throw new j(s,"",r)}function Br(e,t){let s=!1,r=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!s){let a="",l=e.state.exportedVars??new Set,o=Array.from(l).sort();for(let u of o){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}" +`}}return Z(a)}if(s){for(let a of r){let l,o;if(a.includes("=")){let u=a.indexOf("=");l=a.slice(0,u),o=ue(e,a.slice(u+1)),e.state.env.set(l,o)}else l=a;Os(e,l)}return G}let n="",i=0;for(let a of r){let l,o,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)l=c[1],o=ue(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");l=a.slice(0,f),o=ue(e,a.slice(f+1))}else l=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: export: \`${a}': not a valid identifier +`,i=1;continue}if(o!==void 0)if(u){let f=e.state.env.get(l)??"";e.state.env.set(l,f+o)}else e.state.env.set(l,o);else e.state.env.has(l)||e.state.env.set(l,"");Ze(e,l)}return P("",n,i)}function cn(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...] +`);let s=t[0],r=t[1],n=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=s.startsWith(":"),a=i?s.slice(1):s,l;if(t.length>2)l=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);l=[];for(let y=1;y<=m;y++)l.push(e.state.env.get(String(y))||"")}let o=Number.parseInt(e.state.env.get("OPTIND")||"1",10);o<1&&(o=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),o>l.length)return n||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(l.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:1,stdout:"",stderr:""};let c=l[o-1];if(!c||c==="-"||!c.startsWith("-"))return n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),cn(e,t);let h=a.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d} +`,n||e.state.env.set(r,"?"),f+1=l.length){let m="";return i?(e.state.env.set("OPTARG",d),n||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d} +`,n||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",l[o]),e.state.env.set("OPTIND",String(o+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1=t.length)return _(`bash: hash: -p: option requires an argument +`,1);l=t[u],u++}else if(p.startsWith("-")&&p.length>1){for(let m of p.slice(1))if(m==="r")s=!0;else if(m==="d")r=!0;else if(m==="l")n=!0;else if(m==="t")a=!0;else return m==="p"?_(`bash: hash: -p: option requires an argument +`,1):_(`bash: hash: -${m}: invalid option +`,1);u++}else o.push(p),u++}if(s)return e.state.hashTable.clear(),G;if(r){if(o.length===0)return _(`bash: hash: -d: option requires an argument +`,1);let p=!1,m="";for(let y of o)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found +`,p=!0);return p?_(m,1):G}if(a){if(o.length===0)return _(`bash: hash: -t: option requires an argument +`,1);let p="",m=!1,y="";for(let b of o){let v=e.state.hashTable.get(b);v?o.length>1?p+=`${b} ${v} +`:p+=`${v} +`:(y+=`bash: hash: ${b}: not found +`,m=!0)}return m?{exitCode:1,stdout:p,stderr:y}:Z(p)}if(i){if(o.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...] +`,1);let p=o[0];return e.state.hashTable.set(p,l),G}if(o.length===0){if(e.state.hashTable.size===0)return Z(`hash: hash table empty +`);let p="";if(n)for(let[m,y]of e.state.hashTable)p+=`builtin hash -p ${y} ${m} +`;else{p=`hits command +`;for(let[,m]of e.state.hashTable)p+=` 1 ${m} +`}return Z(p)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let p of o){if(p.includes("/")){f+=`bash: hash: ${p}: cannot use / in name +`,c=!0;continue}let m=!1;for(let y of h){if(!y)continue;let b=`${y}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found +`,c=!0)}return c?_(f,1):G}var al=new Map([[":",[": [arguments]",`Null command. No effect; the command does nothing. Exit Status: Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell. @@ -498,32 +572,32 @@ eval: usage: eval [arg ...] job specification, and reports its termination status. Exit Status: Returns the status of the last ID; fails if ID is invalid or an invalid - option is given.`]]]),zr=[...Mr.keys()].sort();function fn(e,t){let s=!1,n=[],r=0;for(;r1){for(let u=1;u1){for(let u=1;us.test(n))}function ja(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=zr.slice(),n=Math.ceil(s.length/2);for(let r=0;rs.test(r))}function If(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=ol.slice(),r=Math.ceil(s.length/2);for(let n=0;n0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await j(e,o.expression.expression))}}catch(i){return _(`bash: let: ${r}: ${i.message} -`)}return P("","",n===0?1:0)}async function hn(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function -`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,l=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")o=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(o=!0);else l.push(u);if(l.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d} -`)}return P(u,"",0)}for(let u of l){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let $=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${u}': not a valid identifier -`,r=1;continue}if(ee(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let m=`${c}_`;for(let v of e.state.env.keys())v.startsWith(m)&&!v.includes("__")&&(s.has(v)||s.set(v,e.state.env.get(v)))}let g=`${c}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&e.state.env.delete(m);let b=ke($);for(let m=0;m0&&(m=Math.max(...b)+1);for(let S=0;S=m&&e.state.env.set(`${c}__length`,String(b+1)),ze(e,c),i&&Te(e,c);continue}if(u.includes("=")){let $=u.indexOf("=");c=u.slice(0,$),f=G(e,u.slice($+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${u}': not a valid identifier -`,r=1;continue}let w=s.has(c);if(f!==void 0){let $=e.state.env.get(c);if(e.state.tempEnvBindings){let g=e.state.accessedTempEnvVars?.has(c),b=e.state.mutatedTempEnvVars?.has(c);if(!g&&!b)for(let m=e.state.tempEnvBindings.length-1;m>=0;m--){let v=e.state.tempEnvBindings[m];if(v.has(c)){$=v.get(c);break}}}Ar(e,c,$)}if(!w){let $=e.state.env.get(c);if(e.state.tempEnvBindings)for(let g=e.state.tempEnvBindings.length-1;g>=0;g--){let b=e.state.tempEnvBindings[g];if(b.has(c)){$=b.get(c);break}}if(s.set(c,$),a){let g=`${c}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&(s.has(m)||s.set(m,e.state.env.get(m)));let b=`${c}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}}if(a&&f===void 0){let $=`${c}_`;for(let g of e.state.env.keys())g.startsWith($)&&!g.includes("__")&&e.state.env.delete(g);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(ee(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference -`,r=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let $=e.state.tempEnvBindings?.some(g=>g.has(c));!w&&!$&&e.state.env.delete(c)}ze(e,c),i&&Te(e,c)}return P("",n,r)}function pn(e,t,s){let n=` -`,r=0,i=0,a=0,o=!1,l="MAPFILE",u=0;for(;u0;){let g=d.indexOf(n);if(g===-1){if(d.length>0){if(y=p)return P("",`mapfile: array element limit exceeded (${p}) -`,1);let v=d,E=v.indexOf("\0");E!==-1&&(v=v.substring(0,E)),f.push(v),h++}}break}let b=d.substring(0,g),m=b.indexOf("\0");if(m!==-1&&(b=b.substring(0,m)),!o&&n!=="\0"&&(b+=n),d=d.substring(g+n.length),y0&&h>=r)break;if(i+h>=p)return P("",`mapfile: array element limit exceeded (${p}) -`,1);f.push(b),h++}i===0&&_e(e,l);for(let g=0;g{let D=1;for(;D1&&C!=="--"){let k=p(C,h);if(k.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(k.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=k.nextArgIndex}else if(C==="--")for(h++;h=0?e.state.fileDescriptors?w=e.state.fileDescriptors.get(c)||"":w="":!w&&e.state.groupStdin!==void 0&&(w=e.state.groupStdin);let $=i===""?"\0":i,g="",b=0,m=!0,v=C=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,w.substring(C));else if(n>=0&&e.state.fileDescriptors){let k=e.state.fileDescriptors.get(n);if(k?.startsWith("__rw__:")){let D=Ua(k);if(D){let A=D.position+C;e.state.fileDescriptors.set(n,Za(D.path,A,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=w.substring(C))};if(l>=0){let C=Math.min(l,w.length);g=w.substring(0,C),b=C,m=C>=l,v(b);let k=d[0]||"REPLY";e.state.env.set(k,g);for(let D=1;D=0){let C=0,k=0,D=!1;for(;k=o||D,v(b)}else{b=0;let C=0;for(;C=w.length&&(m=!1,b=C,g.length===0&&w.length===0)){for(let k of d)e.state.env.set(k,"");return u&&_e(e,u),P("","",1)}v(b)}$===` -`&&g.endsWith(` -`)&&(g=g.slice(0,-1));let E=C=>r?C:C.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",E(g)),P("","",m?0:1);let S=zn(e.state.env);if(u){let{words:C}=Es(g,S,void 0,r),k=e.limits?.maxArrayElements??1e5;if(C.length>k)return P("",`read: array element limit exceeded (${k}) -`,1);_e(e,u);for(let D=0;D0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return _(`bash: return: ${n}: numeric argument required -`,2);s=(r%256+256)%256}throw new le(s)}var St=`set: usage: set [-eux] [+eux] [-o option] [+o option] +`)}function Cf(e){let t=[],s="",r=0;for(let n of e){for(let i of n)i==="("?r++:i===")"&&r--;s?s+=` ${n}`:s=n,r===0&&(t.push(s),s="")}return s&&t.push(s),t}async function Ur(e,t){if(t.length===0)return _(`bash: let: expression expected +`);let s=Cf(t),r=0;for(let n of s)try{let a=qe(`(( ${n} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let l=a.pipelines[0].commands[0];l.type==="ArithmeticCommand"&&(r=await L(e,l.expression.expression))}}catch(i){return _(`bash: let: ${n}: ${i.message} +`)}return P("","",r===0?1:0)}async function Zr(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function +`);let s=e.state.localScopes[e.state.localScopes.length-1],r="",n=0,i=!1,a=!1,l=!1,o=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")l=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(l=!0);else o.push(u);if(o.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d} +`)}return P(u,"",0)}for(let u of o){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier +`,n=1;continue}if(me(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let w=`${c}_`;for(let S of e.state.env.keys())S.startsWith(w)&&!S.includes("__")&&(s.has(S)||s.set(S,e.state.env.get(S)))}let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&e.state.env.delete(w);let E=st(b);for(let w=0;w0&&(w=Math.max(...E)+1);for(let $=0;$=w&&e.state.env.set(`${c}__length`,String(E+1)),bt(e,c),i&&ot(e,c);continue}if(u.includes("=")){let b=u.indexOf("=");c=u.slice(0,b),f=ue(e,u.slice(b+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier +`,n=1;continue}let y=s.has(c);if(f!==void 0){let b=e.state.env.get(c);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(c),E=e.state.mutatedTempEnvVars?.has(c);if(!v&&!E)for(let w=e.state.tempEnvBindings.length-1;w>=0;w--){let S=e.state.tempEnvBindings[w];if(S.has(c)){b=S.get(c);break}}}Uo(e,c,b)}if(!y){let b=e.state.env.get(c);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let E=e.state.tempEnvBindings[v];if(E.has(c)){b=E.get(c);break}}if(s.set(c,b),a){let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)));let E=`${c}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}}if(a&&f===void 0){let b=`${c}_`;for(let v of e.state.env.keys())v.startsWith(b)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(me(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){r+=`bash: local: \`${f}': invalid variable name for name reference +`,n=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(c));!y&&!b&&e.state.env.delete(c)}bt(e,c),i&&ot(e,c)}return P("",r,n)}function Hr(e,t,s){let r=` +`,n=0,i=0,a=0,l=!1,o="MAPFILE",u=0;for(;u0;){let v=d.indexOf(r);if(v===-1){if(d.length>0){if(p=m)return P("",`mapfile: array element limit exceeded (${m}) +`,1);let S=d,A=S.indexOf("\0");A!==-1&&(S=S.substring(0,A)),f.push(S),h++}}break}let E=d.substring(0,v),w=E.indexOf("\0");if(w!==-1&&(E=E.substring(0,w)),!l&&r!=="\0"&&(E+=r),d=d.substring(v+r.length),p0&&h>=n)break;if(i+h>=m)return P("",`mapfile: array element limit exceeded (${m}) +`,1);f.push(E),h++}i===0&&Ke(e,o);for(let v=0;v{let C=1;for(;C1&&k!=="--"){let D=m(k,h);if(D.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(D.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=D.nextArgIndex}else if(k==="--")for(h++;h=0?e.state.fileDescriptors?y=e.state.fileDescriptors.get(c)||"":y="":!y&&e.state.groupStdin!==void 0&&(y=e.state.groupStdin);let b=i===""?"\0":i,v="",E=0,w=!0,S=k=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,y.substring(k));else if(r>=0&&e.state.fileDescriptors){let D=e.state.fileDescriptors.get(r);if(D?.startsWith("__rw__:")){let C=xf(D);if(C){let N=C.position+k;e.state.fileDescriptors.set(r,Rf(C.path,N,C.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=y.substring(k))};if(o>=0){let k=Math.min(o,y.length);v=y.substring(0,k),E=k,w=k>=o,S(E);let D=d[0]||"REPLY";e.state.env.set(D,v);for(let C=1;C=0){let k=0,D=0,C=!1;for(;D=l||C,S(E)}else{E=0;let k=0;for(;k=y.length&&(w=!1,E=k,v.length===0&&y.length===0)){for(let D of d)e.state.env.set(D,"");return u&&Ke(e,u),P("","",1)}S(E)}b===` +`&&v.endsWith(` +`)&&(v=v.slice(0,-1));let A=k=>n?k:k.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",A(v)),P("","",w?0:1);let $=he(e.state.env);if(u){let{words:k}=rr(v,$,void 0,n),D=e.limits?.maxArrayElements??1e5;if(k.length>D)return P("",`read: array element limit exceeded (${D}) +`,1);Ke(e,u);for(let C=0;C0){let r=t[0],n=Number.parseInt(r,10);if(r===""||Number.isNaN(n)||!/^-?\d+$/.test(r))return _(`bash: return: ${r}: numeric argument required +`,2);s=(n%256+256)%256}throw new $e(s)}var us=`set: usage: set [-eux] [+eux] [-o option] [+o option] Options: -e Exit immediately if a command exits with non-zero status +e Disable -e @@ -539,173 +613,173 @@ Options: +o pipefail Disable pipefail -o xtrace Same as -x +o xtrace Disable xtrace -`,Vr=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),os=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),Hr=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Ur=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function gn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,it(e))}function qa(e,t){return t+1{let i=e.state.env.get(`${t}_${r}`)??"";return`[${r}]=${Ge(i)}`});return`${t}=(${n.join(" ")})`}function Ka(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Xa(e,t){let s=Fe(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${Ka(r)}]=${Ge(i)}`});return`${t}=(${n.join(" ")} )`}function Ya(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function Qa(e){return e.state.associativeArrays??new Set}function Br(e){let t=Hr.map(n=>`${n.padEnd(16)}${e.state.options[n]?"on":"off"}`),s=Ur.map(n=>`${n.padEnd(16)}off`);return`${[...t,...s].sort().join(` +`,ll=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),un=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),fl=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],dl=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Kr(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,Wt(e))}function Of(e,t){return t+1{let i=e.state.env.get(`${t}_${n}`)??"";return`[${n}]=${kt(i)}`});return`${t}=(${r.join(" ")})`}function Tf(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Wf(e,t){let s=je(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${Tf(n)}]=${kt(i)}`});return`${t}=(${r.join(" ")} )`}function Mf(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let r of e.state.env.keys()){let n=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(n){let i=n[1];s.has(i)||t.add(i)}}return t}function Ff(e){return e.state.associativeArrays??new Set}function cl(e){let t=fl.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),s=dl.map(r=>`${r.padEnd(16)}off`);return`${[...t,...s].sort().join(` `)} -`}function jr(e){let t=Hr.map(n=>`set ${e.state.options[n]?"-o":"+o"} ${n}`),s=Ur.map(n=>`set +o ${n}`);return`${[...t,...s].sort().join(` +`}function ul(e){let t=fl.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),s=dl.map(r=>`set +o ${r}`);return`${[...t,...s].sort().join(` `)} -`}function vn(e,t){if(t.includes("--help"))return F(St);if(t.length===0){let i=Ya(e),a=Qa(e),o=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},l=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||o(c)||h&&a.has(h[1])||l.push([c,f])}let u=[];for(let[c,f]of l.sort(([d],[h])=>dh?1:0))u.push(`${c}=${rs(f)}`);for(let c of[...i].sort((f,d)=>fd?1:0))u.push(Ga(e,c));for(let c of[...a].sort((f,d)=>fd?1:0))u.push(Xa(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return dh?1:0}),F(u.length>0?`${u.join(` +`}function Yr(e,t){if(t.includes("--help"))return Z(us);if(t.length===0){let i=Mf(e),a=Ff(e),l=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||l(c)||h&&a.has(h[1])||o.push([c,f])}let u=[];for(let[c,f]of o.sort(([d],[h])=>dh?1:0))u.push(`${c}=${on(f)}`);for(let c of[...i].sort((f,d)=>fd?1:0))u.push(Lf(e,c));for(let c of[...a].sort((f,d)=>fd?1:0))u.push(Wf(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return dh?1:0}),Z(u.length>0?`${u.join(` `)} -`:"")}let s=[],n=()=>s.length>0?F(s.join("")):W,r=0;for(;r1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",o=0;for(let l=1;l0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required -`;if(e.state.options.posix)throw new me(1,"",o);return _(o)}s=a}let n=Number.parseInt(e.state.env.get("#")||"0",10);if(s>n){let a=`bash: shift: shift count out of range -`;if(e.state.options.posix)throw new me(1,"",a);return _(a)}if(s===0)return W;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env.get(String(a))||"");let i=r.slice(s);for(let a=1;a<=n;a++)e.state.env.delete(String(a));for(let a=0;a0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required -`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(f),r=f}catch{}}}if(i===null)return _(`bash: ${n}: No such file or directory -`);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Y(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=n;try{let u=$e(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof B)throw u;if(u instanceof le)return P(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${n}: ${u.message} -`);throw u}}function Zr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Ja(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function qr(e,t){if(Ja(t))return null;try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Gr(e,t){if(e.state.localVarStack?.has(t)){let n=ts(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),En(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||es(e,t),!0}}return!1}function En(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function Kr(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new V().parseWordFromString(s,!0,!1);return x(e,r)}if(t.includes("$")){let n=new V().parseWordFromString(t,!1,!1);return x(e,n)}return t}async function Sn(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let b=Ee(e,d);for(let[m]of b)e.state.env.delete(`${d}_${m}`);e.state.env.delete(d);continue}let y=e.state.associativeArrays?.has(d);if(y){let b=await Kr(e,h);e.state.env.delete(`${d}_${b}`);continue}let p=_s(e,d),w=e.state.declaredVars?.has(d);if((e.state.env.has(d)||w)&&!p&&!y){n+=`bash: unset: ${d}: not an array variable -`,r=1;continue}let g=await qr(e,h);if(g===null&&p){n+=`bash: unset: ${h}: not a valid identifier -`,r=1;continue}if(g===null)continue;if(g<0){let b=Ee(e,d),m=b.length,v=e.state.currentLine;if(m===0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript -`,r=1;continue}let E=m+g;if(E<0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript -`,r=1;continue}let S=b[E][0];e.state.env.delete(`${d}_${S}`);continue}e.state.env.delete(`${d}_${g}`);continue}if(!Zr(i)){n+=`bash: unset: \`${i}': not a valid identifier -`,r=1;continue}let c=i;if(ge(e,i)){let d=We(e,i);d&&d!==i&&(c=d)}if(Ue(e,c)){n+=`bash: unset: ${c}: cannot unset: readonly variable -`,r=1;continue}let f=ot(e,c);if(f!==void 0&&f!==e.state.callDepth)Gr(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let y=ts(e,c);y?y.value===void 0?e.state.env.delete(c):e.state.env.set(c,y.value):e.state.env.delete(c)}else e.state.env.delete(c)}else En(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let p=Ee(e,u);for(let[w]of p)e.state.env.delete(`${u}_${w}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let p=await Kr(e,c);e.state.env.delete(`${u}_${p}`);continue}let d=_s(e,u);if(e.state.env.has(u)&&!d&&!f){n+=`bash: unset: ${u}: not an array variable -`,r=1;continue}let y=await qr(e,c);if(y===null&&d){n+=`bash: unset: ${c}: not a valid identifier -`,r=1;continue}if(y===null)continue;if(y<0){let p=Ee(e,u),w=p.length,$=e.state.currentLine;if(w===0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript -`,r=1;continue}let g=w+y;if(g<0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript -`,r=1;continue}let b=p[g][0];e.state.env.delete(`${u}_${b}`);continue}e.state.env.delete(`${u}_${y}`);continue}if(!Zr(i)){n+=`bash: unset: \`${i}': not a valid identifier -`,r=1;continue}let o=i;if(ge(e,i)){let u=We(e,i);u&&u!==i&&(o=u)}if(Ue(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable -`,r=1;continue}let l=ot(e,o);if(l!==void 0&&l!==e.state.callDepth)Gr(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((u||c)&&e.state.localVarStack?.has(o)){let f=ts(e,o);f?f.value===void 0?e.state.env.delete(o):e.state.env.set(o,f.value):e.state.env.delete(o)}else e.state.env.delete(o)}else En(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return P("",n,r)}var An=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],eo=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function ls(e){return An.includes(e)}function to(e){return eo.includes(e)}function Xr(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],l=0;for(;l1){for(let h=1;h0?`${h.join(` +`:"")}let s=[],r=()=>s.length>0?Z(s.join("")):G,n=0;for(;n1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",l=0;for(let o=1;o0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let l=`bash: shift: ${t[0]}: numeric argument required +`;if(e.state.options.posix)throw new Me(1,"",l);return _(l)}s=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(s>r){let a=`bash: shift: shift count out of range +`;if(e.state.options.posix)throw new Me(1,"",a);return _(a)}if(s===0)return G;let n=[];for(let a=1;a<=r;a++)n.push(e.state.env.get(String(a))||"");let i=n.slice(s);for(let a=1;a<=r;a++)e.state.env.delete(String(a));for(let a=0;a0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required +`,2);let r=s[0],n=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),n=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),n=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),n=f}catch{}}}if(i===null)return _(`bash: ${r}: No such file or directory +`);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c{if(e.state.sourceDepth--,e.state.currentSource=l,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Q(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=qe(i),c=await e.executeScript(u);return o(),c}catch(u){if(o(),u instanceof j)throw u;if(u instanceof $e)return P(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${r}: ${u.message} +`);throw u}}function hl(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Vf(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function pl(e,t){if(Vf(t))return null;try{let s=new V,r=X(s,t);return await L(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function ml(e,t){if(e.state.localVarStack?.has(t)){let r=sn(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let n=e.state.localVarStack?.get(t);if(!n||n.length===0)tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),ti(e,t);else{let i=n[n.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let n=e.state.localScopes[r];if(n.has(t)){let i=n.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),n.delete(t);let a=!1;for(let l=r-1;l>=0;l--)if(e.state.localScopes[l].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,l+1),a=!0;break}return a||tn(e,t),!0}}return!1}function ti(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let r=e.state.tempEnvBindings[s];if(r.has(t)){let n=r.get(t);return n===void 0?e.state.env.delete(t):e.state.env.set(t,n),r.delete(t),!0}}return!1}async function gl(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),n=new V().parseWordFromString(s,!0,!1);return W(e,n)}if(t.includes("$")){let r=new V().parseWordFromString(t,!1,!1);return W(e,r)}return t}async function si(e,t){let s="both",r="",n=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let E=F(e,d);for(let[w]of E)e.state.env.delete(`${d}_${w}`);e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let E=await gl(e,h);e.state.env.delete(`${d}_${E}`);continue}let m=Ue(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable +`,n=1;continue}let v=await pl(e,h);if(v===null&&m){r+=`bash: unset: ${h}: not a valid identifier +`,n=1;continue}if(v===null)continue;if(v<0){let E=F(e,d),w=E.length,S=e.state.currentLine;if(w===0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript +`,n=1;continue}let A=w+v;if(A<0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript +`,n=1;continue}let $=E[A][0];e.state.env.delete(`${d}_${$}`);continue}e.state.env.delete(`${d}_${v}`);continue}if(!hl(i)){r+=`bash: unset: \`${i}': not a valid identifier +`,n=1;continue}let c=i;if(ee(e,i)){let d=ve(e,i);d&&d!==i&&(c=d)}if(Je(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable +`,n=1;continue}let f=Bt(e,c);if(f!==void 0&&f!==e.state.callDepth)ml(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let p=sn(e,c);p?p.value===void 0?e.state.env.delete(c):e.state.env.set(c,p.value):e.state.env.delete(c)}else e.state.env.delete(c)}else ti(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let m=F(e,u);for(let[y]of m)e.state.env.delete(`${u}_${y}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await gl(e,c);e.state.env.delete(`${u}_${m}`);continue}let d=Ue(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable +`,n=1;continue}let p=await pl(e,c);if(p===null&&d){r+=`bash: unset: ${c}: not a valid identifier +`,n=1;continue}if(p===null)continue;if(p<0){let m=F(e,u),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript +`,n=1;continue}let v=y+p;if(v<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript +`,n=1;continue}let E=m[v][0];e.state.env.delete(`${u}_${E}`);continue}e.state.env.delete(`${u}_${p}`);continue}if(!hl(i)){r+=`bash: unset: \`${i}': not a valid identifier +`,n=1;continue}let l=i;if(ee(e,i)){let u=ve(e,i);u&&u!==i&&(l=u)}if(Je(e,l)){r+=`bash: unset: ${l}: cannot unset: readonly variable +`,n=1;continue}let o=Bt(e,l);if(o!==void 0&&o!==e.state.callDepth)ml(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(o!==void 0){let u=e.state.accessedTempEnvVars?.has(l),c=e.state.mutatedTempEnvVars?.has(l);if((u||c)&&e.state.localVarStack?.has(l)){let f=sn(e,l);f?f.value===void 0?e.state.env.delete(l):e.state.env.set(l,f.value):e.state.env.delete(l)}else e.state.env.delete(l)}else ti(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l),e.state.functions.delete(i)}return P("",r,n)}var ni=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],zf=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function fn(e){return ni.includes(e)}function Bf(e){return zf.includes(e)}function yl(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=[],o=0;for(;o1){for(let h=1;h0?`${h.join(` `)} -`:"",stderr:""}}let d=[];for(let h of An){let y=e.state.shoptOptions[h];d.push(r?`shopt ${y?"-s":"-u"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(` +`:"",stderr:""}}let d=[];for(let h of ni){let p=e.state.shoptOptions[h];d.push(n?`shopt ${p?"-s":"-u"} ${h}`:`${h} ${p?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(` `)} -`,stderr:""}}let u=!1,c="",f=[];for(let d of o){if(!ls(d)&&!to(d)){c+=`shopt: ${d}: invalid shell option name -`,u=!0;continue}if(s)ls(d)&&(e.state.shoptOptions[d]=!0,Ts(e));else if(n)ls(d)&&(e.state.shoptOptions[d]=!1,Ts(e));else if(ls(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):r?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:r?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` +`,stderr:""}}let u=!1,c="",f=[];for(let d of l){if(!fn(d)&&!Bf(d)){c+=`shopt: ${d}: invalid shell option name +`,u=!0;continue}if(s)fn(d)&&(e.state.shoptOptions[d]=!0,Dn(e));else if(r)fn(d)&&(e.state.shoptOptions[d]=!1,Dn(e));else if(fn(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):n?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:n?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` `)} -`:"",stderr:c}}function so(e,t,s,n,r,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],l=[...a.keys(),...o].sort();if(t.length===0){let d=[];for(let h of l){let y=o.includes(h),p=a.get(h),w=y||!p?!1:e.state.options[p];s&&!w||n&&w||d.push(r?`set ${w?"-o":"+o"} ${h}`:`${h} ${w?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(` +`:"",stderr:c}}function qf(e,t,s,r,n,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],o=[...a.keys(),...l].sort();if(t.length===0){let d=[];for(let h of o){let p=l.includes(h),m=a.get(h),y=p||!m?!1:e.state.options[m];s&&!y||r&&y||d.push(n?`set ${y?"-o":"+o"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(` `)} -`:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),y=o.includes(d);if(!h&&!y){c+=`shopt: ${d}: invalid option name -`,u=!0;continue}if(y){s||n||(i?u=!0:r?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,it(e);else if(n)e.state.options[p]=!1,it(e);else{let w=e.state.options[p];i?w||(u=!0):r?(f.push(`set ${w?"-o":"+o"} ${d}`),w||(u=!0)):(f.push(`${d} ${w?"on":"off"}`),w||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` +`:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),p=l.includes(d);if(!h&&!p){c+=`shopt: ${d}: invalid option name +`,u=!0;continue}if(p){s||r||(i?u=!0:n?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let m=a.get(d);if(m)if(s)m==="vi"?e.state.options.emacs=!1:m==="emacs"&&(e.state.options.vi=!1),e.state.options[m]=!0,Wt(e);else if(r)e.state.options[m]=!1,Wt(e);else{let y=e.state.options[m];i?y||(u=!0):n?(f.push(`set ${y?"-o":"+o"} ${d}`),y||(u=!0)):(f.push(`${d} ${y?"on":"off"}`),y||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` `)} -`:"",stderr:c}}async function Yr(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,l=e.commands.get(o);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:l?{cmd:l,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let l=await e.fs.stat(a);if(!l.isDirectory&&(l.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function cs(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}function no(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function Z(e,t,s,n){return((...r)=>{yt(t,s,`${n} call`);let i=e(...r);return no(i)?i.then(a=>(yt(t,s,`${n} post-await`),a),a=>{throw yt(t,s,`${n} post-await`),a}):(yt(t,s,`${n} return`),i)})}function ro(e,t,s){let n={readFile:Z(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:Z(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:Z(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:Z(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:Z(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:Z(e.exists.bind(e),t,s,"fs.exists"),stat:Z(e.stat.bind(e),t,s,"fs.stat"),mkdir:Z(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:Z(e.readdir.bind(e),t,s,"fs.readdir"),rm:Z(e.rm.bind(e),t,s,"fs.rm"),cp:Z(e.cp.bind(e),t,s,"fs.cp"),mv:Z(e.mv.bind(e),t,s,"fs.mv"),resolvePath:Z(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:Z(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:Z(e.chmod.bind(e),t,s,"fs.chmod"),symlink:Z(e.symlink.bind(e),t,s,"fs.symlink"),link:Z(e.link.bind(e),t,s,"fs.link"),readlink:Z(e.readlink.bind(e),t,s,"fs.readlink"),lstat:Z(e.lstat.bind(e),t,s,"fs.lstat"),realpath:Z(e.realpath.bind(e),t,s,"fs.realpath"),utimes:Z(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(n.readdirWithFileTypes=Z(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),n}function Qr(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,n={...e,fs:ro(e.fs,e.requireDefenseContext,s)};return e.exec&&(n.exec=Z(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(n.fetch=Z(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(n.sleep=Z(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(n.getRegisteredCommands=Z(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),n}async function si(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,l=!1,u=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let w of p.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?a=!0:w==="a"?o=!0:w==="f"&&(l=!0);else u.push(p);let c="",f="",d=0,h=!1,y=!1;for(let p of u){let w=!1;if(a){if(o){let E=await n(p);if(E.length>0){for(let S of E)c+=`${S} -`;h=!0,w=!0}}else{let E=await s(p);E&&(c+=`${E} -`,h=!0,w=!0)}w||(y=!0);continue}let $=!l&&e.state.functions.has(p);if(o&&$){if(!i)if(r)c+=`function -`;else{let E=e.state.functions.get(p),S=E?Jr(p,E):`${p} is a function -`;c+=S}w=!0}let g=e.state.env.get(`BASH_ALIAS_${p}`);if(g!==void 0&&(o||!w)&&(i||(r?c+=`alias -`:c+=`${p} is aliased to \`${g}' -`),w=!0,!o)||zs.has(p)&&(o||!w)&&(i||(r?c+=`keyword -`:c+=`${p} is a shell keyword -`),w=!0,!o))continue;if(!o&&$&&!w){if(!i)if(r)c+=`function -`;else{let E=e.state.functions.get(p),S=E?Jr(p,E):`${p} is a function -`;c+=S}w=!0;continue}if(!(lt.has(p)&&(o||!w)&&(i||(r?c+=`builtin -`:c+=`${p} is a shell builtin -`),w=!0,!o))){if(o){let E=await n(p);for(let S of E)i?c+=`${S} -`:r?c+=`file -`:c+=`${p} is ${S} -`,h=!0,w=!0}else if(!w){let E=await s(p);E&&(i?c+=`${E} -`:r?c+=`file -`:c+=`${p} is ${E} -`,h=!0,w=!0)}if(!w&&(y=!0,!r&&!i)){let E=!0;if(p.includes("/")){let S=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(S)&&(E=!1)}E&&(f+=`bash: type: ${p}: not found -`)}}}return i?d=y&&!h?1:0:d=y?1:0,P(c,f,d)}function Jr(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>At(r)).join("; "):s=At(t.body),`${e} is a function +`:"",stderr:c}}async function wl(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let l=a.split("/").pop()||t,o=e.commands.get(l);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:o?{cmd:o,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let l=e.commands.get(t);if(l)return{cmd:l,path:a};try{let o=await e.fs.stat(a);if(!o.isDirectory&&(o.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let n=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of n){if(!a)continue;let o=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(o))try{let u=await e.fs.stat(o);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:o};if(c){if(f&&!d)return{script:!0,path:o};if(!f)return{script:!0,path:o}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function dn(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let n=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of n){if(!i)continue;let l=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(l)){try{if((await e.fs.stat(l)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?l:`${i}/${t}`)}}return s}function jf(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function ie(e,t,s,r){return((...n)=>{Xt(t,s,`${r} call`);let i=e(...n);return jf(i)?i.then(a=>(Xt(t,s,`${r} post-await`),a),a=>{throw Xt(t,s,`${r} post-await`),a}):(Xt(t,s,`${r} return`),i)})}function Uf(e,t,s){let r={readFile:ie(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:ie(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:ie(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:ie(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:ie(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:ie(e.exists.bind(e),t,s,"fs.exists"),stat:ie(e.stat.bind(e),t,s,"fs.stat"),mkdir:ie(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:ie(e.readdir.bind(e),t,s,"fs.readdir"),rm:ie(e.rm.bind(e),t,s,"fs.rm"),cp:ie(e.cp.bind(e),t,s,"fs.cp"),mv:ie(e.mv.bind(e),t,s,"fs.mv"),resolvePath:ie(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:ie(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:ie(e.chmod.bind(e),t,s,"fs.chmod"),symlink:ie(e.symlink.bind(e),t,s,"fs.symlink"),link:ie(e.link.bind(e),t,s,"fs.link"),readlink:ie(e.readlink.bind(e),t,s,"fs.readlink"),lstat:ie(e.lstat.bind(e),t,s,"fs.lstat"),realpath:ie(e.realpath.bind(e),t,s,"fs.realpath"),utimes:ie(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=ie(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),r}function El(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,r={...e,fs:Uf(e.fs,e.requireDefenseContext,s)};return e.exec&&(r.exec=ie(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(r.fetch=ie(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(r.sleep=ie(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=ie(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),r}async function Al(e,t,s,r){let n=!1,i=!1,a=!1,l=!1,o=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let y of m.slice(1))y==="t"?n=!0:y==="p"?i=!0:y==="P"?a=!0:y==="a"?l=!0:y==="f"&&(o=!0);else u.push(m);let c="",f="",d=0,h=!1,p=!1;for(let m of u){let y=!1;if(a){if(l){let A=await r(m);if(A.length>0){for(let $ of A)c+=`${$} +`;h=!0,y=!0}}else{let A=await s(m);A&&(c+=`${A} +`,h=!0,y=!0)}y||(p=!0);continue}let b=!o&&e.state.functions.has(m);if(l&&b){if(!i)if(n)c+=`function +`;else{let A=e.state.functions.get(m),$=A?bl(m,A):`${m} is a function +`;c+=$}y=!0}let v=e.state.env.get(`BASH_ALIAS_${m}`);if(v!==void 0&&(l||!y)&&(i||(n?c+=`alias +`:c+=`${m} is aliased to \`${v}' +`),y=!0,!l)||br.has(m)&&(l||!y)&&(i||(n?c+=`keyword +`:c+=`${m} is a shell keyword +`),y=!0,!l))continue;if(!l&&b&&!y){if(!i)if(n)c+=`function +`;else{let A=e.state.functions.get(m),$=A?bl(m,A):`${m} is a function +`;c+=$}y=!0;continue}if(!(qt.has(m)&&(l||!y)&&(i||(n?c+=`builtin +`:c+=`${m} is a shell builtin +`),y=!0,!l))){if(l){let A=await r(m);for(let $ of A)i?c+=`${$} +`:n?c+=`file +`:c+=`${m} is ${$} +`,h=!0,y=!0}else if(!y){let A=await s(m);A&&(i?c+=`${A} +`:n?c+=`file +`:c+=`${m} is ${A} +`,h=!0,y=!0)}if(!y&&(p=!0,!n&&!i)){let A=!0;if(m.includes("/")){let $=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists($)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found +`)}}}return i?d=p&&!h?1:0:d=p?1:0,P(c,f,d)}function bl(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(n=>fs(n)).join("; "):s=fs(t.body),`${e} is a function ${e} () { ${s} } -`}function At(e){if(Array.isArray(e))return e.map(t=>At(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;sAt(n)).join("; ")}; }`:"..."}function io(e){let t=e.commands.map(s=>At(s));return(e.negated?"! ":"")+t.join(" | ")}function ei(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>ti(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=ti(s);return t}function ti(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function ni(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let l=e.state.env.get(`BASH_ALIAS_${o}`);if(l!==void 0)n?r+=`${o} is an alias for "${l}" -`:r+=`alias ${o}='${l}' -`;else if(zs.has(o))n?r+=`${o} is a shell keyword -`:r+=`${o} -`;else if(lt.has(o))n?r+=`${o} is a shell builtin -`:r+=`${o} -`;else if(e.state.functions.has(o))n?r+=`${o} is a function -`:r+=`${o} -`;else if(o.includes("/")){let u=e.fs.resolvePath(e.state.cwd,o),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(n?r+=`${o} is ${o} -`:r+=`${o} -`,c=!0)}catch{}c||(n&&(i+=`${o}: not found -`),a=1)}else if(e.commands.has(o)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${o}`;try{let y=await e.fs.stat(h);if(!y.isDirectory&&(y.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${o}`),n?r+=`${o} is ${f} -`:r+=`${f} -`}else n&&(i+=`${o}: not found -`),a=1}return P(r,i,a)}async function ri(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function ii(e,t,s,n,r,i,a,o){let{ctx:l,runCommand:u}=e;if(l.coverage&<.has(t)&&l.coverage.hit(`bash:builtin:${t}`),t==="export")return cn(l,s);if(t==="unset")return Sn(l,s);if(t==="exit")return ln(l,s);if(t==="local")return hn(l,s);if(t==="set")return vn(l,s);if(t==="break")return Is(l,s);if(t==="continue")return qs(l,s);if(t==="return")return yn(l,s);if(t==="eval"&&l.state.options.posix)return is(l,s,r);if(t==="shift")return bn(l,s);if(t==="getopts")return as(l,s);if(t==="compgen")return js(l,s);if(t==="complete")return Us(l,s);if(t==="compopt")return Zs(l,s);if(t==="pushd")return await rn(l,s);if(t==="popd")return an(l,s);if(t==="dirs")return on(l,s);if(t==="source"||t===".")return $n(l,s);if(t==="read")return mn(l,s,r,o);if(t==="mapfile"||t==="readarray")return pn(l,s,r);if(t==="declare"||t==="typeset")return tn(l,s);if(t==="readonly")return sn(l,s);if(!i){let c=l.state.functions.get(t);if(c)return ns(l,c,s,r)}if(t==="eval")return is(l,s,r);if(t==="cd")return await Rs(l,s);if(t===":"||t==="true")return W;if(t==="false")return X(!1);if(t==="let")return dn(l,s);if(t==="command")return ao(e,s,r);if(t==="builtin")return oo(e,s,r);if(t==="shopt")return Xr(l,s);if(t==="exec"){if(s.length===0)return W;let[c,...f]=s;return u(c,f,[],r,!1,!1,-1)}if(t==="wait")return W;if(t==="type")return await si(l,s,c=>ri(l,c),c=>cs(l,c));if(t==="hash")return un(l,s);if(t==="help")return fn(l,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);c=s.slice(0,-1)}return bt(l,c)}return null}async function ao(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return W;let i=!1,a=!1,o=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let f=l[0];if(f==="--"){l=l.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return W;if(o||a)return await ni(n,l,o,a);let[u,...c]=l;return r(u,c,[],s,!0,i,-1)}async function oo(e,t,s){let{runCommand:n}=e;if(t.length===0)return W;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return W;let i=r[0];if(!lt.has(i))return _(`bash: builtin: ${i}: not a shell builtin -`);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function ai(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,u=await Yr(i,t,r?"/usr/bin:/bin":void 0);if(!u)return hr(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle. +`}function fs(e){if(Array.isArray(e))return e.map(t=>fs(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;sfs(r)).join("; ")}; }`:"..."}function Zf(e){let t=e.commands.map(s=>fs(s));return(e.negated?"! ":"")+t.join(" | ")}function vl(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(r=>Sl(r)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=Sl(s);return t}function Sl(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function $l(e,t,s,r){let n="",i="",a=0;for(let l of t){if(!l){a=1;continue}let o=e.state.env.get(`BASH_ALIAS_${l}`);if(o!==void 0)r?n+=`${l} is an alias for "${o}" +`:n+=`alias ${l}='${o}' +`;else if(br.has(l))r?n+=`${l} is a shell keyword +`:n+=`${l} +`;else if(qt.has(l))r?n+=`${l} is a shell builtin +`:n+=`${l} +`;else if(e.state.functions.has(l))r?n+=`${l} is a function +`:n+=`${l} +`;else if(l.includes("/")){let u=e.fs.resolvePath(e.state.cwd,l),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(r?n+=`${l} is ${l} +`:n+=`${l} +`,c=!0)}catch{}c||(r&&(i+=`${l}: not found +`),a=1)}else if(e.commands.has(l)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${l}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${l}`),r?n+=`${l} is ${f} +`:n+=`${f} +`}else r&&(i+=`${l}: not found +`),a=1}return P(n,i,a)}async function Nl(e,t){if(t.includes("/")){let n=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(n)){try{let i=await e.fs.stat(n);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let n of r){if(!n)continue;let a=`${n.startsWith("/")?n:e.fs.resolvePath(e.state.cwd,n)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${n}/${t}`}}if(e.commands.has(t)){for(let n of r)if(n==="/usr/bin"||n==="/bin")return`${n}/${t}`;return`/usr/bin/${t}`}return null}async function kl(e,t,s,r,n,i,a,l){let{ctx:o,runCommand:u}=e;if(o.coverage&&qt.has(t)&&o.coverage.hit(`bash:builtin:${t}`),t==="export")return Br(o,s);if(t==="unset")return si(o,s);if(t==="exit")return zr(o,s);if(t==="local")return Zr(o,s);if(t==="set")return Yr(o,s);if(t==="break")return pr(o,s);if(t==="continue")return _r(o,s);if(t==="return")return Qr(o,s);if(t==="eval"&&o.state.options.posix)return ln(o,s,n);if(t==="shift")return Jr(o,s);if(t==="getopts")return cn(o,s);if(t==="compgen")return Ar(o,s);if(t==="complete")return Nr(o,s);if(t==="compopt")return kr(o,s);if(t==="pushd")return await Mr(o,s);if(t==="popd")return Fr(o,s);if(t==="dirs")return Vr(o,s);if(t==="source"||t===".")return ei(o,s);if(t==="read")return Gr(o,s,n,l);if(t==="mapfile"||t==="readarray")return Hr(o,s,n);if(t==="declare"||t==="typeset")return Lr(o,s);if(t==="readonly")return Tr(o,s);if(!i){let c=o.state.functions.get(t);if(c)return an(o,c,s,n)}if(t==="eval")return ln(o,s,n);if(t==="cd")return await mr(o,s);if(t===":"||t==="true")return G;if(t==="false")return de(!1);if(t==="let")return Ur(o,s);if(t==="command")return Hf(e,s,n);if(t==="builtin")return Gf(e,s,n);if(t==="shopt")return yl(o,s);if(t==="exec"){if(s.length===0)return G;let[c,...f]=s;return u(c,f,[],n,!1,!1,-1)}if(t==="wait")return G;if(t==="type")return await Al(o,s,c=>Nl(o,c),c=>dn(o,c));if(t==="hash")return qr(o,s);if(t==="help")return jr(o,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);c=s.slice(0,-1)}return os(o,c)}return null}async function Hf(e,t,s){let{ctx:r,runCommand:n}=e;if(t.length===0)return G;let i=!1,a=!1,l=!1,o=t;for(;o.length>0&&o[0].startsWith("-");){let f=o[0];if(f==="--"){o=o.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(l=!0);o=o.slice(1)}if(o.length===0)return G;if(l||a)return await $l(r,o,l,a);let[u,...c]=o;return n(u,c,[],s,!0,i,-1)}async function Gf(e,t,s){let{runCommand:r}=e;if(t.length===0)return G;let n=t;if(n[0]==="--"&&(n=n.slice(1),n.length===0))return G;let i=n[0];if(!qt.has(i))return _(`bash: builtin: ${i}: not a shell builtin +`);let[,...a]=n;return r(i,a,[],s,!0,!1,-1)}async function _l(e,t,s,r,n){let{ctx:i,buildExportedEnv:a,executeUserScript:l}=e,u=await wl(i,t,n?"/usr/bin:/bin":void 0);if(!u)return Oo(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle. `,127):_(`bash: ${t}: command not found `,127);if("error"in u)return u.error==="permission_denied"?_(`bash: ${t}: Permission denied `,126):_(`bash: ${t}: No such file or directory -`,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await o(u.path,s,n);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=n||i.state.groupStdin||"",h=a(),y={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},p=Qr(y,t);try{let w=()=>Fn(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,p));return c.trusted?await be.runTrustedAsync(()=>w()):await w()}catch(w){if(w instanceof Y||w instanceof Qe)throw w;return _(`${t}: ${he(De(w))} -`)}}async function _n(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function _t(e,t,s,n){if(e instanceof fe)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof de)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof le||e instanceof pe||e instanceof B||e instanceof Y)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=De(e);return{action:"error",stdout:t,stderr:`${s}${r} -`,exitCode:1}}async function us(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let l=await e.executeStatement(o);r+=l.stdout,i+=l.stderr,a=l.exitCode}}catch(o){if(It(o)||o instanceof pe||o instanceof B||o instanceof Y||o instanceof Ie)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${De(o)} -`,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function oi(e,t){let s="",n="";for(let r of t.clauses){let i=await _n(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return us(e,r.body,s,n)}return t.elseBody?us(e,t.elseBody,s,n):P(s,n,0)}async function li(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier -`);let o=[];if(t.words===null)o=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let u of t.words){let c=await Ce(e,u);o.push(...c.values)}}catch(u){if(u instanceof Tt)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of o){a++,a>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);n+=f.stdout,r+=f.stderr,i=f.exitCode}}catch(c){let f=_t(c,n,r,e.state.loopDepth);if(n=f.stdout,r=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=P(n,r,f.exitCode??1);return q(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let l=P(n,r,i);return q(e,l,t.redirections)}async function ci(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",a=0,o=0;t.init&&await j(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await j(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);r+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=_t(u,r,i,e.state.loopDepth);if(r=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await j(e,t.update.expression);continue}if(c.action==="error"){let f=P(r,i,c.exitCode??1);return q(e,f,t.redirections)}throw c.error}t.update&&await j(e,t.update.expression)}}finally{e.state.loopDepth--}let l=P(r,i,a);return q(e,l,t.redirections)}async function ui(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await x(e,c.content);c.stripTabs&&(f=f.split(` +`,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await l(u.path,s,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",h=a(),p={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},m=El(p,t);try{let y=()=>pi(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,m));return c.trusted?await Be.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof Q||y instanceof It)throw y;return _(`${t}: ${Re(it(y))} +`)}}async function ri(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let r="",n="",i=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,n+=l.stderr,i=l.exitCode}}finally{e.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function ds(e,t,s,r){if(e instanceof De)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof Ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof $e||e instanceof We||e instanceof j||e instanceof Q)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let n=it(e);return{action:"error",stdout:t,stderr:`${s}${n} +`,exitCode:1}}async function hn(e,t,s="",r=""){let n=s,i=r,a=0;try{for(let l of t){let o=await e.executeStatement(l);n+=o.stdout,i+=o.stderr,a=o.exitCode}}catch(l){if(bs(l)||l instanceof We||l instanceof j||l instanceof Q||l instanceof ut)throw l.prependOutput(n,i),l;return{stdout:n,stderr:`${i}${it(l)} +`,exitCode:1}}return{stdout:n,stderr:i,exitCode:a}}async function Pl(e,t){let s="",r="";for(let n of t.clauses){let i=await ri(e,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return hn(e,n.body,s,r)}return t.elseBody?hn(e,t.elseBody,s,r):P(s,r,0)}async function Dl(e,t){let s=await nt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier +`);let l=[];if(t.words===null)l=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)l=[];else try{for(let u of t.words){let c=await et(e,u);l.push(...c.values)}}catch(u){if(u instanceof ct)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of l){a++,a>e.limits.maxLoopIterations&&tt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,n+=f.stderr,i=f.exitCode}}catch(c){let f=ds(c,r,n,e.state.loopDepth);if(r=f.stdout,n=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=P(r,n,f.exitCode??1);return le(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let o=P(r,n,i);return le(e,o,t.redirections)}async function Il(e,t){let s=await nt(e,t.redirections);if(s)return s;let r=t.line;r!==void 0&&(e.state.currentLine=r);let n="",i="",a=0,l=0;t.init&&await L(e,t.init.expression),e.state.loopDepth++;try{for(;l++,l>e.limits.maxLoopIterations&&tt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,i),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await L(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);n+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=ds(u,n,i,e.state.loopDepth);if(n=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await L(e,t.update.expression);continue}if(c.action==="error"){let f=P(n,i,c.exitCode??1);return le(e,f,t.redirections)}throw c.error}t.update&&await L(e,t.update.expression)}}finally{e.state.loopDepth--}let o=P(n,i,a);return le(e,o,t.redirections)}async function Cl(e,t,s=""){let r="",n="",i=0,a=0,l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await W(e,c.content);c.stripTabs&&(f=f.split(` `).map(d=>d.replace(/^\t+/,"")).join(` -`)),o=f}else if(u.operator==="<<<"&&u.target.type==="Word")o=`${await x(e,u.target)} -`;else if(u.operator==="<"&&u.target.type==="Word")try{let c=await x(e,u.target),f=e.fs.resolvePath(e.state.cwd,c);o=await e.fs.readFile(f)}catch{let c=await x(e,u.target);return _(`bash: ${c}: No such file or directory -`)}let l=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Pe(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,u=y.exitCode}}catch(h){if(h instanceof fe){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;c=!0}else if(h instanceof de){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,i=y.exitCode}}catch(h){let y=_t(h,n,r,e.state.loopDepth);if(n=y.stdout,r=y.stderr,y.action==="break")break;if(y.action==="continue")continue;if(y.action==="error")return P(n,r,y.exitCode??1);throw y.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return P(n,r,i)}async function fi(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Pe(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await _n(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let l=await e.executeStatement(o);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(o){let l=_t(o,s,n,e.state.loopDepth);if(s=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return P(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return P(s,n,r)}async function di(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await x(e,t.word),o=!1;for(let u=0;uco(t)).join(" ")}function co(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(` -`),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let l="";for(let u of e){let c=u.charCodeAt(0);u===` -`?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function yi(e,t,s){if(!e.state.options.xtrace)return"";let n=await mi(e),r=[t,...s],i=lo(r);return`${n}${i} -`}async function gi(e,t,s){return e.state.options.xtrace?`${await mi(e)}${t}=${s} -`:""}async function vi(e,t,s){let n=t.timed?vs():0,r="",i=W,a=0,o=[],l="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else if(b instanceof pe&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else throw $&&(e.state.env=$),b}$&&(e.state.env=$),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),y?i=g:(t.pipeStderr?.[d]??!1?r=je(g.stderr)+ys(g):(r=ys(g),l+=g.stderr),i={stdout:"",stderr:"",exitCode:g.exitCode})}if(l&&(i={...i,stderr:l+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;de.limits.maxLoopIterations&&tt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,u=p.exitCode}}catch(h){if(h instanceof De){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;c=!0}else if(h instanceof Ie){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,i=p.exitCode}}catch(h){let p=ds(h,r,n,e.state.loopDepth);if(r=p.stdout,n=p.stderr,p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return P(r,n,p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return P(r,n,i)}async function xl(e,t){let s="",r="",n=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&tt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r);let a=await ri(e,t.condition);if(s+=a.stdout,r+=a.stderr,a.exitCode===0)break;try{for(let l of t.body){let o=await e.executeStatement(l);s+=o.stdout,r+=o.stderr,n=o.exitCode}}catch(l){let o=ds(l,s,r,e.state.loopDepth);if(s=o.stdout,r=o.stderr,o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return P(s,r,o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return P(s,r,n)}async function Rl(e,t){let s=await nt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=await W(e,t.word),l=!1;for(let u=0;uKf(t)).join(" ")}function Kf(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),r=e.includes(` +`),n=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||r||n||i){let o="";for(let u of e){let c=u.charCodeAt(0);u===` +`?o+="\\n":u===" "?o+="\\t":u==="\\"?o+="\\\\":u==="'"?o+="'":u==='"'?o+='"':c<32||c===127?c<256?o+=`\\x${c.toString(16).padStart(2,"0")}`:o+=`\\u${c.toString(16).padStart(4,"0")}`:o+=u}return`$'${o}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Wl(e,t,s){if(!e.state.options.xtrace)return"";let r=await Tl(e),n=[t,...s],i=Qf(n);return`${r}${i} +`}async function Ml(e,t,s){return e.state.options.xtrace?`${await Tl(e)}${t}=${s} +`:""}async function Vl(e,t,s){let r=t.timed?Sn():0,n="",i=G,a=0,l=[],o="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else if(E instanceof We&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else throw b&&(e.state.env=b),E}b&&(e.state.env=b),l.push(v.exitCode),v.exitCode!==0&&(a=v.exitCode),p?i=v:(t.pipeStderr?.[d]??!1?n=St(v.stderr)+En(v):(n=En(v),o+=v.stderr),i={stdout:"",stderr:"",exitCode:v.exitCode})}if(o&&(i={...i,stderr:o+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;d{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(o&&l?await ho(e,t,s,n,r,u,c=>{a+=c}):l?await po(e,s,n,r,u):await mo(e,s,n,r,u),t.name){i.set(s,e.state.env.get(s));let f=`(${n.map(d=>Lt(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function fo(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function ho(e,t,s,n,r,i,a){let o=[];for(let l of n){let u=$s(l);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await x(e,{type:"Word",parts:f}):h="",h=G(e,h),o.push({type:"keyed",key:c,value:h,append:d})}else{let c=await x(e,l);o.push({type:"invalid",expandedValue:c})}}r||i();for(let l of o)if(l.type==="keyed")if(l.append){let u=e.state.env.get(`${s}_${l.key}`)??"";e.state.env.set(`${s}_${l.key}`,u+l.value)}else e.state.env.set(`${s}_${l.key}`,l.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array -`)}}async function po(e,t,s,n,r){let i=[];for(let o of s){let l=$s(o);if(l){let{key:u,valueParts:c,append:f}=l,d;c.length>0?d=await x(e,{type:"Word",parts:c}):d="",d=G(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await Ce(e,o);i.push({type:"non-keyed",values:u.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let l;try{let u=new V,c=Q(u,o.indexExpr);l=await j(e,c.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))l=Number.parseInt(o.indexExpr,10);else{let u=e.state.env.get(o.indexExpr);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}}if(o.append){let u=e.state.env.get(`${t}_${l}`)??"";e.state.env.set(`${t}_${l}`,u+o.value)}else e.state.env.set(`${t}_${l}`,o.value);a=l+1}else for(let l of o.values)e.state.env.set(`${t}_${a++}`,l)}async function mo(e,t,s,n,r){let i=[];for(let o of s){let l=await Ce(e,o);i.push(...l.values)}let a=0;if(n){let o=Ee(e,t);if(o.length>0)a=Math.max(...o.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(e.state.env.set(`${t}_0`,l),e.state.env.delete(t),a=1)}}else r();for(let o=0;o0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function $i(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),a=new V().parseWordFromString(r,!0,!1);n=await x(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);n=await x(e,i)}else n=s;return`${t}_${n}`}async function go(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new V,a=Q(i,n);r=await j(e,a.expression,!1)}catch(i){if(i instanceof He){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message} -`;if(i.fatal)throw new B(1,"",l);return{index:0,error:P("",l,1)}}let a=e.state.env.get(s);r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=Ee(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:P("",`bash: line ${o}: ${t}[${s}]: bad array subscript -`,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:P("",`bash: line ${o}: ${t}[${s}]: bad array subscript -`,1)}}}return{index:r}}async function wo(e,t,s,n,r,i){let a="",o=s,l=null;if(ge(e,s)){let f=Un(e,s,n);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference -`,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};o=f;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Ue(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable -`,{continueToNext:!0,xtraceOutput:a};let f=ee(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if($t(e,o))try{let f=new V;if(r){let h=`(${e.state.env.get(o)||"0"}) + (${n})`,y=Q(f,h);u=String(await j(e,y.expression))}else{let d=Q(f,n);u=String(await j(e,d.expression))}}catch{u="0"}else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js"),d=f(e,o)?`${o}_0`:o;u=r?(e.state.env.get(d)||"")+n:n}u=ut(e,o,u),a+=await gi(e,o,u);let c=o;if(l)c=await vo(e,l);else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js");f(e,o)&&(c=`${o}_0`)}return t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(f=>f.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function vo(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return $i(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new V,o=Q(a,n);i=await j(e,o.expression,!1)}catch{let a=e.state.env.get(n);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=Ee(e,s);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Ei(e,t,s,n){let r=await Ne(e,t.redirections);if(r)return r;let i=new Map(e.state.env),a=e.state.cwd,o={...e.state.options},l=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map(S=>new Map(S)),c){e.state.localVarStack=new Map;for(let[S,O]of c.entries())e.state.localVarStack.set(S,O.map(N=>({...N})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,y=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,w=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;s&&(e.state.groupStdin=s);let g="",b="",m=0,v=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.functions=l,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=y,e.state.groupStdin=$,e.state.bashPid=w,e.state.lastArg=p};try{for(let S of t.body){let O=await n(S);g+=O.stdout,b+=O.stderr,m=O.exitCode}}catch(S){if(v(),S instanceof Y)throw S;if(S instanceof Ie){g+=S.stdout,b+=S.stderr;let N=P(g,b,0);return q(e,N,t.redirections)}if(S instanceof fe||S instanceof de){g+=S.stdout,b+=S.stderr;let N=P(g,b,0);return q(e,N,t.redirections)}if(S instanceof B){g+=S.stdout,b+=S.stderr;let N=P(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof le){g+=S.stdout,b+=S.stderr;let N=P(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof pe){let N=P(g+S.stdout,b+S.stderr,S.exitCode);return q(e,N,t.redirections)}let O=P(g,`${b}${De(S)} -`,1);return q(e,O,t.redirections)}v();let E=P(g,b,m);return q(e,E,t.redirections)}async function Si(e,t,s,n){let r="",i="",a=0,o=await ss(e,t.redirections);if(o)return o;let l=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await x(e,d.content);d.stripTabs&&(h=h.split(` -`).map(p=>p.replace(/^\t+/,"")).join(` -`));let y=f.fd??0;y!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),ie(e),e.state.fileDescriptors.set(y,h)):l=h}else if(f.operator==="<<<"&&f.target.type==="Word")l=`${await x(e,f.target)} -`;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await x(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=await x(e,f.target);return P("",`bash: ${d}: No such file or directory -`,1)}let u=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let f of t.body){let d=await n(f);r+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof Y)throw f;if(It(f)||f instanceof pe||f instanceof B)throw f.prependOutput(r,i),f;return P(r,`${i}${De(f)} -`,1)}e.state.groupStdin=u;let c=P(r,i,a);return q(e,c,t.redirections)}async function Ai(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory -`,127)}if(i.startsWith("#!")){let w=i.indexOf(` -`);w!==-1&&(i=i.slice(w+1))}let a=new Map(e.state.env),o=e.state.cwd,l={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,y=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let w=0;w{e.state.env=a,e.state.cwd=o,e.state.options=l,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=y};try{let $=new V().parse(i),g=await r($);return p(),g}catch(w){if(p(),w instanceof B||w instanceof Y)throw w;if(w.name==="ParseException")return _(`bash: ${t}: ${w.message} -`);throw w}}var Ct=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Qe(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let a=this.ctx.state.env.get(i);a!==void 0&&(r[i]=a)}return r}async executeScript(t){this.assertDefenseContext("execution");let s="",n="",r=0,i=this.ctx.limits.maxOutputSize,a=(o,l)=>{s.length+n.length+o.length+l.length>i&&Pe(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=o,n+=l};for(let o of t.statements)try{let l=await this.executeStatement(o);a(gs(l),l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(l){if(l instanceof B)throw l.prependOutput(s,n),l;if(l instanceof me)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Re(this.ctx.state.env)};if(l instanceof Y)throw l;if(l instanceof pe)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Re(this.ctx.state.env)};if(l instanceof Rn)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Re(this.ctx.state.env)};if(l instanceof Dt)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Re(this.ctx.state.env)};if(l instanceof He){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof Ln){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof fe||l instanceof de){if(this.ctx.state.loopDepth>0)throw l.prependOutput(s,n),l;a(l.stdout,l.stderr);continue}throw l instanceof le&&l.prependOutput(s,n),l}return{stdout:s,stderr:n,exitCode:r,env:Re(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Ai(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new xt;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Pe(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Rt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return W;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText} -`);let r=0,i=-1,a=!1;for(let u=0;u0?t.operators[u-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(c);s+=gs(d),n+=d.stderr,r=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let o=ithis.executeCommand(s,n))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return oi(this.ctx,t);case"For":return li(this.ctx,t);case"CStyleFor":return ci(this.ctx,t);case"While":return ui(this.ctx,t,s);case"Until":return fi(this.ctx,t);case"Case":return di(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return kr(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return W}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof Tt)return _(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let m=t,v=100;for(;v>0;){let E=this.expandAlias(m);if(E===m)break;m=E,v--}this.aliasExpansionStack.clear(),m!==t&&(t=m)}this.ctx.state.expansionStderr="";let n=await bi(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let v=await Ne(this.ctx,t.redirections);if(v)return v;let E=P("",i,0);return q(this.ctx,E,t.redirections)}this.ctx.state.lastArg="";let m=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",m,this.ctx.state.lastExitCode)}let a=t.name&&Cn(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(r.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let m of o)this.ctx.state.tempExportedVars.add(m)}let l=await ss(this.ctx,t.redirections);if(l){for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);return l}let u=-1;for(let m of t.redirections){if((m.operator==="<<"||m.operator==="<<-")&&m.target.type==="HereDoc"){let v=m.target,E=await x(this.ctx,v.content);v.stripTabs&&(E=E.split(` -`).map(O=>O.replace(/^\t+/,"")).join(` -`)),E=je(E);let S=m.fd??0;S!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),ie(this.ctx),this.ctx.state.fileDescriptors.set(S,E)):s=E;continue}if(m.operator==="<<<"&&m.target.type==="Word"){s=je(`${await x(this.ctx,m.target)} -`);continue}if(m.operator==="<"&&m.target.type==="Word")try{let v=await x(this.ctx,m.target),E=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);s=await In(this.ctx.fs,E)}catch{let v=await x(this.ctx,m.target);for(let[E,S]of r)S===void 0?this.ctx.state.env.delete(E):this.ctx.state.env.set(E,S);return _(`bash: ${v}: No such file or directory -`)}if(m.operator==="<&"&&m.target.type==="Word"){let v=await x(this.ctx,m.target),E=Number.parseInt(v,10);if(!Number.isNaN(E)&&this.ctx.state.fileDescriptors){let S=this.ctx.state.fileDescriptors.get(E);if(S!==void 0)if(S.startsWith("__rw__:")){let O=hi(S);O&&(s=O.content.slice(O.position),u=E)}else S.startsWith("__file__:")||S.startsWith("__file_append__:")||(s=S)}}}let c=await x(this.ctx,t.name),f=[],d=[];if(Cn(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let m of t.args){let v=await fr(this.ctx,m);if(v)f.push(v),d.push(!0);else{let E=await dr(this.ctx,m);if(E!==null)f.push(E),d.push(!0);else{let S=await Ce(this.ctx,m);for(let O of S.values)f.push(O),d.push(S.quoted)}}}else for(let m of t.args){let v=await Ce(this.ctx,m);for(let E of v.values)f.push(E),d.push(v.quoted)}if(!c){if(t.name.parts.every(v=>v.type==="CommandSubstitution"||v.type==="ParameterExpansion"||v.type==="ArithmeticExpansion")){if(f.length>0){let v=f.shift();return d.shift(),await this.runCommand(v,f,d,s,!1,!1,u)}return P("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found -`,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let m of t.redirections){if(m.target.type==="HereDoc"||m.fdVariable)continue;let v=await x(this.ctx,m.target),E=m.fd??(m.operator==="<"||m.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),m.operator){case">":case">|":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);await this.ctx.fs.writeFile(S,"","utf8"),ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file__:${S}`);break}case">>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file_append__:${S}`);break}case"<":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ie(this.ctx),this.ctx.state.fileDescriptors.set(E,O)}catch{return _(`bash: ${v}: No such file or directory -`)}break}case"<>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:${O}`)}catch{await this.ctx.fs.writeFile(S,"","utf8"),ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:`)}break}case">&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupout__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupout__:${S}`))}break}case"<&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupin__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ie(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupin__:${S}`))}break}}}for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return W}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let m=0;m0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let p,w=null;try{p=await this.runCommand(c,f,d,s,!1,!1,u)}catch(m){if(m instanceof fe||m instanceof de)w=m,p=W;else throw m}let $=i+y;if($&&(p={...p,stderr:$+p.stderr}),p=await q(this.ctx,p,t.redirections),w)throw w;if(f.length>0){let m=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(m)){let v=m.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);v&&(m=v[1])}this.ctx.state.lastArg=m}else this.ctx.state.lastArg=c;let g=Cr(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!g)for(let[m,v]of r)this.ctx.state.fullyUnsetLocals?.has(m)||(v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v));if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(c,f,d,h,y,p,w)=>this.runCommand(c,f,d,h,y,p,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await ii(l,t,s,n,r,i,a,o);return u!==null?u:ai(l,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return xs(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return cs(this.ctx,t)}async executeSubshell(t,s=""){return Ei(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return Si(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Ne(this.ctx,t.redirections);if(s)return s;try{let n=await j(this.ctx,t.expression.expression),r=X(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=_(`bash: arithmetic expression: ${n.message} -`);return q(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Ne(this.ctx,t.redirections);if(s)return s;try{let n=await Me(this.ctx,t.expression),r=X(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=n instanceof He?1:2,i=_(`bash: conditional expression: ${n.message} -`,r);return q(this.ctx,i,t.redirections)}}};var te={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function _i(e){return e?{maxCallDepth:e.maxCallDepth??te.maxCallDepth,maxCommandCount:e.maxCommandCount??te.maxCommandCount,maxLoopIterations:e.maxLoopIterations??te.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??te.maxAwkIterations,maxSedIterations:e.maxSedIterations??te.maxSedIterations,maxJqIterations:e.maxJqIterations??te.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??te.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??te.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??te.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??te.maxGlobOperations,maxStringLength:e.maxStringLength??te.maxStringLength,maxArrayElements:e.maxArrayElements??te.maxArrayElements,maxHeredocSize:e.maxHeredocSize??te.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??te.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??te.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??te.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??te.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??te.maxSourceDepth}:{...te}}import{lookup as No}from"node:dns";function Pn(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function bo(e){let t=Pn(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Ci(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function $o(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function kn(e,t){let s=Pn(e);if(!s)return!1;let n=bo(t);return!n||s.origin!==n.origin||n.pathPrefix!=="/"&&n.pathPrefix!==""&&Ci(s.pathname)?!1:$o(s.pathname,n.pathPrefix)}function Pi(e){return typeof e=="string"?e:e.url}function ki(e,t){return!t||t.length===0?!1:t.some(s=>kn(e,Pi(s)))}function Nn(e){let t=Eo(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Ni(t);if(s)return fs(s);let n=Ao(t);return n?_o(n):!1}function Eo(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function So(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let n=Number.parseInt(s,t);return!Number.isFinite(n)||n<0?null:n}function Ni(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(l=>So(l));if(s.some(l=>l===null))return null;let n=s;if(t.length===1){let l=n[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=n;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=n;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[r,i,a,o]=n;return r>255||i>255||a>255||o>255?null:[r,i,a,o]}function Ao(e){let t=e,s=null;if(t.includes(".")){let p=t.lastIndexOf(":");if(p<0)return null;let w=t.slice(p+1),$=Ni(w);if(!$)return null;s=$,t=t.slice(0,p)}let n=t.includes("::")?t.split("::").length-1:0;if(n>1)return null;let[r,i]=t.split("::"),a=r?r.split(":").filter(Boolean):[],o=i?i.split(":").filter(Boolean):[],l=p=>/^[0-9a-f]{1,4}$/i.test(p)?Number.parseInt(p,16):null,u=a.map(l),c=o.map(l);if(u.some(p=>p===null)||c.some(p=>p===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(n===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let y=[...u,...new Array(h).fill(0),...c];return s&&(y.push(s[0]<<8|s[1]),y.push(s[2]<<8|s[3])),y.length===8?y:null}function fs(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function _o(e){if(e.every(r=>r===0)||e.slice(0,7).every(r=>r===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let r=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return fs(r)}return!1}function Oi(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let n=Pi(s);if(!Pn(n)){t.push(`Invalid URL in allow-list: "${n}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(n);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${n}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${n}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Ci(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${n}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${n}"`)}return t}var Co=typeof __BROWSER__<"u"&&__BROWSER__,ft=null,ds=null,Di=!1;function Po(){if(ft===null&&!Co)try{let e=Dn("node:async_hooks");ds=Dn("node:dns"),ft=new e.AsyncLocalStorage}catch{}}function ko(){if(Di||(Po(),!ft||!ds))return;Di=!0;let e=ft,t=ds.lookup;function s(...n){let r=n[0],i=e.getStore();if(typeof r!="string"||!i||i.hostname.toLowerCase()!==r.toLowerCase())return t.apply(this,n);let a={},o;if(n.length===2)o=n[1];else if(n.length>=3){let f=n[1];typeof f=="number"?a={family:f}:f&&typeof f=="object"&&(a=f),o=n[2]}if(typeof o!="function")return t.apply(this,n);let l=o,u=a.family===4||a.family===6?a.family:0,c=u===0?i.addresses:i.addresses.filter(f=>f.family===u);if(c.length===0){let f=new Error(`ENOTFOUND ${r}`);f.code="ENOTFOUND",f.errno=-3008,f.syscall="getaddrinfo",f.hostname=r,process.nextTick(()=>l(f));return}process.nextTick(()=>{a.all?l(null,c.map(f=>({address:f.address,family:f.family}))):l(null,c[0].address,c[0].family)})}Object.defineProperty(ds,"lookup",{value:s,writable:!0,configurable:!0})}function Ti(e,t){return ko(),ft?ft.run(e,t):t()}var Oe=class extends Error{constructor(t,s){let n=s??"URL not in allow-list";super(`Network access denied: ${n}: ${t}`),this.name="NetworkAccessDeniedError"}},Pt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},kt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},hs=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},dt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function Oo(e){return new Promise((t,s)=>{No(e,{all:!0},(n,r)=>{n?s(n):t(r)})})}var Do=20,To=3e4,xo=10485760,Io=["GET","HEAD"],Ro=new Set(["GET","HEAD","OPTIONS"]),Lo=new Set([301,302,303,307,308]);function On(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Oi(t);if(h.length>0)throw new Error(`Invalid network allow-list: +`,i={...i,stderr:i.stderr+y}}return u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function zl(e,t){let s=new Map,r="";for(let n of t.assignments){let i=n.name;if(n.array){let c=await Xf(e,t,i,n.array,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=n.value?await W(e,n.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript +`,1)};let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=await sd(e,t,o[1],o[2],a,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let u=await rd(e,t,i,a,n.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:s}}async function Xf(e,t,s,r,n,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member +`,1)};if(ee(e,s)){let c=Nt(e,s);if(c===void 0||c==="")throw new j(1,"","");let f=ve(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member +`,1)}}if(Je(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable +`,{continueToNext:!0,xtraceOutput:a};let c=me(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let l=e.state.associativeArrays?.has(s),o=Yf(r),u=()=>{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(l&&o?await Jf(e,t,s,r,n,u,c=>{a+=c}):o?await ed(e,s,r,n,u):await td(e,s,r,n,u),t.name){i.set(s,e.state.env.get(s));let f=`(${r.map(d=>Mt(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function Yf(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],r=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let n=t.parts[2];return n.type!=="Literal"?!1:n.value.startsWith("]=")||n.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):s.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function Jf(e,t,s,r,n,i,a){let l=[];for(let o of r){let u=sr(o);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await W(e,{type:"Word",parts:f}):h="",h=ue(e,h),l.push({type:"keyed",key:c,value:h,append:d})}else{let c=await W(e,o);l.push({type:"invalid",expandedValue:c})}}n||i();for(let o of l)if(o.type==="keyed")if(o.append){let u=e.state.env.get(`${s}_${o.key}`)??"";e.state.env.set(`${s}_${o.key}`,u+o.value)}else e.state.env.set(`${s}_${o.key}`,o.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${o.expandedValue}: must use subscript when assigning associative array +`)}}async function ed(e,t,s,r,n){let i=[];for(let l of s){let o=sr(l);if(o){let{key:u,valueParts:c,append:f}=o,d;c.length>0?d=await W(e,{type:"Word",parts:c}):d="",d=ue(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await et(e,l);i.push({type:"non-keyed",values:u.values})}}r||n();let a=0;for(let l of i)if(l.type==="keyed"){let o;try{let u=new V,c=X(u,l.indexExpr);o=await L(e,c.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))o=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);o=u?Number.parseInt(u,10):0,Number.isNaN(o)&&(o=0)}}if(l.append){let u=e.state.env.get(`${t}_${o}`)??"";e.state.env.set(`${t}_${o}`,u+l.value)}else e.state.env.set(`${t}_${o}`,l.value);a=o+1}else for(let o of l.values)e.state.env.set(`${t}_${a++}`,o)}async function td(e,t,s,r,n){let i=[];for(let l of s){let o=await et(e,l);i.push(...o.values)}let a=0;if(r){let l=F(e,t);if(l.length>0)a=Math.max(...l.map(([u])=>typeof u=="number"?u:0))+1;else{let o=e.state.env.get(t);o!==void 0&&(e.state.env.set(`${t}_0`,o),e.state.env.delete(t),a=1)}}else n();for(let l=0;l0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function Bl(e,t,s){let r;if(s.startsWith("'")&&s.endsWith("'"))r=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let n=s.slice(1,-1),a=new V().parseWordFromString(n,!0,!1);r=await W(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);r=await W(e,i)}else r=s;return`${t}_${r}`}async function nd(e,t,s){let r=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(r=s.slice(1,-1));let n;if(/^-?\d+$/.test(r))n=Number.parseInt(r,10);else{try{let i=new V,a=X(i,r);n=await L(e,a.expression,!1)}catch(i){if(i instanceof te){let o=`bash: line ${e.state.currentLine}: ${s}: ${i.message} +`;if(i.fatal)throw new j(1,"",o);return{index:0,error:P("",o,1)}}let a=e.state.env.get(s);n=a?Number.parseInt(a,10):0}Number.isNaN(n)&&(n=0)}if(n<0){let i=F(e,t);if(i.length===0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript +`,1)}}if(n=Math.max(...i.map(([l])=>typeof l=="number"?l:0))+1+n,n<0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript +`,1)}}}return{index:n}}async function rd(e,t,s,r,n,i){let a="",l=s,o=null;if(ee(e,s)){let f=Aa(e,s,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference +`,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};l=f;let d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(o={arrayName:d[1],subscriptExpr:d[2]},l=d[1])}if(Je(e,l)){if(t.name)return a+=`bash: ${l}: readonly variable +`,{continueToNext:!0,xtraceOutput:a};let f=me(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ls(e,l))try{let f=new V;if(n){let h=`(${e.state.env.get(l)||"0"}) + (${r})`,p=X(f,h);u=String(await L(e,p.expression))}else{let d=X(f,r);u=String(await L(e,d.expression))}}catch{u="0"}else{let f=Ue(e,l)?`${l}_0`:l;u=n?(e.state.env.get(f)||"")+r:r}u=Zt(e,l,u),a+=await Ml(e,l,u);let c=l;return o?c=await id(e,o):Ue(e,l)&&(c=`${l}_0`),t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(l)),e.state.tempEnvBindings?.some(f=>f.has(l))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(l))),{continueToNext:!1,xtraceOutput:a}}async function id(e,t){let{arrayName:s,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(s))return Bl(e,s,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new V,l=X(a,r);i=await L(e,l.expression,!1)}catch{let a=e.state.env.get(r);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=F(e,s);a.length>0&&(i=Math.max(...a.map(o=>o[0]))+1+i)}return`${s}_${i}`}async function ql(e,t,s,r){let n=await nt(e,t.redirections);if(n)return n;let i=new Map(e.state.env),a=e.state.cwd,l={...e.state.options},o=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map($=>new Map($)),c){e.state.localVarStack=new Map;for(let[$,x]of c.entries())e.state.localVarStack.set($,x.map(I=>({...I})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,p=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let m=e.state.lastArg,y=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let b=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",E="",w=0,S=()=>{e.state.env=i,e.state.cwd=a,e.state.options=l,e.state.functions=o,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=p,e.state.groupStdin=b,e.state.bashPid=y,e.state.lastArg=m};try{for(let $ of t.body){let x=await r($);v+=x.stdout,E+=x.stderr,w=x.exitCode}}catch($){if(S(),$ instanceof Q)throw $;if($ instanceof ut){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof De||$ instanceof Ie){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof j){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof $e){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof We){let I=P(v+$.stdout,E+$.stderr,$.exitCode);return le(e,I,t.redirections)}let x=P(v,`${E}${it($)} +`,1);return le(e,x,t.redirections)}S();let A=P(v,E,w);return le(e,A,t.redirections)}async function jl(e,t,s,r){let n="",i="",a=0,l=await rn(e,t.redirections);if(l)return l;let o=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await W(e,d.content);d.stripTabs&&(h=h.split(` +`).map(m=>m.replace(/^\t+/,"")).join(` +`));let p=f.fd??0;p!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),be(e),e.state.fileDescriptors.set(p,h)):o=h}else if(f.operator==="<<<"&&f.target.type==="Word")o=`${await W(e,f.target)} +`;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await W(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);o=await e.fs.readFile(h)}catch{let d=await W(e,f.target);return P("",`bash: ${d}: No such file or directory +`,1)}let u=e.state.groupStdin;o&&(e.state.groupStdin=o);try{for(let f of t.body){let d=await r(f);n+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof Q)throw f;if(bs(f)||f instanceof We||f instanceof j)throw f.prependOutput(n,i),f;return P(n,`${i}${it(f)} +`,1)}e.state.groupStdin=u;let c=P(n,i,a);return le(e,c,t.redirections)}async function Ul(e,t,s,r,n){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory +`,127)}if(i.startsWith("#!")){let y=i.indexOf(` +`);y!==-1&&(i=i.slice(y+1))}let a=new Map(e.state.env),l=e.state.cwd,o={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,p=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let y=0;y{e.state.env=a,e.state.cwd=l,e.state.options=o,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=p};try{let b=new V().parse(i),v=await n(b);return m(),v}catch(y){if(m(),y instanceof j||y instanceof Q)throw y;if(y.name==="ParseException")return _(`bash: ${t}: ${y.message} +`);throw y}}var hs=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new It(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let a=this.ctx.state.env.get(i);a!==void 0&&(n[i]=a)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,a=(l,o)=>{s.length+r.length+l.length+o.length>i&&tt(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=l,r+=o};for(let l of t.statements)try{let o=await this.executeStatement(l);a(bn(o),o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(o){if(o instanceof j)throw o.prependOutput(s,r),o;if(o instanceof Me)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:ft(this.ctx.state.env)};if(o instanceof Q)throw o;if(o instanceof We)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:ft(this.ctx.state.env)};if(o instanceof Ce)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:ft(this.ctx.state.env)};if(o instanceof xe)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:ft(this.ctx.state.env)};if(o instanceof te){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof ws){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof De||o instanceof Ie){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,r),o;a(o.stdout,o.stderr);continue}throw o instanceof $e&&o.prependOutput(s,r),o}return{stdout:s,stderr:r,exitCode:n,env:ft(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return Ul(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Es;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&tt(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new ye(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return G;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText} +`);let n=0,i=-1,a=!1;for(let u=0;u0?t.operators[u-1]:null;if(f==="&&"&&n!==0||f==="||"&&n===0)continue;let d=await this.executePipeline(c);s+=bn(d),r+=d.stderr,n=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}let l=ithis.executeCommand(s,r))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Pl(this.ctx,t);case"For":return Dl(this.ctx,t);case"CStyleFor":return Il(this.ctx,t);case"While":return Cl(this.ctx,t,s);case"Until":return xl(this.ctx,t);case"Case":return Rl(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Qo(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return G}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(r){if(r instanceof ct)return _(r.stderr);throw r}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let w=t,S=100;for(;S>0;){let A=this.expandAlias(w);if(A===w)break;w=A,S--}this.aliasExpansionStack.clear(),w!==t&&(t=w)}this.ctx.state.expansionStderr="";let r=await zl(this.ctx,t);if(r.error)return r.error;let n=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let S=await nt(this.ctx,t.redirections);if(S)return S;let A=P("",i,0);return le(this.ctx,A,t.redirections)}this.ctx.state.lastArg="";let w=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",w,this.ctx.state.lastExitCode)}let a=t.name&&ii(t.name,["local","declare","typeset","export","readonly"]),l=Array.from(n.keys());if(l.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let w of l)this.ctx.state.tempExportedVars.add(w)}let o=await rn(this.ctx,t.redirections);if(o){for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);return o}let u=-1;for(let w of t.redirections){if((w.operator==="<<"||w.operator==="<<-")&&w.target.type==="HereDoc"){let S=w.target,A=await W(this.ctx,S.content);S.stripTabs&&(A=A.split(` +`).map(x=>x.replace(/^\t+/,"")).join(` +`)),A=St(A);let $=w.fd??0;$!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),be(this.ctx),this.ctx.state.fileDescriptors.set($,A)):s=A;continue}if(w.operator==="<<<"&&w.target.type==="Word"){s=St(`${await W(this.ctx,w.target)} +`);continue}if(w.operator==="<"&&w.target.type==="Word")try{let S=await W(this.ctx,w.target),A=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);s=await hi(this.ctx.fs,A)}catch{let S=await W(this.ctx,w.target);for(let[A,$]of n)$===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,$);return _(`bash: ${S}: No such file or directory +`)}if(w.operator==="<&"&&w.target.type==="Word"){let S=await W(this.ctx,w.target),A=Number.parseInt(S,10);if(!Number.isNaN(A)&&this.ctx.state.fileDescriptors){let $=this.ctx.state.fileDescriptors.get(A);if($!==void 0)if($.startsWith("__rw__:")){let x=Ol($);x&&(s=x.content.slice(x.position),u=A)}else $.startsWith("__file__:")||$.startsWith("__file_append__:")||(s=$)}}}let c=await W(this.ctx,t.name),f=[],d=[];if(ii(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let w of t.args){let S=await xo(this.ctx,w);if(S)f.push(S),d.push(!0);else{let A=await Ro(this.ctx,w);if(A!==null)f.push(A),d.push(!0);else{let $=await et(this.ctx,w);for(let x of $.values)f.push(x),d.push($.quoted)}}}else for(let w of t.args){let S=await et(this.ctx,w);for(let A of S.values)f.push(A),d.push(S.quoted)}if(!c){if(t.name.parts.every(S=>S.type==="CommandSubstitution"||S.type==="ParameterExpansion"||S.type==="ArithmeticExpansion")){if(f.length>0){let S=f.shift();return d.shift(),await this.runCommand(S,f,d,s,!1,!1,u)}return P("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found +`,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let w of t.redirections){if(w.target.type==="HereDoc"||w.fdVariable)continue;let S=await W(this.ctx,w.target),A=w.fd??(w.operator==="<"||w.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),w.operator){case">":case">|":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);await this.ctx.fs.writeFile($,"","utf8"),be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file__:${$}`);break}case">>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file_append__:${$}`);break}case"<":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let x=await this.ctx.fs.readFile($);be(this.ctx),this.ctx.state.fileDescriptors.set(A,x)}catch{return _(`bash: ${S}: No such file or directory +`)}break}case"<>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let x=await this.ctx.fs.readFile($);be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:${x}`)}catch{await this.ctx.fs.writeFile($,"","utf8"),be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:`)}break}case">&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),x=Number.parseInt($,10);if(!Number.isNaN(x)){let I=this.ctx.state.fileDescriptors.get(x);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupout__:${x}`),this.ctx.state.fileDescriptors.delete(x)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupout__:${$}`))}break}case"<&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),x=Number.parseInt($,10);if(!Number.isNaN(x)){let I=this.ctx.state.fileDescriptors.get(x);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupin__:${x}`),this.ctx.state.fileDescriptors.delete(x)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(be(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupin__:${$}`))}break}}}for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return G}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let w=0;w0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(n)));let m,y=null;try{m=await this.runCommand(c,f,d,s,!1,!1,u)}catch(w){if(w instanceof De||w instanceof Ie)y=w,m=G;else throw w}let b=i+p;if(b&&(m={...m,stderr:b+m.stderr}),m=await le(this.ctx,m,t.redirections),y)throw y;if(f.length>0){let w=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(w)){let S=w.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);S&&(w=S[1])}this.ctx.state.lastArg=w}else this.ctx.state.lastArg=c;let v=Ho(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!v)for(let[w,S]of n)this.ctx.state.fullyUnsetLocals?.has(w)||(S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S));if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return n.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(m={...m,stderr:this.ctx.state.expansionStderr+m.stderr},this.ctx.state.expansionStderr=""),m}async runCommand(t,s,r,n,i=!1,a=!1,l=-1){let o={ctx:this.ctx,runCommand:(c,f,d,h,p,m,y)=>this.runCommand(c,f,d,h,p,m,y),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await kl(o,t,s,r,n,i,a,l);return u!==null?u:_l(o,t,s,n,a)}aliasExpansionStack=new Set;expandAlias(t){return Xn(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return dn(this.ctx,t)}async executeSubshell(t,s=""){return ql(this.ctx,t,s,r=>this.executeStatement(r))}async executeGroup(t,s=""){return jl(this.ctx,t,s,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await nt(this.ctx,t.redirections);if(s)return s;try{let r=await L(this.ctx,t.expression.expression),n=de(r!==0);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=_(`bash: arithmetic expression: ${r.message} +`);return le(this.ctx,n,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await nt(this.ctx,t.redirections);if(s)return s;try{let r=await Et(this.ctx,t.expression),n=de(r);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=r instanceof te?1:2,i=_(`bash: conditional expression: ${r.message} +`,n);return le(this.ctx,i,t.redirections)}}};var ge={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function Zl(e){return e?{maxCallDepth:e.maxCallDepth??ge.maxCallDepth,maxCommandCount:e.maxCommandCount??ge.maxCommandCount,maxLoopIterations:e.maxLoopIterations??ge.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??ge.maxAwkIterations,maxSedIterations:e.maxSedIterations??ge.maxSedIterations,maxJqIterations:e.maxJqIterations??ge.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??ge.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??ge.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??ge.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??ge.maxGlobOperations,maxStringLength:e.maxStringLength??ge.maxStringLength,maxArrayElements:e.maxArrayElements??ge.maxArrayElements,maxHeredocSize:e.maxHeredocSize??ge.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??ge.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??ge.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??ge.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??ge.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??ge.maxSourceDepth}:{...ge}}import{lookup as md}from"node:dns";function ai(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function ad(e){let t=ai(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Hl(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function od(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function oi(e,t){let s=ai(e);if(!s)return!1;let r=ad(t);return!r||s.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Hl(s.pathname)?!1:od(s.pathname,r.pathPrefix)}function Gl(e){return typeof e=="string"?e:e.url}function Ql(e,t){return!t||t.length===0?!1:t.some(s=>oi(e,Gl(s)))}function li(e){let t=ld(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Kl(t);if(s)return pn(s);let r=ud(t);return r?fd(r):!1}function ld(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function cd(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let r=Number.parseInt(s,t);return!Number.isFinite(r)||r<0?null:r}function Kl(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(o=>cd(o));if(s.some(o=>o===null))return null;let r=s;if(t.length===1){let o=r[0];return o>4294967295?null:[o>>>24&255,o>>>16&255,o>>>8&255,o&255]}if(t.length===2){let[o,u]=r;return o>255||u>16777215?null:[o,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[o,u,c]=r;return o>255||u>255||c>65535?null:[o,u,c>>>8&255,c&255]}let[n,i,a,l]=r;return n>255||i>255||a>255||l>255?null:[n,i,a,l]}function ud(e){let t=e,s=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Kl(y);if(!b)return null;s=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[n,i]=t.split("::"),a=n?n.split(":").filter(Boolean):[],l=i?i.split(":").filter(Boolean):[],o=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=a.map(o),c=l.map(o);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...u,...new Array(h).fill(0),...c];return s&&(p.push(s[0]<<8|s[1]),p.push(s[2]<<8|s[3])),p.length===8?p:null}function pn(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function fd(e){if(e.every(n=>n===0)||e.slice(0,7).every(n=>n===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let n=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return pn(n)}return!1}function Xl(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Gl(s);if(!ai(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Hl(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var dd=typeof __BROWSER__<"u"&&__BROWSER__,Ht=null,mn=null,Yl=!1;function hd(){if(Ht===null&&!dd)try{let e=ui("node:async_hooks");mn=ui("node:dns"),Ht=new e.AsyncLocalStorage}catch{}}function pd(){if(Yl||(hd(),!Ht||!mn))return;Yl=!0;let e=Ht,t=mn.lookup;function s(...r){let n=r[0],i=e.getStore();if(typeof n!="string"||!i||i.hostname.toLowerCase()!==n.toLowerCase())return t.apply(this,r);let a={},l;if(r.length===2)l=r[1];else if(r.length>=3){let f=r[1];typeof f=="number"?a={family:f}:f&&typeof f=="object"&&(a=f),l=r[2]}if(typeof l!="function")return t.apply(this,r);let o=l,u=a.family===4||a.family===6?a.family:0,c=u===0?i.addresses:i.addresses.filter(f=>f.family===u);if(c.length===0){let f=new Error(`ENOTFOUND ${n}`);f.code="ENOTFOUND",f.errno=-3008,f.syscall="getaddrinfo",f.hostname=n,process.nextTick(()=>o(f));return}process.nextTick(()=>{a.all?o(null,c.map(f=>({address:f.address,family:f.family}))):o(null,c[0].address,c[0].family)})}Object.defineProperty(mn,"lookup",{value:s,writable:!0,configurable:!0})}function Jl(e,t){return pd(),Ht?Ht.run(e,t):t()}var rt=class extends Error{constructor(t,s){let r=s??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},ps=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ms=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},gn=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},Gt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function gd(e){return new Promise((t,s)=>{md(e,{all:!0},(r,n)=>{r?s(r):t(n)})})}var yd=20,wd=3e4,Ed=10485760,bd=["GET","HEAD"],vd=new Set(["GET","HEAD","OPTIONS"]),Sd=new Set([301,302,303,307,308]);function ci(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Xl(t);if(h.length>0)throw new Error(`Invalid network allow-list: ${h.join(` -`)}`)}let s=[];for(let h of t)typeof h=="object"&&h.transform&&h.transform.length>0&&s.push(h);function n(h){if(s.length===0)return null;let y=null;for(let p of s)if(kn(h,p.url)&&p.transform){y||(y=new Headers);for(let w of p.transform)for(let[$,g]of Object.entries(w.headers))y.set($,g)}return y}let r=e.maxRedirects??Do,i=e.timeoutMs??To,a=e.maxResponseSize??xo,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Io,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??Oo;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!ki(h,t))throw new Oe(h);if(l)try{let y=new URL(h);if(Nn(y.hostname))throw new Oe(h,"private/loopback IP address blocked");let p=y.hostname;if(/[a-zA-Z]/.test(p))try{let $=await u(p);for(let{address:b}of $)if(Nn(b))throw new Oe(h,"hostname resolves to private/loopback IP address");let g=[];for(let b of $)g.push({address:b.address,family:b.family===6?6:4});if(g.length>0)return{hostname:p,addresses:g}}catch($){if($ instanceof Oe)throw $;let g=$?.code;if(!(g==="ENOTFOUND"||g==="ENODATA"))throw new Oe(h,"DNS resolution failed for private IP check")}}catch(y){if(y instanceof Oe)throw y}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let y=h.toUpperCase();if(!o.includes(y))throw new hs(y,o)}async function d(h,y={}){let p=y.method?.toUpperCase()??"GET",w=await c(h);f(p);let $=h,g=0,b=y.followRedirects??!0,m=y.timeoutMs!==void 0?Math.min(y.timeoutMs,i):i;for(;;){let v=new AbortController,E=Tn(()=>v.abort(),m);try{let S=await be.runTrustedAsync(()=>{let O=n($),N=Fo(y.headers,O),I={method:p,headers:N,signal:v.signal,redirect:"manual"};return y.body&&!Ro.has(p)&&(I.body=y.body),w?Ti(w,()=>fetch($,I)):fetch($,I)});if(Lo.has(S.status)&&b){let O=S.headers.get("location");if(!O)return await xi(S,$,a);let N=new URL(O,$).href;try{w=await c(N)}catch{throw new kt(N)}if(g++,g>r)throw new Pt(r);$=N;continue}return await xi(S,$,a)}finally{xn(E)}}}return d}function Fo(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[n,r]of t)s.set(n,r);return s}async function xi(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,a)=>{n[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new dt(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),a=[],o=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(o+=c.byteLength,o>s)throw i.cancel(),new dt(s);a.push(c)}}r=new Uint8Array(o);let l=0;for(let u of a)r.set(u,l),l+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new dt(s);r=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Ii(e){return Xe(e)}function Xe(e){return e.statements.map(Ri).join(` -`)}function Ri(e){let t=[];for(let n=0;n0?`${t.join(" ")} `:"")+s.join(" ")}function Li(e){switch(e.type){case"SimpleCommand":return Mo(e);case"If":return Go(e);case"For":return Ko(e);case"CStyleFor":return Xo(e);case"While":return Yo(e);case"Until":return Qo(e);case"Case":return Jo(e);case"Subshell":return tl(e);case"Group":return sl(e);case"ArithmeticCommand":return nl(e);case"ConditionalCommand":return rl(e);case"FunctionDef":return il(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Mo(e){let t=[];for(let s of e.assignments)t.push(zo(s));e.name&&t.push(ae(e.name));for(let s of e.args)t.push(ae(s));for(let s of e.redirections)t.push(Mi(s));return t.join(" ")}function zo(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(ae).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${ae(e.value)}`:`${e.name}${t}`}function ae(e){return e.parts.map(t=>ps(t,!1)).join("")}function Be(e){return e.parts.map(t=>ps(t,!0)).join("")}function ps(e,t){switch(e.type){case"Literal":return t?Bo(e.value):Vo(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>ps(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Fi(e);case"CommandSubstitution":return e.legacy?`\`${Xe(e.body)}\``:`$(${Xe(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Xe(e.body)})`:`>(${Xe(e.body)})`;case"BraceExpansion":return Zo(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function Vo(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Bo(e){return e.replace(/[$`"\\]/g,"\\$&")}function jo(e,t){return e.parts.map(s=>Ho(s,t)).join("")}function Ho(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Fi(e);case"CommandSubstitution":return e.legacy?`\`${Xe(e.body)}\``:`$(${Xe(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;default:return ps(e,!1)}}function Fi(e){return e.operation?`\${${Wi(e.parameter,e.operation)}}`:Uo(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Uo(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Wi(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Be(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Be(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Be(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Be(t.word)}`;case"Substring":{let s=H(t.offset.expression);return t.length?`${e}:${s}:${H(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",n=t.greedy?`${s}${s}`:s;return`${e}${n}${Be(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let n=t.replacement?`/${Be(t.replacement)}`:"";return`${e}${s}${Be(t.pattern)}${n}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",n=t.all?`${s}${s}`:s,r=t.pattern?Be(t.pattern):"";return`${e}${n}${r}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Wi(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Zo(e){return`{${e.items.map(qo).join(",")}}`}function qo(e){if(e.type==="Word")return ae(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function Mi(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,n=s.quoted?`'${s.delimiter}'`:s.delimiter,r=jo(s.content,s.quoted);return`${t}${e.operator}${n} -${r}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${ae(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${ae(e.target)}`:`${t}${e.operator} ${ae(e.target)}`}function Ae(e){return e.length===0?"":` ${e.map(Mi).join(" ")}`}function we(e){return e.map(Ri).join(` -`)}function Go(e){let t=[];for(let s=0;s0&&s.push(h);function r(h){if(s.length===0)return null;let p=null;for(let m of s)if(oi(h,m.url)&&m.transform){p||(p=new Headers);for(let y of m.transform)for(let[b,v]of Object.entries(y.headers))p.set(b,v)}return p}let n=e.maxRedirects??yd,i=e.timeoutMs??wd,a=e.maxResponseSize??Ed,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??bd,o=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??gd;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!Ql(h,t))throw new rt(h);if(o)try{let p=new URL(h);if(li(p.hostname))throw new rt(h,"private/loopback IP address blocked");let m=p.hostname;if(/[a-zA-Z]/.test(m))try{let b=await u(m);for(let{address:E}of b)if(li(E))throw new rt(h,"hostname resolves to private/loopback IP address");let v=[];for(let E of b)v.push({address:E.address,family:E.family===6?6:4});if(v.length>0)return{hostname:m,addresses:v}}catch(b){if(b instanceof rt)throw b;let v=b?.code;if(!(v==="ENOTFOUND"||v==="ENODATA"))throw new rt(h,"DNS resolution failed for private IP check")}}catch(p){if(p instanceof rt)throw p}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let p=h.toUpperCase();if(!l.includes(p))throw new gn(p,l)}async function d(h,p={}){let m=p.method?.toUpperCase()??"GET",y=await c(h);f(m);let b=h,v=0,E=p.followRedirects??!0,w=p.timeoutMs!==void 0?Math.min(p.timeoutMs,i):i;for(;;){let S=new AbortController,A=fi(()=>S.abort(),w);try{let $=await Be.runTrustedAsync(()=>{let x=r(b),I=Ad(p.headers,x),T={method:m,headers:I,signal:S.signal,redirect:"manual"};return p.body&&!vd.has(m)&&(T.body=p.body),y?Jl(y,()=>fetch(b,T)):fetch(b,T)});if(Sd.has($.status)&&E){let x=$.headers.get("location");if(!x)return await ec($,b,a);let I=new URL(x,b).href;try{y=await c(I)}catch{throw new ms(I)}if(v++,v>n)throw new ps(n);b=I;continue}return await ec($,b,a)}finally{di(A)}}}return d}function Ad(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,n]of t)s.set(r,n);return s}async function ec(e,t,s){let r=Object.create(null);if(e.headers.forEach((i,a)=>{r[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new Gt(s)}}let n;if(s>0&&e.body){let i=e.body.getReader(),a=[],l=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(l+=c.byteLength,l>s)throw i.cancel(),new Gt(s);a.push(c)}}n=new Uint8Array(l);let o=0;for(let u of a)n.set(u,o),o+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new Gt(s);n=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:r,body:n,url:t}}function tc(e){return Pt(e)}function Pt(e){return e.statements.map(sc).join(` +`)}function sc(e){let t=[];for(let r=0;r0?`${t.join(" ")} `:"")+s.join(" ")}function nc(e){switch(e.type){case"SimpleCommand":return Nd(e);case"If":return Od(e);case"For":return Ld(e);case"CStyleFor":return Td(e);case"While":return Wd(e);case"Until":return Md(e);case"Case":return Fd(e);case"Subshell":return zd(e);case"Group":return Bd(e);case"ArithmeticCommand":return qd(e);case"ConditionalCommand":return jd(e);case"FunctionDef":return Ud(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Nd(e){let t=[];for(let s of e.assignments)t.push(kd(s));e.name&&t.push(Se(e.name));for(let s of e.args)t.push(Se(s));for(let s of e.redirections)t.push(ac(s));return t.join(" ")}function kd(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(Se).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${Se(e.value)}`:`${e.name}${t}`}function Se(e){return e.parts.map(t=>yn(t,!1)).join("")}function vt(e){return e.parts.map(t=>yn(t,!0)).join("")}function yn(e,t){switch(e.type){case"Literal":return t?Pd(e.value):_d(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>yn(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return rc(e);case"CommandSubstitution":return e.legacy?`\`${Pt(e.body)}\``:`$(${Pt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Pt(e.body)})`:`>(${Pt(e.body)})`;case"BraceExpansion":return xd(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function _d(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Pd(e){return e.replace(/[$`"\\]/g,"\\$&")}function Dd(e,t){return e.parts.map(s=>Id(s,t)).join("")}function Id(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return rc(e);case"CommandSubstitution":return e.legacy?`\`${Pt(e.body)}\``:`$(${Pt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;default:return yn(e,!1)}}function rc(e){return e.operation?`\${${ic(e.parameter,e.operation)}}`:Cd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Cd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function ic(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${vt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${vt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?vt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${vt(t.word)}`;case"Substring":{let s=ne(t.offset.expression);return t.length?`${e}:${s}:${ne(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",r=t.greedy?`${s}${s}`:s;return`${e}${r}${vt(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let r=t.replacement?`/${vt(t.replacement)}`:"";return`${e}${s}${vt(t.pattern)}${r}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",r=t.all?`${s}${s}`:s,n=t.pattern?vt(t.pattern):"";return`${e}${r}${n}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${ic(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function xd(e){return`{${e.items.map(Rd).join(",")}}`}function Rd(e){if(e.type==="Word")return Se(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function ac(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,r=s.quoted?`'${s.delimiter}'`:s.delimiter,n=Dd(s.content,s.quoted);return`${t}${e.operator}${r} +${n}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Se(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Se(e.target)}`:`${t}${e.operator} ${Se(e.target)}`}function Ge(e){return e.length===0?"":` ${e.map(ac).join(" ")}`}function Ve(e){return e.map(sc).join(` +`)}function Od(e){let t=[];for(let s=0;sthis.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option. -`,exitCode:1,env:ye(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:ye(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);r!==void 0&&a.set("PWD",r);let o={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:ol(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},l=t;s?.rawScript||(l=zi(t));let u=this.defenseInDepthConfig?be.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=$e(l,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let g=Object.create(null);for(let b of this.transformPlugins){let m=b.transform({ast:d,metadata:g});d=m.ast,m.metadata&&(g=ws(g,m.metadata))}h=g}let y={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},$=await new Ct(y,o).executeScript(d);return h&&($.metadata=h),this.logResult($)};return c?await c.run(f):await f()}catch(f){if(f instanceof B)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof He)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:ye(this.state.env,s?.env)});if(f instanceof xt)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:ye(this.state.env,s?.env)});if(f instanceof Y)return this.logResult({stdout:f.stdout,stderr:he(f.stderr),exitCode:Y.EXIT_CODE,env:ye(this.state.env,s?.env)});if(f instanceof Qe)return this.logResult({stdout:"",stderr:`bash: security violation: ${he(f.message)} -`,exitCode:1,env:ye(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${he(f.message)} -`,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof Mn)return this.logResult({stdout:"",stderr:`bash: ${he(f.message)} -`,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${he(f.message)} -`,exitCode:1,env:ye(this.state.env,s?.env)});throw f}finally{c?.deactivate()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return Re(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=zi(t),n=$e(s,{maxHeredocSize:this.limits.maxHeredocSize}),r=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:n,metadata:r});n=a.ast,a.metadata&&(r=ws(r,a.metadata))}return{script:Ii(n),ast:n,metadata:r}}};function zi(e){let t=e.split(` -`),s=[],n=[];for(let r=0;r0){let l=n[n.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of a.matchAll(o)){let u=l[1]==="-",c=l[3];n.push({delimiter:c,stripTabs:u})}}return s.join(` -`)}var al=new TextDecoder("utf-8",{fatal:!0});function Vi(e){if(!e)return e;let t=!1;for(let n=0;n255)return e;r>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let n=0;n0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?U.constants.O_RDONLY:U.constants.O_RDONLY|U.constants.O_NOFOLLOW,l=await U.promises.open(i,o);try{let u=await l.readFile();return new Uint8Array(u)}finally{await l.close()}}catch(a){let o=a.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,n){M(t,"write"),this.assertWritable(`write '${t}'`);let r=L(t);this.ensureParentDirs(r);let i=Le(n),a=Je(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){M(t,"append"),this.assertWritable(`append '${t}'`);let r=L(t),i=Le(n),a=Je(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let l=new Uint8Array(o.length+a.length);l.set(o),l.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){M(t,"stat");let n=L(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.resolveRealPath_(this.toRealPath(n));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await U.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await U.promises.readlink(i),l=this.realTargetToVirtual(n,o),u=this.resolveSymlink(n,l);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){M(t,"lstat");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await U.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return st(t,s)}realTargetToVirtual(t,s){let n=Hi(s,this.canonicalRoot);if(n.withinRoot){if(!re.isAbsolute(s))return s;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,s){M(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let n=L(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=Ze(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&r.add(u)}for(let[o,l]of this.memory)if(o!==s&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!r.has(c)&&!u.includes("/",1)&&n.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await U.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return n}let o=await U.promises.readdir(a,{withFileTypes:!0});for(let l of o)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else o.code!=="ENOTDIR"&&this.sanitizeError(o,t,"scandir")}return n}async resolveForReaddir(t,s=!1){let n=L(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(n));if(!l)return{normalized:n,outsideOverlay:!0};try{if((await U.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:n,outsideOverlay:!0};let c=await U.promises.readlink(l),f=this.realTargetToVirtual(n,c),d=this.resolveSymlink(n,f);return this.resolveForReaddir(d,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){M(t,"scandir");let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,a)=>ia?1:0)}async readdirWithFileTypes(t){M(t,"scandir");let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,a)=>i.namea.name?1:0)}async rm(t,s){M(t,"rm"),this.assertWritable(`rm '${t}'`);let n=L(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(l,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(n),this.existsOnRealFs(n)&&this.deleted.add(n)}existsOnRealFs(t){let s=this.toRealPath(t),n=this.resolveRealPathParent_(s);if(!n)return!1;try{return U.lstatSync(n),!0}catch{return!1}}async cp(t,s,n){M(t,"cp"),M(s,"cp"),this.assertWritable(`cp '${s}'`);let r=L(t),i=L(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let u of l){let c=r==="/"?`/${u}`:`${r}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return zt(t,s)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.resolveRealPath_(this.toRealPath(t));if(n)try{let r=U.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=re.join(n,i);U.lstatSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){M(t,"chmod"),this.assertWritable(`chmod '${t}'`);let n=L(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);M(s,"symlink"),this.assertWritable(`symlink '${s}'`);let n=L(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){M(t,"link"),M(s,"link"),this.assertWritable(`link '${s}'`);let n=L(t),r=L(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){M(t,"readlink");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await U.promises.readlink(r);if(!re.isAbsolute(i)){let a=re.resolve(re.dirname(r),i),o;try{o=U.realpathSync(a)}catch{o=a}if(!Ot(o,this.canonicalRoot))return re.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){M(t,"realpath");let s=L(t),n=new Set,r=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let y=this.toRealPath(u),p=this.resolveRealPath_(y);if(p)try{if((await U.promises.lstat(p)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let $=await U.promises.readlink(p),g=this.realTargetToVirtual(u,$);return n.add(u),u=this.resolveSymlink(u,g),r(u)}}catch(w){if(w.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(w,t,"realpath")}else if(!this.allowSymlinks){let w=this.resolveRealPathParent_(y);if(w)try{if((await U.promises.lstat(w)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch($){if($.message?.includes("ENOENT")||$.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError($,t,"realpath")}}}}return u||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){M(t,"utimes"),this.assertWritable(`utimes '${t}'`);let r=L(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};function qi(){console.log(`just-bash - A secure bash environment for AI agents +`;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=lc(t.stdout),t.stderr=lc(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option. +`,exitCode:1,env:Fe(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Fe(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);n!==void 0&&a.set("PWD",n);let l={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:Gd(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},o=t;s?.rawScript||(o=oc(t));let u=this.defenseInDepthConfig?Be.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=qe(o,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let v=Object.create(null);for(let E of this.transformPlugins){let w=E.transform({ast:d,metadata:v});d=w.ast,w.metadata&&(v=vn(v,w.metadata))}h=v}let p={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},b=await new hs(p,l).executeScript(d);return h&&(b.metadata=h),this.logResult(b)};return c?await c.run(f):await f()}catch(f){if(f instanceof j)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof Me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof te)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:Fe(this.state.env,s?.env)});if(f instanceof Es)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Fe(this.state.env,s?.env)});if(f instanceof Q)return this.logResult({stdout:f.stdout,stderr:Re(f.stderr),exitCode:Q.EXIT_CODE,env:Fe(this.state.env,s?.env)});if(f instanceof It)return this.logResult({stdout:"",stderr:`bash: security violation: ${Re(f.message)} +`,exitCode:1,env:Fe(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${Re(f.message)} +`,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof ht)return this.logResult({stdout:"",stderr:`bash: ${Re(f.message)} +`,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${Re(f.message)} +`,exitCode:1,env:Fe(this.state.env,s?.env)});throw f}finally{c?.deactivate()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return ft(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=oc(t),r=qe(s,{maxHeredocSize:this.limits.maxHeredocSize}),n=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:r,metadata:n});r=a.ast,a.metadata&&(n=vn(n,a.metadata))}return{script:tc(r),ast:r,metadata:n}}};function Zd(e,t){let s=t;for(let r=0;r0){let c=r[r.length-1];if((c.stripTabs?a.replace(/^\t+/,""):a)===c.delimiter){s.push(a.trimStart()),r.pop();continue}s.push(a);continue}let l=n,o=l==="none"?a.trimStart():a;if(s.push(o),n=Zd(a,l),l!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return s.join(` +`)}var Hd=new TextDecoder("utf-8",{fatal:!0});function lc(e){if(!e)return e;let t=!1;for(let r=0;r255)return e;n>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let r=0;r0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let l=this.allowSymlinks?re.constants.O_RDONLY:re.constants.O_RDONLY|re.constants.O_NOFOLLOW,o=await re.promises.open(i,l);try{let u=await o.readFile();return new Uint8Array(u)}finally{await o.close()}}catch(a){let l=a.code;if(l==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(l==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,r){K(t,"write"),this.assertWritable(`write '${t}'`);let n=B(t);this.ensureParentDirs(n);let i=dt(r),a=Ct(s,i);this.memory.set(n,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(n)}async appendFile(t,s,r){K(t,"append"),this.assertWritable(`append '${t}'`);let n=B(t),i=dt(r),a=Ct(s,i),l;try{l=await this.readFileBuffer(n)}catch{l=new Uint8Array(0)}let o=new Uint8Array(l.length+a.length);o.set(l),o.set(a,l.length),this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(n)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){K(t,"stat");let r=B(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let l=this.resolveSymlink(r,n.target);return this.stat(l,s)}let a=0;return n.type==="file"&&(a=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:a,mtime:n.mtime}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await re.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let l=await re.promises.readlink(i),o=this.realTargetToVirtual(r,l),u=this.resolveSymlink(r,o);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){K(t,"lstat");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(s);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime}}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await re.promises.lstat(n);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return Ot(t,s)}realTargetToVirtual(t,s){let r=fc(s,this.canonicalRoot);if(r.withinRoot){if(!Ee.isAbsolute(s))return s;let n=r.relativePath;return this.mountPoint==="/"?n:`${this.mountPoint}${n}`}return r.safeName}async mkdir(t,s){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=B(t);if(await this.existsInOverlay(r)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=At(r);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,n=new Set,i=s==="/"?"/":`${s}/`;for(let l of this.deleted)if(l.startsWith(i)){let o=l.slice(i.length),u=o.split("/")[0];u&&!o.includes("/",u.length)&&n.add(u)}for(let[l,o]of this.memory)if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!n.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await re.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let l=await re.promises.readdir(a,{withFileTypes:!0});for(let o of l)!n.has(o.name)&&!r.has(o.name)&&r.set(o.name,{name:o.name,isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,s=!1){let r=B(t),n=new Set,i=s,a=this.memory.get(r);for(;a&&a.type==="symlink";){if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(r),i=!0,r=this.resolveSymlink(r,a.target),a=this.memory.get(r)}if(a)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let o=this.resolveRealPath_(this.toRealPath(r));if(!o)return{normalized:r,outsideOverlay:!0};try{if((await re.promises.lstat(o)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await re.promises.readlink(o),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.keys()).sort((i,a)=>ia?1:0)}async readdirWithFileTypes(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.values()).sort((i,a)=>i.namea.name?1:0)}async rm(t,s){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=B(t);if(!await this.existsInOverlay(r)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let a=await this.readdir(r);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let l of a){let o=r==="/"?`/${l}`:`${r}/${l}`;await this.rm(o,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let s=this.toRealPath(t),r=this.resolveRealPathParent_(s);if(!r)return!1;try{return re.lstatSync(r),!0}catch{return!1}}async cp(t,s,r){K(t,"cp"),K(s,"cp"),this.assertWritable(`cp '${s}'`);let n=B(t),i=B(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);await this.writeFile(i,o)}else if(l.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(n);for(let u of o){let c=n==="/"?`/${u}`:`${n}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return Ss(t,s)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let n=re.readdirSync(r);for(let i of n){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let l=Ee.join(r,i);re.lstatSync(l).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=B(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=s;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);K(s,"symlink"),this.assertWritable(`symlink '${s}'`);let r=B(s);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,s){K(t,"link"),K(s,"link"),this.assertWritable(`link '${s}'`);let r=B(t),n=B(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(r);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=await this.readFileBuffer(r);this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:a.mode,mtime:new Date}),this.deleted.delete(n)}async readlink(t){K(t,"readlink");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(s);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await re.promises.readlink(n);if(!Ee.isAbsolute(i)){let a=Ee.resolve(Ee.dirname(n),i),l;try{l=re.realpathSync(a)}catch{l=a}if(!ys(l,this.canonicalRoot))return Ee.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let s=B(t),r=new Set,n=async l=>{let o=l==="/"?[]:l.slice(1).split("/"),u="";for(let c of o){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(u),m=this.resolveRealPath_(p);if(m)try{if((await re.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await re.promises.readlink(m),v=this.realTargetToVirtual(u,b);return r.add(u),u=this.resolveSymlink(u,v),n(u)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(p);if(y)try{if((await re.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return u||"/"},i=await n(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let n=B(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(n);if(a){a.mtime=r;return}let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:l.mode,mtime:r})}else l.isDirectory&&this.memory.set(n,{type:"directory",mode:l.mode,mtime:r})}};function pc(){console.log(`just-bash - A secure bash environment for AI agents Usage: just-bash [options] [script-file] @@ -752,5 +826,5 @@ Examples: # Allow write operations (writes stay in memory) just-bash -c 'echo test > /tmp/file.txt && cat /tmp/file.txt' --allow-write -`)}function ul(){console.log("just-bash 1.0.0")}function fl(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},s=0;for(;s=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[s+1],s+=2;else if(n==="-e"||n==="--errexit")t.errexit=!0,s++;else if(n==="--root")s+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=Zi(e[s+1]),s+=2;else if(n==="--cwd")s+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[s+1],t.cwdOverridden=!0,s+=2;else if(n==="--json")t.json=!0,s++;else if(n==="--allow-write")t.allowWrite=!0,s++;else if(n==="--python")t.python=!0,s++;else if(n==="--javascript")t.javascript=!0,s++;else if(n.startsWith("-"))if(n.length>2&&!n.startsWith("--")){let r=n.slice(1);for(let i of r)if(i==="e")t.errexit=!0;else if(i==="h")t.help=!0;else if(i==="v")t.version=!0;else if(i==="c"){s+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[s+1],s++;break}else console.error(`Error: Unknown option: -${i}`),process.exit(1);s++}else console.error(`Error: Unknown option: ${n}`),process.exit(1);else!t.scriptFile&&!t.script?t.scriptFile=n:t.scriptFile&&t.root===process.cwd()&&(t.root=Zi(n)),s++}return t}function dl(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(r=>r&&r!=="."),n=[];for(let r of s)r===".."?n.pop():n.push(r);return`/${n.join("/")}`||"/"}async function hl(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function pl(){let e=process.argv.slice(2),t=fl(e);t.help&&(qi(),process.exit(0)),t.version&&(ul(),process.exit(0));let s;if(t.script)s=t.script;else if(t.scriptFile){let o=new ht({root:t.root}),l=o.getMountPoint();try{let u=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;s=await o.readFile(u,"utf-8")}catch(u){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(he(u instanceof Error?u.message:String(u))),process.exit(1)}}else process.stdin.isTTY?(qi(),process.exit(1)):s=await hl();s.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let n=new ht({root:t.root,readOnly:!t.allowWrite}),r=n.getMountPoint(),i=t.cwdOverridden?dl(t.cwd):r,a=new ms({fs:n,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(s=`set -e -${s}`);try{let o=await a.exec(s);t.json?console.log(JSON.stringify({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode})):(o.stdout&&process.stdout.write(o.stdout),o.stderr&&process.stderr.write(o.stderr)),process.exit(o.exitCode)}catch(o){let l=he(o instanceof Error?o.message:String(o));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}pl().catch(e=>{console.error("Fatal error:",he(e instanceof Error?e.message:String(e))),process.exit(1)}); +`)}function Xd(){console.log("just-bash 1.0.0")}function Yd(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},s=0;for(;s=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[s+1],s+=2;else if(r==="-e"||r==="--errexit")t.errexit=!0,s++;else if(r==="--root")s+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=hc(e[s+1]),s+=2;else if(r==="--cwd")s+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[s+1],t.cwdOverridden=!0,s+=2;else if(r==="--json")t.json=!0,s++;else if(r==="--allow-write")t.allowWrite=!0,s++;else if(r==="--python")t.python=!0,s++;else if(r==="--javascript")t.javascript=!0,s++;else if(r.startsWith("-"))if(r.length>2&&!r.startsWith("--")){let n=r.slice(1);for(let i of n)if(i==="e")t.errexit=!0;else if(i==="h")t.help=!0;else if(i==="v")t.version=!0;else if(i==="c"){s+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[s+1],s++;break}else console.error(`Error: Unknown option: -${i}`),process.exit(1);s++}else console.error(`Error: Unknown option: ${r}`),process.exit(1);else!t.scriptFile&&!t.script?t.scriptFile=r:t.scriptFile&&t.root===process.cwd()&&(t.root=hc(r)),s++}return t}function Jd(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(n=>n&&n!=="."),r=[];for(let n of s)n===".."?r.pop():r.push(n);return`/${r.join("/")}`||"/"}async function eh(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function th(){let e=process.argv.slice(2),t=Yd(e);t.help&&(pc(),process.exit(0)),t.version&&(Xd(),process.exit(0));let s;if(t.script)s=t.script;else if(t.scriptFile){let l=new Qt({root:t.root}),o=l.getMountPoint();try{let u=t.scriptFile.startsWith("/")?t.scriptFile:`${o}/${t.scriptFile}`;s=await l.readFile(u,"utf-8")}catch(u){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(Re(u instanceof Error?u.message:String(u))),process.exit(1)}}else process.stdin.isTTY?(pc(),process.exit(1)):s=await eh();s.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new Qt({root:t.root,readOnly:!t.allowWrite}),n=r.getMountPoint(),i=t.cwdOverridden?Jd(t.cwd):n,a=new wn({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(s=`set -e +${s}`);try{let l=await a.exec(s);t.json?console.log(JSON.stringify({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode})):(l.stdout&&process.stdout.write(l.stdout),l.stderr&&process.stderr.write(l.stderr)),process.exit(l.exitCode)}catch(l){let o=Re(l instanceof Error?l.message:String(l));t.json?console.log(JSON.stringify({stdout:"",stderr:o,exitCode:1})):console.error(o),process.exit(1)}}th().catch(e=>{console.error("Fatal error:",Re(e instanceof Error?e.message:String(e))),process.exit(1)}); diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-4J4UC7OD.js b/packages/just-bash/dist/bin/shell/chunks/chunk-63LSI3D6.js similarity index 98% rename from packages/just-bash/dist/bin/shell/chunks/chunk-4J4UC7OD.js rename to packages/just-bash/dist/bin/shell/chunks/chunk-63LSI3D6.js index f2d20755..c9eef76c 100644 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-4J4UC7OD.js +++ b/packages/just-bash/dist/bin/shell/chunks/chunk-63LSI3D6.js @@ -1,6 +1,6 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as w,b as V}from"./chunk-LMA4D2KK.js";import{d as E}from"./chunk-MLUOPG3W.js";import{a as T,b as M}from"./chunk-AZH64XMJ.js";import{a as F}from"./chunk-LX2H4DPL.js";import{a as R}from"./chunk-ZZP3RSWL.js";import{a as J}from"./chunk-DHIKZU63.js";import{k as O}from"./chunk-47WZ2U6M.js";import{a as N}from"./chunk-PBOVSFTJ.js";import{a as A,b as L,c as I}from"./chunk-MUFNRCMY.js";function W(t){switch(t){case"\b":return"\\b";case"\f":return"\\f";case` +import{a as w,b as V}from"./chunk-ISLENKSH.js";import{d as E}from"./chunk-MLUOPG3W.js";import{a as T,b as M}from"./chunk-AZH64XMJ.js";import{a as F}from"./chunk-LX2H4DPL.js";import{a as R}from"./chunk-ZZP3RSWL.js";import{a as J}from"./chunk-DHIKZU63.js";import{k as O}from"./chunk-47WZ2U6M.js";import{a as N}from"./chunk-PBOVSFTJ.js";import{a as A,b as L,c as I}from"./chunk-MUFNRCMY.js";function W(t){switch(t){case"\b":return"\\b";case"\f":return"\\f";case` `:return"\\n";case"\r":return"\\r";case" ":return"\\t";default:return`\\u${t.charCodeAt(0).toString(16).padStart(4,"0")}`}}function _(t){let n="",s=!1,i=!1;for(let a=0;a=i)break;let a=s,r=t[s];if(r==="{"||r==="["){let f=r,c=r==="{"?"}":"]",p=1,m=!1,d=!1;for(s++;s0;){let j=t[s];d?d=!1:j==="\\"?d=!0:j==='"'?m=!m:m||(j===f?p++:j===c&&p--),s++}if(p!==0)throw new Error(`Unexpected end of JSON input at position ${s} (unclosed ${f})`);n.push(E(k(t,a,s)))}else if(r==='"'){let f=!1;for(s++;s="0"&&r<="9"){for(;sC(p,!0,!1,i,a)).join(",")}]`:`[ ${t.map(p=>f.repeat(r+1)+C(p,!1,!1,i,a,r+1)).join(`, `)} diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-BKQLXMS6.js b/packages/just-bash/dist/bin/shell/chunks/chunk-BKQLXMS6.js new file mode 100644 index 00000000..9a3d2b41 --- /dev/null +++ b/packages/just-bash/dist/bin/shell/chunks/chunk-BKQLXMS6.js @@ -0,0 +1,36 @@ +#!/usr/bin/env node +import{createRequire} from"node:module";const require=createRequire(import.meta.url); +import{f as G}from"./chunk-MLUOPG3W.js";import{a as q}from"./chunk-3MRB66F4.js";import{a as B,b as U,c as A}from"./chunk-UI7CV277.js";import{a as M}from"./chunk-52FZYTIX.js";import{a as D}from"./chunk-DHIKZU63.js";import{a as z,b as E,c as O}from"./chunk-MUFNRCMY.js";var H=G({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),$=class{types;constructor(){this.types=new Map(Object.entries(H).map(([t,s])=>[t,{extensions:[...s.extensions],globs:[...s.globs]}]))}addType(t){let s=t.indexOf(":");if(s===-1)return;let n=t.slice(0,s),r=t.slice(s+1);if(r.startsWith("include:")){let l=r.slice(8),i=this.types.get(l);if(i){let o=this.types.get(n)||{extensions:[],globs:[]};o.extensions.push(...i.extensions),o.globs.push(...i.globs),this.types.set(n,o)}}else{let l=this.types.get(n)||{extensions:[],globs:[]};if(r.startsWith("*.")&&!r.slice(2).includes("*")){let i=r.slice(1);l.extensions.includes(i)||l.extensions.push(i)}else l.globs.includes(r)||l.globs.push(r);this.types.set(n,l)}}clearType(t){let s=this.types.get(t);s&&(s.extensions=[],s.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,s){let n=t.toLowerCase();for(let r of s){if(r==="all"){if(this.matchesAnyType(t))return!0;continue}let l=this.types.get(r);if(l){for(let i of l.extensions)if(n.endsWith(i))return!0;for(let i of l.globs)if(i.includes("*")){let o=i.replace(/\./g,"\\.").replace(/\*/g,".*");if(M(`^${o}$`,"i").test(t))return!0}else if(n===i.toLowerCase())return!0}}return!1}matchesAnyType(t){let s=t.toLowerCase();for(let n of this.types.values()){for(let r of n.extensions)if(s.endsWith(r))return!0;for(let r of n.globs)if(r.includes("*")){let l=r.replace(/\./g,"\\.").replace(/\*/g,".*");if(M(`^${l}$`,"i").test(t))return!0}else if(s===r.toLowerCase())return!0}return!1}};function V(){let e=[];for(let[t,s]of Object.entries(H).sort()){let n=[];for(let r of s.extensions)n.push(`*${r}`);for(let r of s.globs)n.push(r);e.push(`${t}: ${n.join(", ")}`)}return`${e.join(` +`)} +`}function Z(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}function se(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let s=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return s*1024;case"M":return s*1024*1024;case"G":return s*1024*1024*1024;default:return s}}function ne(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} +`,exitCode:1}}function J(e){return null}var Y=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:J},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:J},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:se,validate:ne},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],re=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),ie=new Set(["n","--line-number"]);function le(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function oe(e,t,s){let n=e[t];for(let r of Y){if(n.startsWith(`--${r.long}=`)){let l=n.slice(`--${r.long}=`.length),i=P(s,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&n.startsWith(`-${r.short}`)&&n.length>2){let l=n.slice(2),i=P(s,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&n===`-${r.short}`||n===`--${r.long}`){if(t+1>=e.length)return null;let l=e[t+1],i=P(s,r,l);return i?{newIndex:t+1,error:i}:{newIndex:t+1}}}return null}function ae(e){return Y.find(t=>t.short===e)}function P(e,t,s){if(t.validate){let r=t.validate(s);if(r)return r}if(t.ignored||!t.target)return;let n=t.parse?t.parse(s):s;t.multi?e[t.target].push(n):e[t.target]=n}function ce(e,t){let s=e[t];if(s==="--sort"&&t+1=e.length)return{success:!1,error:O("rg",`-${u}`)};let f=P(t,g,e[c+1]);if(f)return{success:!1,error:f};c++,m=!0;continue}}let w=re.get(u);if(w){w(t);continue}if(u.startsWith("--"))return{success:!1,error:O("rg",u)};if(u.length===1)return{success:!1,error:O("rg",`-${u}`)}}}else s===null&&t.patterns.length===0&&t.patternFiles.length===0?s=a:n.push(a)}return(r>=0||i>=0)&&(t.afterContext=Math.max(r>=0?r:0,i>=0?i:0)),(l>=0||i>=0)&&(t.beforeContext=Math.max(l>=0?l:0,i>=0?i:0)),s!==null&&t.patterns.push(s),(t.column||t.vimgrep)&&(o=!0),{success:!0,options:t,paths:n,explicitLineNumbers:o}}import{gunzipSync as he}from"node:zlib";var T=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let s=t.split(` +`);for(let n of s){let r=n.replace(/\s+$/,"");if(!r||r.startsWith("#"))continue;let l=!1;r.startsWith("!")&&(l=!0,r=r.slice(1));let i=!1;r.endsWith("/")&&(i=!0,r=r.slice(0,-1));let o=!1;r.startsWith("/")?(o=!0,r=r.slice(1)):r.includes("/")&&!r.startsWith("**/")&&(o=!0);let c=this.patternToRegex(r,o);this.patterns.push({pattern:n,regex:c,negated:l,directoryOnly:i,rooted:o})}}patternToRegex(t,s){let n="";s?n="^":n="(?:^|/)";let r=0;for(;r=t.length,n+=".*",r+=2):(n+="[^/]*",r++);else if(l==="?")n+="[^/]",r++;else if(l==="["){let i=r+1;for(i=2&&e[0]===31&&e[1]===139}function pe(e){let t=!1;for(let s=0;sv.length>0);l.push(...d)}catch{return{stdout:"",stderr:`rg: ${g}: No such file or directory +`,exitCode:2}}if(l.length===0)return s.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given +`,exitCode:2};let i=de(s,l),o,c;try{let g=me(l,s,i);o=g.regex,c=g.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${l.join(", ")} +`,exitCode:2}}let a=s.patternFiles.includes("-"),h=D(t.stdin);if(n.length===0&&h.length>0&&!a){let f=B(h,o,{invertMatch:s.invertMatch,showLineNumbers:s.lineNumber,countOnly:s.count,countMatches:s.countMatches,filename:"",onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace!==null?A(s.replace):null,passthru:s.passthru,multiline:s.multiline,kResetGroup:c});return s.quiet?{stdout:"",stderr:"",exitCode:f.matched?0:1}:s.filesWithMatches?{stdout:f.matched?`(standard input) +`:"",stderr:"",exitCode:f.matched?0:1}:s.filesWithoutMatch?{stdout:f.matched?"":`(standard input) +`,stderr:"",exitCode:f.matched?1:0}:{stdout:f.output,stderr:"",exitCode:f.matched?0:1}}let y=n.length===0?["."]:n,x=null;s.noIgnore||(x=await R(t.fs,t.cwd,s.noIgnoreDot,s.noIgnoreVcs,s.ignoreFiles));let p=new $;for(let g of s.typeClear)p.clearType(g);for(let g of s.typeAdd)p.addType(g);let{files:b,singleExplicitFile:m}=await Q(t,y,s,x,p);if(b.length===0)return{stdout:"",stderr:"",exitCode:1};let u=!s.noFilename&&(s.withFilename||!m||b.length>1),w=s.lineNumber;return r||(m&&b.length===1&&(w=!1),s.onlyMatching&&(w=!1)),we(t,b,o,s,u,w,c)}function de(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(s=>/[A-Z]/.test(s)):!1}function me(e,t,s){let n;return e.length===1?n=e[0]:n=e.map(r=>t.fixedStrings?r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${r})`).join("|"),U(n,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:s,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function Q(e,t,s,n,r){let l=[],i=0,o=0;for(let a of t){let h=e.fs.resolvePath(e.cwd,a);try{let y=await e.fs.stat(h);if(y.isFile){if(i++,s.maxFilesize>0&&y.size>s.maxFilesize)continue;te(a,s,n,h,r)&&l.push(a)}else y.isDirectory&&(o++,await ee(e,a,h,0,s,n,r,l))}catch{}}return{files:s.sort==="path"?l.sort():l,singleExplicitFile:i===1&&o===0}}async function ee(e,t,s,n,r,l,i,o){if(!(n>=r.maxDepth)){l&&await l.loadForDirectory(s);try{let c=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(s):(await e.fs.readdir(s)).map(a=>({name:a,isFile:void 0}));for(let a of c){let h=a.name;if(!r.noIgnore&&N.isCommonIgnored(h))continue;let y=h.startsWith("."),x=t==="."?h:t==="./"?`./${h}`:t.endsWith("/")?`${t}${h}`:`${t}/${h}`,p=e.fs.resolvePath(s,h),b,m,u=!1;if(a.isFile!==void 0&&"isDirectory"in a){let f=a;if(u=f.isSymbolicLink===!0,u&&!r.followSymlinks)continue;if(u&&r.followSymlinks)try{let d=await e.fs.stat(p);b=d.isFile,m=d.isDirectory}catch{continue}else b=f.isFile,m=f.isDirectory}else try{let f=e.fs.lstat?await e.fs.lstat(p):await e.fs.stat(p);if(u=f.isSymbolicLink===!0,u&&!r.followSymlinks)continue;let d=u&&r.followSymlinks?await e.fs.stat(p):f;b=d.isFile,m=d.isDirectory}catch{continue}if(!l?.matches(p,m)&&!(y&&!r.hidden&&!l?.isWhitelisted(p,m))){if(m)await ee(e,x,p,n+1,r,l,i,o);else if(b){if(r.maxFilesize>0)try{if((await e.fs.stat(p)).size>r.maxFilesize)continue}catch{continue}te(x,r,l,p,i)&&o.push(x)}}}}catch{}}}function te(e,t,s,n,r){let l=e.split("/").pop()||e;if(s?.matches(n,!1)||t.types.length>0&&!r.matchesType(l,t.types)||t.typesNot.length>0&&r.matchesType(l,t.typesNot))return!1;if(t.globs.length>0){let i=t.globCaseInsensitive,o=t.globs.filter(a=>!a.startsWith("!")),c=t.globs.filter(a=>a.startsWith("!")).map(a=>a.slice(1));if(o.length>0){let a=!1;for(let h of o)if(C(l,h,i)||C(e,h,i)){a=!0;break}if(!a)return!1}for(let a of c)if(a.startsWith("/")){let h=a.slice(1);if(C(e,h,i))return!1}else if(C(l,a,i)||C(e,a,i))return!1}if(t.iglobs.length>0){let i=t.iglobs.filter(c=>!c.startsWith("!")),o=t.iglobs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(i.length>0){let c=!1;for(let a of i)if(C(l,a,!0)||C(e,a,!0)){c=!0;break}if(!c)return!1}for(let c of o)if(c.startsWith("/")){let a=c.slice(1);if(C(e,a,!0))return!1}else if(C(l,c,!0)||C(e,c,!0))return!1}return!0}function C(e,t,s=!1){let n="^";for(let r=0;ra+o).join(""),stderr:"",exitCode:0}}function ye(e,t){if(t.length===0)return!0;for(let s of t)if(C(e,s,!1))return!0;return!1}async function be(e,t,s,n){try{if(n.preprocessor&&e.exec){let i=s.split("/").pop()||s;if(ye(i,n.preprocessorGlobs)){let o=await e.exec(q([n.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(o.exitCode===0&&o.stdout){let c=D(o.stdout),a=c.slice(0,8192);return{content:c,isBinary:a.includes("\0")}}}}if(n.searchZip&&s.endsWith(".gz")){let i=await e.fs.readFileBuffer(t);if(ge(i))try{let o=he(i),c=new TextDecoder().decode(o),a=c.slice(0,8192);return{content:c,isBinary:a.includes("\0")}}catch{return null}}let r=await e.fs.readFile(t),l=r.slice(0,8192);return{content:r,isBinary:l.includes("\0")}}catch{return null}}async function we(e,t,s,n,r,l,i){let o="",c=!1,a=[],h=0,y=0,x=0,p=50;e:for(let u=0;u{let d=e.fs.resolvePath(e.cwd,f),v=await be(e,d,f,n);if(!v)return null;let{content:F,isBinary:W}=v;if(x+=F.length,W&&!n.searchBinary)return null;let k=r&&!n.heading?f:"",I=B(F,s,{invertMatch:n.invertMatch,showLineNumbers:l,countOnly:n.count,countMatches:n.countMatches,filename:k,onlyMatching:n.onlyMatching,beforeContext:n.beforeContext,afterContext:n.afterContext,maxCount:n.maxCount,contextSeparator:n.contextSeparator,showColumn:n.column,vimgrep:n.vimgrep,showByteOffset:n.byteOffset,replace:n.replace!==null?A(n.replace):null,passthru:n.passthru,multiline:n.multiline,kResetGroup:i});return n.json&&I.matched?{file:f,result:I,content:F,isBinary:!1}:{file:f,result:I}}));for(let f of g){if(!f)continue;let{file:d,result:v}=f;if(v.matched){if(c=!0,y++,h+=v.matchCount,n.quiet&&!n.json)break e;if(n.json&&!n.quiet){let F=f.content||"";a.push(JSON.stringify({type:"begin",data:{path:{text:d}}}));let W=F.split(` +`);s.lastIndex=0;let k=0;for(let I=0;I0){let S={type:"match",data:{path:{text:d},lines:{text:`${j} +`},line_number:I+1,absolute_offset:k,submatches:L}};a.push(JSON.stringify(S))}k+=j.length+1}a.push(JSON.stringify({type:"end",data:{path:{text:d},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:F.length,bytes_printed:0,matched_lines:v.matchCount,matches:v.matchCount}}}))}else if(n.filesWithMatches){let F=n.nullSeparator?"\0":` +`;o+=`${d}${F}`}else n.filesWithoutMatch||(n.heading&&!n.noFilename&&(o+=`${d} +`),o+=v.output)}else if(n.filesWithoutMatch){let F=n.nullSeparator?"\0":` +`;o+=`${d}${F}`}else n.includeZero&&(n.count||n.countMatches)&&(o+=v.output)}}n.json&&(a.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:y,bytes_searched:x,bytes_printed:0,matched_lines:h,matches:h}}})),o=`${a.join(` +`)} +`);let b=n.quiet&&!n.json?"":o;if(n.stats&&!n.json){let u=["",`${h} matches`,`${h} matched lines`,`${y} files contained matches`,`${t.length} files searched`,`${x} bytes searched`].join(` +`);b+=`${u} +`}let m;return n.filesWithoutMatch?m=o.length>0?0:1:m=c?0:1,{stdout:b,stderr:"",exitCode:m}}var ve={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. +Unlike grep, rg is recursive by default and respects .gitignore files. + +EXAMPLES: + rg foo Search for 'foo' in current directory + rg foo src/ Search in src/ directory + rg -i foo Case-insensitive search + rg -w foo Match whole words only + rg -t js foo Search only JavaScript files + rg -g '*.ts' foo Search files matching glob + rg --hidden foo Include hidden files + rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ge={name:"rg",async execute(e,t){if(E(e))return z(ve);if(e.includes("--type-list"))return{stdout:V(),stderr:"",exitCode:0};let s=K(e);return s.success?X({ctx:t,options:s.options,paths:s.paths,explicitLineNumbers:s.explicitLineNumbers}):s.error}},qe={name:"rg",flags:[{flag:"-i",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-N",type:"boolean"},{flag:"--hidden",type:"boolean"},{flag:"--no-ignore",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-g",type:"value",valueHint:"pattern"},{flag:"-t",type:"value",valueHint:"string"},{flag:"-T",type:"value",valueHint:"string"}],needsArgs:!0};export{Ge as a,qe as b}; diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-GXX3QUMM.js b/packages/just-bash/dist/bin/shell/chunks/chunk-GXX3QUMM.js deleted file mode 100644 index a0295baa..00000000 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-GXX3QUMM.js +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{f as G}from"./chunk-MLUOPG3W.js";import{a as q}from"./chunk-3MRB66F4.js";import{a as z,b as E,c as U}from"./chunk-UI7CV277.js";import{a as $}from"./chunk-52FZYTIX.js";import{a as L}from"./chunk-DHIKZU63.js";import{a as B,b as _,c as D}from"./chunk-MUFNRCMY.js";var H=G({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),M=class{types;constructor(){this.types=new Map(Object.entries(H).map(([t,n])=>[t,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(t){let n=t.indexOf(":");if(n===-1)return;let s=t.slice(0,n),r=t.slice(n+1);if(r.startsWith("include:")){let l=r.slice(8),i=this.types.get(l);if(i){let a=this.types.get(s)||{extensions:[],globs:[]};a.extensions.push(...i.extensions),a.globs.push(...i.globs),this.types.set(s,a)}}else{let l=this.types.get(s)||{extensions:[],globs:[]};if(r.startsWith("*.")&&!r.slice(2).includes("*")){let i=r.slice(1);l.extensions.includes(i)||l.extensions.push(i)}else l.globs.includes(r)||l.globs.push(r);this.types.set(s,l)}}clearType(t){let n=this.types.get(t);n&&(n.extensions=[],n.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,n){let s=t.toLowerCase();for(let r of n){if(r==="all"){if(this.matchesAnyType(t))return!0;continue}let l=this.types.get(r);if(l){for(let i of l.extensions)if(s.endsWith(i))return!0;for(let i of l.globs)if(i.includes("*")){let a=i.replace(/\./g,"\\.").replace(/\*/g,".*");if($(`^${a}$`,"i").test(t))return!0}else if(s===i.toLowerCase())return!0}}return!1}matchesAnyType(t){let n=t.toLowerCase();for(let s of this.types.values()){for(let r of s.extensions)if(n.endsWith(r))return!0;for(let r of s.globs)if(r.includes("*")){let l=r.replace(/\./g,"\\.").replace(/\*/g,".*");if($(`^${l}$`,"i").test(t))return!0}else if(n===r.toLowerCase())return!0}return!1}};function V(){let e=[];for(let[t,n]of Object.entries(H).sort()){let s=[];for(let r of n.extensions)s.push(`*${r}`);for(let r of n.globs)s.push(r);e.push(`${t}: ${s.join(", ")}`)}return`${e.join(` -`)} -`}function Z(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}function se(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let n=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return n*1024;case"M":return n*1024*1024;case"G":return n*1024*1024*1024;default:return n}}function ne(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} -`,exitCode:1}}function J(e){return null}var Y=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:J},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:J},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:se,validate:ne},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],re=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),ie=new Set(["n","--line-number"]);function le(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function oe(e,t,n){let s=e[t];for(let r of Y){if(s.startsWith(`--${r.long}=`)){let l=s.slice(`--${r.long}=`.length),i=P(n,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&s.startsWith(`-${r.short}`)&&s.length>2){let l=s.slice(2),i=P(n,r,l);return i?{newIndex:t,error:i}:{newIndex:t}}if(r.short&&s===`-${r.short}`||s===`--${r.long}`){if(t+1>=e.length)return null;let l=e[t+1],i=P(n,r,l);return i?{newIndex:t+1,error:i}:{newIndex:t+1}}}return null}function ae(e){return Y.find(t=>t.short===e)}function P(e,t,n){if(t.validate){let r=t.validate(n);if(r)return r}if(t.ignored||!t.target)return;let s=t.parse?t.parse(n):n;t.multi?e[t.target].push(s):e[t.target]=s}function ce(e,t){let n=e[t];if(n==="--sort"&&t+1=e.length)return{success:!1,error:D("rg",`-${f}`)};let h=P(t,b,e[c+1]);if(h)return{success:!1,error:h};c++,m=!0;continue}}let x=re.get(f);if(x){x(t);continue}if(f.startsWith("--"))return{success:!1,error:D("rg",f)};if(f.length===1)return{success:!1,error:D("rg",`-${f}`)}}}else n===null&&t.patterns.length===0&&t.patternFiles.length===0?n=o:s.push(o)}return(r>=0||i>=0)&&(t.afterContext=Math.max(r>=0?r:0,i>=0?i:0)),(l>=0||i>=0)&&(t.beforeContext=Math.max(l>=0?l:0,i>=0?i:0)),n!==null&&t.patterns.push(n),(t.column||t.vimgrep)&&(a=!0),{success:!0,options:t,paths:s,explicitLineNumbers:a}}import{gunzipSync as he}from"node:zlib";var T=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let n=t.split(` -`);for(let s of n){let r=s.replace(/\s+$/,"");if(!r||r.startsWith("#"))continue;let l=!1;r.startsWith("!")&&(l=!0,r=r.slice(1));let i=!1;r.endsWith("/")&&(i=!0,r=r.slice(0,-1));let a=!1;r.startsWith("/")?(a=!0,r=r.slice(1)):r.includes("/")&&!r.startsWith("**/")&&(a=!0);let c=this.patternToRegex(r,a);this.patterns.push({pattern:s,regex:c,negated:l,directoryOnly:i,rooted:a})}}patternToRegex(t,n){let s="";n?s="^":s="(?:^|/)";let r=0;for(;r=t.length,s+=".*",r+=2):(s+="[^/]*",r++);else if(l==="?")s+="[^/]",r++;else if(l==="["){let i=r+1;for(i=2&&e[0]===31&&e[1]===139}function pe(e){let t=!1;for(let n=0;nh.length>0);l.push(...b)}catch{return{stdout:"",stderr:`rg: ${f}: No such file or directory -`,exitCode:2}}if(l.length===0)return n.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given -`,exitCode:2};let i=s.length===0?["."]:s,a=me(n,l),c,o;try{let f=de(l,n,a);c=f.regex,o=f.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${l.join(", ")} -`,exitCode:2}}let u=null;n.noIgnore||(u=await A(t.fs,t.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let d=new M;for(let f of n.typeClear)d.clearType(f);for(let f of n.typeAdd)d.addType(f);let{files:p,singleExplicitFile:g}=await Q(t,i,n,u,d);if(p.length===0)return{stdout:"",stderr:"",exitCode:1};let w=!n.noFilename&&(n.withFilename||!g||p.length>1),m=n.lineNumber;return r||(g&&p.length===1&&(m=!1),n.onlyMatching&&(m=!1)),we(t,p,c,n,w,m,o)}function me(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(n=>/[A-Z]/.test(n)):!1}function de(e,t,n){let s;return e.length===1?s=e[0]:s=e.map(r=>t.fixedStrings?r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${r})`).join("|"),E(s,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:n,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function Q(e,t,n,s,r){let l=[],i=0,a=0;for(let o of t){let u=e.fs.resolvePath(e.cwd,o);try{let d=await e.fs.stat(u);if(d.isFile){if(i++,n.maxFilesize>0&&d.size>n.maxFilesize)continue;te(o,n,s,u,r)&&l.push(o)}else d.isDirectory&&(a++,await ee(e,o,u,0,n,s,r,l))}catch{}}return{files:n.sort==="path"?l.sort():l,singleExplicitFile:i===1&&a===0}}async function ee(e,t,n,s,r,l,i,a){if(!(s>=r.maxDepth)){l&&await l.loadForDirectory(n);try{let c=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(n):(await e.fs.readdir(n)).map(o=>({name:o,isFile:void 0}));for(let o of c){let u=o.name;if(!r.noIgnore&&k.isCommonIgnored(u))continue;let d=u.startsWith("."),p=t==="."?u:t==="./"?`./${u}`:t.endsWith("/")?`${t}${u}`:`${t}/${u}`,g=e.fs.resolvePath(n,u),w,m,f=!1;if(o.isFile!==void 0&&"isDirectory"in o){let h=o;if(f=h.isSymbolicLink===!0,f&&!r.followSymlinks)continue;if(f&&r.followSymlinks)try{let y=await e.fs.stat(g);w=y.isFile,m=y.isDirectory}catch{continue}else w=h.isFile,m=h.isDirectory}else try{let h=e.fs.lstat?await e.fs.lstat(g):await e.fs.stat(g);if(f=h.isSymbolicLink===!0,f&&!r.followSymlinks)continue;let y=f&&r.followSymlinks?await e.fs.stat(g):h;w=y.isFile,m=y.isDirectory}catch{continue}if(!l?.matches(g,m)&&!(d&&!r.hidden&&!l?.isWhitelisted(g,m))){if(m)await ee(e,p,g,s+1,r,l,i,a);else if(w){if(r.maxFilesize>0)try{if((await e.fs.stat(g)).size>r.maxFilesize)continue}catch{continue}te(p,r,l,g,i)&&a.push(p)}}}}catch{}}}function te(e,t,n,s,r){let l=e.split("/").pop()||e;if(n?.matches(s,!1)||t.types.length>0&&!r.matchesType(l,t.types)||t.typesNot.length>0&&r.matchesType(l,t.typesNot))return!1;if(t.globs.length>0){let i=t.globCaseInsensitive,a=t.globs.filter(o=>!o.startsWith("!")),c=t.globs.filter(o=>o.startsWith("!")).map(o=>o.slice(1));if(a.length>0){let o=!1;for(let u of a)if(v(l,u,i)||v(e,u,i)){o=!0;break}if(!o)return!1}for(let o of c)if(o.startsWith("/")){let u=o.slice(1);if(v(e,u,i))return!1}else if(v(l,o,i)||v(e,o,i))return!1}if(t.iglobs.length>0){let i=t.iglobs.filter(c=>!c.startsWith("!")),a=t.iglobs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(i.length>0){let c=!1;for(let o of i)if(v(l,o,!0)||v(e,o,!0)){c=!0;break}if(!c)return!1}for(let c of a)if(c.startsWith("/")){let o=c.slice(1);if(v(e,o,!0))return!1}else if(v(l,c,!0)||v(e,c,!0))return!1}return!0}function v(e,t,n=!1){let s="^";for(let r=0;ro+a).join(""),stderr:"",exitCode:0}}function ye(e,t){if(t.length===0)return!0;for(let n of t)if(v(e,n,!1))return!0;return!1}async function be(e,t,n,s){try{if(s.preprocessor&&e.exec){let i=n.split("/").pop()||n;if(ye(i,s.preprocessorGlobs)){let a=await e.exec(q([s.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(a.exitCode===0&&a.stdout){let c=L(a.stdout),o=c.slice(0,8192);return{content:c,isBinary:o.includes("\0")}}}}if(s.searchZip&&n.endsWith(".gz")){let i=await e.fs.readFileBuffer(t);if(ge(i))try{let a=he(i),c=new TextDecoder().decode(a),o=c.slice(0,8192);return{content:c,isBinary:o.includes("\0")}}catch{return null}}let r=await e.fs.readFile(t),l=r.slice(0,8192);return{content:r,isBinary:l.includes("\0")}}catch{return null}}async function we(e,t,n,s,r,l,i){let a="",c=!1,o=[],u=0,d=0,p=0,g=50;e:for(let f=0;f{let y=e.fs.resolvePath(e.cwd,h),F=await be(e,y,h,s);if(!F)return null;let{content:C,isBinary:N}=F;if(p+=C.length,N&&!s.searchBinary)return null;let W=r&&!s.heading?h:"",S=z(C,n,{invertMatch:s.invertMatch,showLineNumbers:l,countOnly:s.count,countMatches:s.countMatches,filename:W,onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace!==null?U(s.replace):null,passthru:s.passthru,multiline:s.multiline,kResetGroup:i});return s.json&&S.matched?{file:h,result:S,content:C,isBinary:!1}:{file:h,result:S}}));for(let h of b){if(!h)continue;let{file:y,result:F}=h;if(F.matched){if(c=!0,d++,u+=F.matchCount,s.quiet&&!s.json)break e;if(s.json&&!s.quiet){let C=h.content||"";o.push(JSON.stringify({type:"begin",data:{path:{text:y}}}));let N=C.split(` -`);n.lastIndex=0;let W=0;for(let S=0;S0){let I={type:"match",data:{path:{text:y},lines:{text:`${j} -`},line_number:S+1,absolute_offset:W,submatches:O}};o.push(JSON.stringify(I))}W+=j.length+1}o.push(JSON.stringify({type:"end",data:{path:{text:y},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:C.length,bytes_printed:0,matched_lines:F.matchCount,matches:F.matchCount}}}))}else if(s.filesWithMatches){let C=s.nullSeparator?"\0":` -`;a+=`${y}${C}`}else s.filesWithoutMatch||(s.heading&&!s.noFilename&&(a+=`${y} -`),a+=F.output)}else if(s.filesWithoutMatch){let C=s.nullSeparator?"\0":` -`;a+=`${y}${C}`}else s.includeZero&&(s.count||s.countMatches)&&(a+=F.output)}}s.json&&(o.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:d,bytes_searched:p,bytes_printed:0,matched_lines:u,matches:u}}})),a=`${o.join(` -`)} -`);let w=s.quiet&&!s.json?"":a;if(s.stats&&!s.json){let f=["",`${u} matches`,`${u} matched lines`,`${d} files contained matches`,`${t.length} files searched`,`${p} bytes searched`].join(` -`);w+=`${f} -`}let m;return s.filesWithoutMatch?m=a.length>0?0:1:m=c?0:1,{stdout:w,stderr:"",exitCode:m}}var ve={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. -Unlike grep, rg is recursive by default and respects .gitignore files. - -EXAMPLES: - rg foo Search for 'foo' in current directory - rg foo src/ Search in src/ directory - rg -i foo Case-insensitive search - rg -w foo Match whole words only - rg -t js foo Search only JavaScript files - rg -g '*.ts' foo Search files matching glob - rg --hidden foo Include hidden files - rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ge={name:"rg",async execute(e,t){if(_(e))return B(ve);if(e.includes("--type-list"))return{stdout:V(),stderr:"",exitCode:0};let n=K(e);return n.success?X({ctx:t,options:n.options,paths:n.paths,explicitLineNumbers:n.explicitLineNumbers}):n.error}},qe={name:"rg",flags:[{flag:"-i",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-N",type:"boolean"},{flag:"--hidden",type:"boolean"},{flag:"--no-ignore",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-g",type:"value",valueHint:"pattern"},{flag:"-t",type:"value",valueHint:"string"},{flag:"-T",type:"value",valueHint:"string"}],needsArgs:!0};export{Ge as a,qe as b}; diff --git a/packages/just-bash/dist/bin/chunks/chunk-J7XTZ47D.js b/packages/just-bash/dist/bin/shell/chunks/chunk-HZR3FOJM.js similarity index 99% rename from packages/just-bash/dist/bin/chunks/chunk-J7XTZ47D.js rename to packages/just-bash/dist/bin/shell/chunks/chunk-HZR3FOJM.js index 6cf0cff5..b3af3108 100644 --- a/packages/just-bash/dist/bin/chunks/chunk-J7XTZ47D.js +++ b/packages/just-bash/dist/bin/shell/chunks/chunk-HZR3FOJM.js @@ -1,6 +1,6 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as $l}from"./chunk-MNWK4UIM.js";import{a as Be,b as er}from"./chunk-LMA4D2KK.js";import{d as D}from"./chunk-MLUOPG3W.js";import{a as Qi,b as Zi}from"./chunk-AZH64XMJ.js";import{a as Bs}from"./chunk-LX2H4DPL.js";import{a as Hi}from"./chunk-DHIKZU63.js";import{k as Vs}from"./chunk-47WZ2U6M.js";import{a as js}from"./chunk-PBOVSFTJ.js";import{a as Xi,b as zi,c as he}from"./chunk-MUFNRCMY.js";import{a as Ot,c as w,e as Fs}from"./chunk-LNVSXNT7.js";var xr=w((xm,_r)=>{var{hasOwnProperty:nn}=Object.prototype,rn=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r +import{a as $l}from"./chunk-MNWK4UIM.js";import{a as Be,b as er}from"./chunk-ISLENKSH.js";import{d as D}from"./chunk-MLUOPG3W.js";import{a as Qi,b as Zi}from"./chunk-AZH64XMJ.js";import{a as Bs}from"./chunk-LX2H4DPL.js";import{a as Hi}from"./chunk-DHIKZU63.js";import{k as Vs}from"./chunk-47WZ2U6M.js";import{a as js}from"./chunk-PBOVSFTJ.js";import{a as Xi,b as zi,c as he}from"./chunk-MUFNRCMY.js";import{a as Ot,c as w,e as Fs}from"./chunk-LNVSXNT7.js";var xr=w((xm,_r)=>{var{hasOwnProperty:nn}=Object.prototype,rn=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r `:` `,n=e.whitespace?" = ":"=",i=[],r=e.sort?Object.keys(s).sort():Object.keys(s),o=0;e.align&&(o=z(r.filter(c=>s[c]===null||Array.isArray(s[c])||typeof s[c]!="object").map(c=>Array.isArray(s[c])?`${c}[]`:c).concat([""]).reduce((c,u)=>z(c).length>=z(u).length?c:u)).length);let a="",l=e.bracketedArray?"[]":"";for(let c of r){let u=s[c];if(u&&Array.isArray(u))for(let f of u)a+=z(`${c}${l}`).padEnd(o," ")+n+z(f)+t;else u&&typeof u=="object"?i.push(c):a+=z(c).padEnd(o," ")+n+z(u)+t}e.section&&a.length&&(a="["+z(e.section)+"]"+(e.newline?t+t:t)+a);for(let c of i){let u=qr(c,".").join("\\."),f=(e.section?e.section+".":"")+u,h=rn(s[c],{...e,section:f});a.length&&h.length&&(a+=t),a+=h}return a};function qr(s,e){var t=0,n=0,i=0,r=[];do if(i=s.indexOf(e,t),i!==-1){if(t=i+e.length,i>0&&s[i-1]==="\\")continue;r.push(s.slice(n,i)),n=i+e.length}while(i!==-1);return r.push(s.slice(n)),r}var Lr=(s,e={})=>{e.bracketedArray=e.bracketedArray!==!1;let t=Object.create(null),n=t,i=null,r=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,o=s.split(/[\r\n]+/g),a={};for(let c of o){if(!c||c.match(/^\s*[;#]/)||c.match(/^\s*$/))continue;let u=c.match(r);if(!u)continue;if(u[1]!==void 0){if(i=Mt(u[1]),i==="__proto__"){n=Object.create(null);continue}n=t[i]=t[i]||Object.create(null);continue}let f=Mt(u[2]),h;e.bracketedArray?h=f.length>2&&f.slice(-2)==="[]":(a[f]=(a?.[f]||0)+1,h=a[f]>1);let p=h&&f.endsWith("[]")?f.slice(0,-2):f;if(p==="__proto__")continue;let g=u[3]?Mt(u[4]):!0,d=g==="true"||g==="false"||g==="null"?JSON.parse(g):g;h&&(nn.call(n,p)?Array.isArray(n[p])||(n[p]=[n[p]]):n[p]=[]),Array.isArray(n[p])?n[p].push(d):n[p]=d}let l=[];for(let c of Object.keys(t)){if(!nn.call(t,c)||typeof t[c]!="object"||Array.isArray(t[c]))continue;let u=qr(c,".");n=t;let f=u.pop(),h=f.replace(/\\\./g,".");for(let p of u)p!=="__proto__"&&((!nn.call(n,p)||typeof n[p]!="object")&&(n[p]=Object.create(null)),n=n[p]);n===t&&h===f||(n[h]=t[c],l.push(c))}for(let c of l)delete t[c];return t},Pr=s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"),z=s=>typeof s!="string"||s.match(/[=\r\n]/)||s.match(/^\[/)||s.length>1&&Pr(s)||s!==s.trim()?JSON.stringify(s):s.split(";").join("\\;").split("#").join("\\#"),Mt=s=>{if(s=(s||"").trim(),Pr(s)){s.charAt(0)==="'"&&(s=s.slice(1,-1));try{s=JSON.parse(s)}catch{}}else{let e=!1,t="";for(let n=0,i=s.length;n{"use strict";var un=Symbol.for("yaml.alias"),Ur=Symbol.for("yaml.document"),jt=Symbol.for("yaml.map"),Kr=Symbol.for("yaml.pair"),fn=Symbol.for("yaml.scalar"),Ut=Symbol.for("yaml.seq"),Q=Symbol.for("yaml.node.type"),zc=s=>!!s&&typeof s=="object"&&s[Q]===un,Qc=s=>!!s&&typeof s=="object"&&s[Q]===Ur,Zc=s=>!!s&&typeof s=="object"&&s[Q]===jt,eu=s=>!!s&&typeof s=="object"&&s[Q]===Kr,Yr=s=>!!s&&typeof s=="object"&&s[Q]===fn,tu=s=>!!s&&typeof s=="object"&&s[Q]===Ut;function Dr(s){if(s&&typeof s=="object")switch(s[Q]){case jt:case Ut:return!0}return!1}function su(s){if(s&&typeof s=="object")switch(s[Q]){case un:case jt:case fn:case Ut:return!0}return!1}var nu=s=>(Yr(s)||Dr(s))&&!!s.anchor;x.ALIAS=un;x.DOC=Ur;x.MAP=jt;x.NODE_TYPE=Q;x.PAIR=Kr;x.SCALAR=fn;x.SEQ=Ut;x.hasAnchor=nu;x.isAlias=zc;x.isCollection=Dr;x.isDocument=Qc;x.isMap=Zc;x.isNode=su;x.isPair=eu;x.isScalar=Yr;x.isSeq=tu});var He=w(hn=>{"use strict";var _=C(),V=Symbol("break visit"),Jr=Symbol("skip children"),H=Symbol("remove node");function Kt(s,e){let t=Gr(e);_.isDocument(s)?ke(null,s.contents,t,Object.freeze([s]))===H&&(s.contents=null):ke(null,s,t,Object.freeze([]))}Kt.BREAK=V;Kt.SKIP=Jr;Kt.REMOVE=H;function ke(s,e,t,n){let i=Wr(s,e,t,n);if(_.isNode(i)||_.isPair(i))return Hr(s,n,i),ke(s,i,t,n);if(typeof i!="symbol"){if(_.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r{"use strict";var Xr=C(),iu=He(),ru={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},ou=s=>s.replace(/[!,[\]{}]/g,e=>ru[e]),Xe=class s{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},s.defaultYaml,e),this.tags=Object.assign({},s.defaultTags,t)}clone(){let e=new s(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new s(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:s.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},s.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:s.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},s.defaultTags),this.atNextDocument=!1);let n=e.trim().split(/[ \t]+/),i=n.shift();switch(i){case"%TAG":{if(n.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;let[r,o]=n;return this.tags[r]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,n.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[r]=n;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{let o=/^\d+\.\d+$/.test(r);return t(6,`Unsupported YAML version ${r}`,o),!1}}default:return t(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let o=e.slice(2,-1);return o==="!"||o==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),o)}let[,n,i]=e.match(/^(.*!)([^!]*)$/s);i||t(`The ${e} tag has no suffix`);let r=this.tags[n];if(r)try{return r+decodeURIComponent(i)}catch(o){return t(String(o)),null}return n==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+ou(e.substring(n.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags),i;if(e&&n.length>0&&Xr.isNode(e.contents)){let r={};iu.visit(e.contents,(o,a)=>{Xr.isNode(a)&&a.tag&&(r[a.tag]=!0)}),i=Object.keys(r)}else i=[];for(let[r,o]of n)r==="!!"&&o==="tag:yaml.org,2002:"||(!e||i.some(a=>a.startsWith(o)))&&t.push(`%TAG ${r} ${o}`);return t.join(` `)}};Xe.defaultYaml={explicit:!1,version:"1.2"};Xe.defaultTags={"!!":"tag:yaml.org,2002:"};zr.Directives=Xe});var Dt=w(ze=>{"use strict";var Qr=C(),au=He();function lu(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function Zr(s){let e=new Set;return au.visit(s,{Value(t,n){n.anchor&&e.add(n.anchor)}}),e}function eo(s,e){for(let t=1;;++t){let n=`${s}${t}`;if(!e.has(n))return n}}function cu(s,e){let t=[],n=new Map,i=null;return{onAnchor:r=>{t.push(r),i??(i=Zr(s));let o=eo(e,i);return i.add(o),o},setAnchors:()=>{for(let r of t){let o=n.get(r);if(typeof o=="object"&&o.anchor&&(Qr.isScalar(o.node)||Qr.isCollection(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=r,a}}},sourceObjects:n}}ze.anchorIsValid=lu;ze.anchorNames=Zr;ze.createNodeAnchors=cu;ze.findNewAnchor=eo});var pn=w(to=>{"use strict";function Qe(s,e,t,n){if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0,r=n.length;i{"use strict";var uu=C();function so(s,e,t){if(Array.isArray(s))return s.map((n,i)=>so(n,String(i),t));if(s&&typeof s.toJSON=="function"){if(!t||!uu.hasAnchor(s))return s.toJSON(e,t);let n={aliasCount:0,count:1,res:void 0};t.anchors.set(s,n),t.onCreate=r=>{n.res=r,delete t.onCreate};let i=s.toJSON(e,t);return t.onCreate&&t.onCreate(i),i}return typeof s=="bigint"&&!t?.keep?Number(s):s}no.toJS=so});var Jt=w(ro=>{"use strict";var fu=pn(),io=C(),hu=se(),mn=class{constructor(e){Object.defineProperty(this,io.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:i,reviver:r}={}){if(!io.isDocument(e))throw new TypeError("A document argument is required");let o={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n=="number"?n:100},a=hu.toJS(this,"",o);if(typeof i=="function")for(let{count:l,res:c}of o.anchors.values())i(c,l);return typeof r=="function"?fu.applyReviver(r,{"":a},"",a):a}};ro.NodeBase=mn});var Ze=w(oo=>{"use strict";var du=Dt(),pu=He(),Le=C(),mu=Jt(),gu=se(),gn=class extends mu.NodeBase{constructor(e){super(Le.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],pu.visit(e,{Node:(r,o)=>{(Le.isAlias(o)||Le.hasAnchor(o))&&n.push(o)}}),t&&(t.aliasResolveCache=n));let i;for(let r of n){if(r===this)break;r.anchor===this.source&&(i=r)}return i}toJSON(e,t){if(!t)return{source:this.source};let{anchors:n,doc:i,maxAliasCount:r}=t,o=this.resolve(i,t);if(!o){let l=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(l)}let a=n.get(o);if(a||(gu.toJS(o,null,t),a=n.get(o)),a?.res===void 0){let l="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(l)}if(r>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=Gt(i,o,n)),a.count*a.aliasCount>r)){let l="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(l)}return a.res}toString(e,t,n){let i=`*${this.source}`;if(e){if(du.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${i} `}return i}};function Gt(s,e,t){if(Le.isAlias(e)){let n=e.resolve(s),i=t&&n&&t.get(n);return i?i.count*i.aliasCount:0}else if(Le.isCollection(e)){let n=0;for(let i of e.items){let r=Gt(s,i,t);r>n&&(n=r)}return n}else if(Le.isPair(e)){let n=Gt(s,e.key,t),i=Gt(s,e.value,t);return Math.max(n,i)}return 1}oo.Alias=gn});var L=w(yn=>{"use strict";var yu=C(),bu=Jt(),wu=se(),Su=s=>!s||typeof s!="function"&&typeof s!="object",ne=class extends bu.NodeBase{constructor(e){super(yu.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:wu.toJS(this.value,e,t)}toString(){return String(this.value)}};ne.BLOCK_FOLDED="BLOCK_FOLDED";ne.BLOCK_LITERAL="BLOCK_LITERAL";ne.PLAIN="PLAIN";ne.QUOTE_DOUBLE="QUOTE_DOUBLE";ne.QUOTE_SINGLE="QUOTE_SINGLE";yn.Scalar=ne;yn.isScalarValue=Su});var et=w(lo=>{"use strict";var Nu=Ze(),me=C(),ao=L(),Au="tag:yaml.org,2002:";function Eu(s,e,t){if(e){let n=t.filter(r=>r.tag===e),i=n.find(r=>!r.format)??n[0];if(!i)throw new Error(`Tag ${e} not found`);return i}return t.find(n=>n.identify?.(s)&&!n.format)}function vu(s,e,t){if(me.isDocument(s)&&(s=s.contents),me.isNode(s))return s;if(me.isPair(s)){let f=t.schema[me.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:n,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=t,l;if(n&&s&&typeof s=="object"){if(l=a.get(s),l)return l.anchor??(l.anchor=i(s)),new Nu.Alias(l.anchor);l={anchor:null,node:null},a.set(s,l)}e?.startsWith("!!")&&(e=Au+e.slice(2));let c=Eu(s,e,o.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new ao.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?o[me.MAP]:Symbol.iterator in Object(s)?o[me.SEQ]:o[me.MAP]}r&&(r(c),delete t.onTagObj);let u=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new ao.Scalar(s);return e?u.tag=e:c.default||(u.tag=c.tag),l&&(l.node=u),u}lo.createNode=vu});var Ht=w(Wt=>{"use strict";var Tu=et(),X=C(),Cu=Jt();function bn(s,e,t){let n=t;for(let i=e.length-1;i>=0;--i){let r=e[i];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let o=[];o[r]=n,n=o}else n=new Map([[r,n]])}return Tu.createNode(n,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var co=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,wn=class extends Cu.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(n=>X.isNode(n)||X.isPair(n)?n.clone(e):n),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(co(e))this.add(t);else{let[n,...i]=e,r=this.get(n,!0);if(X.isCollection(r))r.addIn(i,t);else if(r===void 0&&this.schema)this.set(n,bn(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let i=this.get(t,!0);if(X.isCollection(i))return i.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...i]=e,r=this.get(n,!0);return i.length===0?!t&&X.isScalar(r)?r.value:r:X.isCollection(r)?r.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!X.isPair(t))return!1;let n=t.value;return n==null||e&&X.isScalar(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let i=this.get(t,!0);return X.isCollection(i)?i.hasIn(n):!1}setIn(e,t){let[n,...i]=e;if(i.length===0)this.set(n,t);else{let r=this.get(n,!0);if(X.isCollection(r))r.setIn(i,t);else if(r===void 0&&this.schema)this.set(n,bn(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}};Wt.Collection=wn;Wt.collectionFromPath=bn;Wt.isEmptyPath=co});var tt=w(Xt=>{"use strict";var Ou=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function Sn(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var ku=(s,e,t)=>s.endsWith(` diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-ISLENKSH.js b/packages/just-bash/dist/bin/shell/chunks/chunk-ISLENKSH.js new file mode 100644 index 00000000..a4d2ca4d --- /dev/null +++ b/packages/just-bash/dist/bin/shell/chunks/chunk-ISLENKSH.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node +import{createRequire} from"node:module";const require=createRequire(import.meta.url); +import{a as g,b as A,c as T,d as at,e as E,g as O,h as G}from"./chunk-MLUOPG3W.js";import{a as X,c as lt}from"./chunk-MROECM42.js";import{a as yt}from"./chunk-AZH64XMJ.js";import{a as R}from"./chunk-52FZYTIX.js";import{k as B}from"./chunk-47WZ2U6M.js";function W(t,r,e,n,c,o,u,p,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,a)=>{let y=c(h,e[0],n)[0],l=c(a,e[0],n)[0];return u(y,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:c(t,e[0],n).map(h=>{let a=0,y=t.length;for(;a>>1;u(t[l],h)<0?a=l+1:y=l}return au(a.key,y.key)),[h.map(a=>a.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let h of t){let a=JSON.stringify(c(h,e[0],n)[0]);i.has(a)||i.set(a,[]),i.get(a)?.push(h)}return[[...i.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)>0?i:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=c(i,e[0],n)[0],y=c(h,e[0],n)[0];return u(a,y)>0?i:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)<0?i:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=c(i,e[0],n)[0],y=c(h,e[0],n)[0];return u(a,y)<0?i:h})];case"add":{let i=h=>{let a=h.filter(y=>y!==null);return a.length===0?null:a.every(y=>typeof y=="number")?a.reduce((y,l)=>y+l,0):a.every(y=>typeof y=="string")?a.join(""):a.every(y=>Array.isArray(y))?a.flat():a.every(y=>y&&typeof y=="object"&&!Array.isArray(y))?lt(...a):null};if(e.length>=1){let h=c(t,e[0],n);return[i(h)]}return Array.isArray(t)?[i(t)]:[null]}case"any":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(c(h,e[1],n).some(p))return[!0]}catch(i){if(i instanceof f)throw i}return[!1]}return e.length===1?Array.isArray(t)?[t.some(i=>p(c(i,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(p)]:[!1]}case"all":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(!c(h,e[1],n).some(p))return[!1]}catch(i){if(i instanceof f)throw i}return[!0]}return e.length===1?Array.isArray(t)?[t.every(i=>p(c(i,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(p)]:[!0]}case"select":return e.length===0?[t]:c(t,e[0],n).some(p)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>c(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(i=>c(i,e[0],n))];if(t&&typeof t=="object"){let i=Object.create(null);for(let[h,a]of Object.entries(t)){if(!g(h))continue;let y=c(a,e[0],n);y.length>0&&A(i,h,y[0])}return[i]}return[null]}case"has":{if(e.length===0)return[!1];let h=c(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h=0&&t0)try{let s=o(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof p)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=c(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=c(t,e[0],n);if(e.length>1){for(let i of s)if(i<0)throw new Error("nth doesn't support negative indices");let f;try{f=o(t,e[1],n)}catch(i){if(i instanceof p)throw i;f=[]}return s.flatMap(i=>{let h=i;return h{let i=f;if(i<0)throw new Error("nth doesn't support negative indices");return il.length>=s,i=c(t,e[0],n);if(e.length===1){let l=[];for(let m of i){let b=m;for(let w=0;w0){for(let C=w;Ck;C+=N)if(y.push(C),f(y))return y}}return y}case"limit":return e.length<2?[]:c(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("limit doesn't support negative count");if(i===0)return[];let h;try{h=o(t,e[1],n)}catch(a){if(a instanceof p)throw a;h=[]}return h.slice(0,i)});case"isempty":{if(e.length<1)return[!0];try{return[o(t,e[0],n).length===0]}catch(s){if(s instanceof p)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[c(t,e[0],n).length>0]}catch(s){if(s instanceof p)throw s;return[!1]}}case"skip":return e.length<2?[]:c(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("skip doesn't support negative count");return c(t,e[1],n).slice(i)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let i=0;i=i)throw new p(`jq while: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,i=n.limits.maxIterations;for(let h=0;h=i)throw new p(`jq repeat: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function Z(t,r,e,n,c){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let o=new Date(t*1e3),u=o.getUTCFullYear(),p=o.getUTCMonth(),s=o.getUTCDate(),f=o.getUTCHours(),i=o.getUTCMinutes(),h=o.getUTCSeconds(),a=o.getUTCDay(),y=Date.UTC(u,0,1),l=Math.floor((o.getTime()-y)/(1440*60*1e3));return[[u,p,s,f,i,h,a,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[o,u,p,s=0,f=0,i=0]=t;if(typeof o!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(o,u,p??1,s??0,f??0,i??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=c(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let p;if(typeof t=="number")p=new Date(t*1e3);else if(Array.isArray(t)){let[a,y,l,m=0,b=0,w=0]=t;if(typeof a!="number"||typeof y!="number")throw new Error("strftime/1 requires parsed datetime inputs");p=new Date(Date.UTC(a,y,l??1,m??0,b??0,w??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],i=(a,y=2)=>String(a).padStart(y,"0");return[u.replace(/%Y/g,String(p.getUTCFullYear())).replace(/%m/g,i(p.getUTCMonth()+1)).replace(/%d/g,i(p.getUTCDate())).replace(/%H/g,i(p.getUTCHours())).replace(/%M/g,i(p.getUTCMinutes())).replace(/%S/g,i(p.getUTCSeconds())).replace(/%A/g,s[p.getUTCDay()]).replace(/%B/g,f[p.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=c(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,i,h,a,y,l]=s.map(Number),m=new Date(Date.UTC(f,i-1,h,a,y,l)),b=m.getUTCDay(),w=Date.UTC(f,0,1),k=Math.floor((m.getTime()-w)/(1440*60*1e3));return[[f,i-1,h,a,y,l,b,k]]}}let p=new Date(t);if(!Number.isNaN(p.getTime())){let s=p.getUTCFullYear(),f=p.getUTCMonth(),i=p.getUTCDate(),h=p.getUTCHours(),a=p.getUTCMinutes(),y=p.getUTCSeconds(),l=p.getUTCDay(),m=Date.UTC(s,0,1),b=Math.floor((p.getTime()-m)/(1440*60*1e3));return[[s,f,i,h,a,y,l,b]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let o=new Date(t);if(Number.isNaN(o.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(o.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function S(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function U(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function v(t,r){let e=O(t);for(let n of Object.keys(r)){if(!g(n))continue;let c=T(e,n)?E(e[n]):null,o=E(r[n]);c&&o?A(e,n,v(c,o)):A(e,n,r[n])}return e}function D(t,r=3e3){let e=0,n=t;for(;ep===null?0:typeof p=="boolean"?1:typeof p=="number"?2:typeof p=="string"?3:Array.isArray(p)?4:typeof p=="object"?5:6,n=e(t),c=e(r);if(n!==c)return n-c;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let p=0;pt.some(o=>F(o,c)));let e=E(t),n=E(r);return e&&n?Object.keys(n).every(c=>T(e,c)&&F(e[c],n[c])):!1}var Ot=2e3;function tt(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(c=>{if(c===null)return"";if(typeof c=="boolean")return c?"true":"false";if(typeof c=="number")return String(c);let o=String(c);return o.includes(",")||o.includes('"')||o.includes(` +`)||o.includes("\r")?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??Ot;return D(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function et(t,r,e,n,c,o){switch(r){case"index":return e.length===0?[null]:c(t,e[0],n).map(p=>{if(typeof t=="string"&&typeof p=="string"){if(p===""&&t==="")return null;let s=t.indexOf(p);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(p)){for(let f=0;f<=t.length-p.length;f++){let i=!0;for(let h=0;ho(f,p));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:c(t,e[0],n).map(p=>{if(typeof t=="string"&&typeof p=="string"){let s=t.lastIndexOf(p);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(p)){for(let s=t.length-p.length;s>=0;s--){let f=!0;for(let i=0;i=0;s--)if(o(t[s],p))return s;return null}return null});case"indices":return e.length===0?[[]]:c(t,e[0],n).map(p=>{let s=[];if(typeof t=="string"&&typeof p=="string"){let f=t.indexOf(p);for(;f!==-1;)s.push(f),f=t.indexOf(p,f+1)}else if(Array.isArray(t))if(Array.isArray(p)){let f=p.length;if(f===0)for(let i=0;i<=t.length;i++)s.push(i);else for(let i=0;i<=t.length-f;i++){let h=!0;for(let a=0;a{if(y.push(m),Array.isArray(m))for(let b of m)l(b);else if(m&&typeof m=="object")for(let b of Object.keys(m))l(m[b])};return l(t),y}let s=[],f=e.length>=2?e[1]:null,i=1e4,h=0,a=y=>{if(h++>i||f&&!c(y,f,n).some(o))return;s.push(y);let l=c(y,e[0],n);for(let m of l)m!=null&&a(m)};return a(t),s}case"recurse_down":return p(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=i=>{if(i&&typeof i=="object"){if(s.has(i))return i;s.add(i)}let h;if(Array.isArray(i))h=i.map(f);else if(i&&typeof i=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(i))g(l)&&A(y,l,f(m));h=y}else h=i;return c(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(i=>Array.isArray(i)?i.length:0)),f=[];for(let i=0;iArray.isArray(h)?h[i]:null));return[f]}case"combinations":{if(e.length>0){let h=c(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let a=[],y=(l,m)=>{if(m===h){a.push([...l]);return}for(let b of t)l.push(b),y(l,m+1),l.pop()};return y([],0),a}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let i of t)if(!Array.isArray(i))return[];let s=[],f=(i,h)=>{if(i===t.length){s.push([...h]);return}let a=t[i];for(let y of a)h.push(y),f(i+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?c(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let i=s.slice(0,s.length-f);return[u(n.root,i)]}else{let i=-f-1;if(i>=s.length)return[t];let h=s.slice(0,i);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let i=s.length-1;i>=0;i--)f.push(u(n.root,s.slice(0,i)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var Nt=2e3;function st(t,r,e,n,c){switch(r){case"keys":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) only strings have UTF-8 byte length`)}case"to_entries":{let o=E(t);return o?[Object.entries(o).map(([u,p])=>({key:u,value:p}))]:[null]}case"from_entries":if(Array.isArray(t)){let o=Object.create(null);for(let u of t){let p=E(u);if(p){let s=p.key??p.Key??p.name??p.Name??p.k,f=p.value??p.Value??p.v;if(s!==void 0){let i=String(s);g(i)&&A(o,i,f)}}}return[o]}return[null];case"with_entries":{if(e.length===0)return[t];let o=E(t);if(o){let p=Object.entries(o).map(([f,i])=>({key:f,value:i})).flatMap(f=>c(f,e[0],n)),s=Object.create(null);for(let f of p){let i=E(f);if(i){let h=i.key??i.name??i.k,a=i.value??i.v;if(h!==void 0){let y=String(h);g(y)&&A(s,y,a)}}}return[s]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?c(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let p=u;if(p<0)throw new Error("flatten depth must not be negative");return t.flat(p)}):[null];case"unique":if(Array.isArray(t)){let o=new Set,u=[];for(let p of t){let s=JSON.stringify(p);o.has(s)||(o.add(s),u.push(p))}return[u]}return[null];case"tojson":case"tojsonstream":{let o=n.limits.maxDepth??Nt;return D(t,o+1)>o?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let o=t.trim().toLowerCase();if(o==="nan")return[Number.NaN];if(o==="inf"||o==="infinity")return[Number.POSITIVE_INFINITY];if(o==="-inf"||o==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[at(JSON.parse(t))]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let o=Number(t);if(Number.isNaN(o))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[o]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) cannot be parsed as a boolean`)}case"tostream":{let o=[],u=(p,s)=>{if(p===null||typeof p!="object")o.push([s,p]);else if(Array.isArray(p))if(p.length===0)o.push([s,[]]);else for(let f=0;fo&&u.push([f.slice(o)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],i=s[1];f.length>o&&u.push([f.slice(o),i])}}return u}default:return null}}function it(t,r,e,n,c,o,u,p,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let i=c(t,e[0],n),h=[];for(let a of i){let y=a,l=t;for(let m of y){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof m=="string"){let b=E(l);if(!b||!Object.hasOwn(b,m)){l=null;break}l=b[m]}else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=c(t,e[0],n)[0],y=c(t,e[1],n)[0];return[u(t,h,y)]}case"delpaths":{if(e.length===0)return[t];let h=c(t,e[0],n)[0],a=t;for(let y of h.sort((l,m)=>m.length-l.length))a=p(a,y);return[a]}case"path":{if(e.length===0)return[[]];let i=[];return f(t,e[0],n,[],i),i}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let i=[];for(let a of e)f(t,a,n,[],i);let h=null;for(let a of i){for(let l of a)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let y=t;for(let l of a){if(y==null)break;if(Array.isArray(y)&&typeof l=="number")y=y[l];else if(typeof l=="string"){let m=E(y);if(!m||!Object.hasOwn(m,l)){y=null;break}y=m[l]}else{y=null;break}}h=u(h,a,y)}return[h]}case"paths":{let i=[],h=(a,y)=>{if(a&&typeof a=="object")if(Array.isArray(a))for(let l=0;l0?i.filter(a=>{let y=t;for(let m of a)if(Array.isArray(y)&&typeof m=="number")y=y[m];else if(typeof m=="string"){let b=E(y);if(!b||!Object.hasOwn(b,m))return!1;y=b[m]}else return!1;return c(y,e[0],n).some(o)}):i}case"leaf_paths":{let i=[],h=(a,y)=>{if(a===null||typeof a!="object")i.push(y);else if(Array.isArray(a))for(let l=0;lJSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[Object.create(null)];if(e.length===1){let s=c(t,e[0],n),f=Object.create(null);for(let i of s){let h=String(i);g(h)&&A(f,h,i)}return[f]}if(e.length===2){let s=c(t,e[0],n),f=Object.create(null);for(let i of s){let h=c(i,e[1],n);if(h.length>0){let a=String(h[0]);g(a)&&A(f,a,i)}}return[f]}let u=c(t,e[0],n),p=Object.create(null);for(let s of u){let f=c(s,e[1],n),i=c(s,e[2],n);if(f.length>0&&i.length>0){let h=String(f[0]);g(h)&&A(p,h,i[0])}}return[p]}case"JOIN":{if(e.length<2)return[null];let u=E(c(t,e[0],n)[0]);if(!u)return[null];if(!Array.isArray(t))return[null];let p=[];for(let s of t){let f=c(s,e[1],n),i=f.length>0?String(f[0]):"",h=T(u,i)?u[i]:null;p.push([s,h])}return[p]}default:return null}}function ft(t,r,e,n,c){switch(r){case"join":{if(!Array.isArray(t))return[null];let o=e.length>0?c(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return o.map(u=>t.map(p=>p===null?"":typeof p=="string"?p:String(p)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"g";return R(u,p.includes("g")?p:`${p}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"";return[...R(u,p.includes("g")?p:`${p}g`).matchAll(t)].map(i=>i.length>1?i.slice(1):i[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"";return[R(u,p).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"",f=R(u,`${p}d`).exec(t);if(!f)return[];let i=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,a)=>({offset:i?.[a+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let o=c(t,e[0],n),u=String(o[0]);try{let p=e.length>1?String(c(t,e[1],n)[0]):"",f=R(u,p).match(t);return!f||!f.groups?[Object.create(null)]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let o=c(t,e[0],n),u=c(t,e[1],n),p=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(c(t,e[2],n)[0]):"";return[R(p,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let o=c(t,e[0],n),u=c(t,e[1],n),p=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(c(t,e[2],n)[0]):"g",i=f.includes("g")?f:`${f}g`;return[R(p,i).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,o=>String.fromCharCode(o.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,o=>String.fromCharCode(o.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let o=c(t,e[0],n),u=String(o[0]);if(u==="")return[t];let p=t;return p.startsWith(u)&&(p=p.slice(u.length)),p.endsWith(u)&&(p=p.slice(0,-u.length)),[p]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n);return[t.startsWith(String(o[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let o=c(t,e[0],n);return[t.endsWith(String(o[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(o=>o.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(p=>{if(typeof p=="string")throw new Error(`string (${JSON.stringify(p)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof p!="number"||Number.isNaN(p))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(p);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function ct(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function K(t,r,e){if(r.length===0)return e;let[n,...c]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let f=Array.isArray(t)?[...t]:[];for(;f.length<=n;)f.push(null);return f[n]=K(f[n],c,e),f}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!g(n))return t??Object.create(null);let o=E(t),u=o?O(o):Object.create(null),p=Object.hasOwn(u,n)?u[n]:void 0;return A(u,n,K(p,c,e)),u}function V(t,r){if(r.length===0)return null;if(r.length===1){let c=r[0];if(Array.isArray(t)&&typeof c=="number"){let o=[...t];return o.splice(c,1),o}if(t&&typeof t=="object"&&!Array.isArray(t)){let o=String(c);if(!g(o))return t;let u=O(t);return delete u[o],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let c=[...t];return c[e]=V(c[e],n),c}if(t&&typeof t=="object"&&!Array.isArray(t)){let c=String(e);if(!g(c))return t;let o=O(t);return Object.hasOwn(o,c)&&A(o,c,V(o[c],n)),o}return t}var P=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},H=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},St=1e4,bt=2e3,Ct=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function Tt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??St,maxDepth:t?.limits?.maxDepth??bt},env:t?.env,coverage:t?.coverage,requireDefenseContext:t?.requireDefenseContext,defenseContextChecked:!1}}function q(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,requireDefenseContext:t.requireDefenseContext,defenseContextChecked:t.defenseContextChecked,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels,coverage:t.coverage}}function L(t,r,e){switch(r.type){case"var":return q(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let c=0;c0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=pt(t,r.left);return e===null?null:pt(e,r.right)}return r.type==="Identity"?t:null}function mt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(c){if(c instanceof B)throw c;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(c){if(c instanceof B)throw c;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Tt(e);switch(n.defenseContextChecked||(yt(n.requireDefenseContext,"query-engine","evaluation"),n={...n,defenseContextChecked:!0}),n.root===void 0&&(n={...n,root:t,currentPath:[]}),n.coverage?.hit(`jq:node:${r.type}`),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(o=>{let u=E(o);if(u){if(!Object.hasOwn(u,r.name))return[null];let s=u[r.name];return[s===void 0?null:s]}if(o===null)return[null];let p=Array.isArray(o)?"array":typeof o;throw new Error(`Cannot index ${p} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(o=>d(o,r.index,n).flatMap(p=>{if(typeof p=="number"&&Array.isArray(o)){if(Number.isNaN(p))return[null];let s=Math.trunc(p),f=s<0?o.length+s:s;return f>=0&&f{if(o===null)return[null];if(!Array.isArray(o)&&typeof o!="string")throw new Error(`Cannot slice ${typeof o} (${JSON.stringify(o)})`);let u=o.length,p=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return p.flatMap(f=>s.map(i=>{let h=f,a=i,y=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(a)?u:Number.isInteger(a)?a:Math.ceil(a),m=dt(y,u),b=dt(l,u);return Array.isArray(o),o.slice(m,b)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(o=>Array.isArray(o)?o:o&&typeof o=="object"?Object.values(o):[]);case"Pipe":{let c=d(t,r.left,n),o=M(r.left),u=[];for(let p of c)try{if(o!==null){let s={...n,currentPath:[...n.currentPath??[],...o]};u.push(...d(p,r.right,s))}else u.push(...d(p,r.right,n))}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Comma":{let c=d(t,r.left,n),o=d(t,r.right,n);return[...c,...o]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let c=[Object.create(null)];for(let o of r.entries){let u=typeof o.key=="string"?[o.key]:d(t,o.key,n),p=d(t,o.value,n),s=[];for(let f of c)for(let i of u){if(typeof i!="string"){let h=i===null?"null":Array.isArray(i)?"array":typeof i;throw new Error(`Cannot use ${h} (${JSON.stringify(i)}) as object key`)}if(!g(i)){for(let h of p)s.push(O(f));continue}for(let h of p){let a=O(f);A(a,i,h),s.push(a)}}c.length=0,c.push(...s)}return c}case"Paren":return d(t,r.expr,n);case"BinaryOp":return xt(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(o=>{if(r.op==="-"){if(typeof o=="number")return-o;if(typeof o=="string"){let u=p=>p.length>5?`"${p.slice(0,3)}...`:JSON.stringify(p);throw new Error(`string (${u(o)}) cannot be negated`)}return null}return r.op==="not"?!S(o):null});case"Cond":return d(t,r.cond,n).flatMap(o=>{if(S(o))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(S))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(c){if(r.catch){let o=c instanceof H?c.value:c instanceof Error?c.message:String(c);return d(o,r.catch,n)}return[]}case"Call":return gt(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(o=>{let u=null,p=[];r.pattern?p.push(r.pattern):r.name&&p.push({type:"var",name:r.name}),r.alternatives&&p.push(...r.alternatives);for(let s of p)if(u=L(n,s,o),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?X(n.env):Object.create(null)];let c=n.vars.get(r.name);return c!==void 0?[c]:[null]}case"Recurse":{let c=[],o=new WeakSet,u=p=>{if(p&&typeof p=="object"){if(o.has(p))return;o.add(p)}if(c.push(p),Array.isArray(p))for(let s of p)u(s);else if(p&&typeof p=="object")for(let s of Object.keys(p))u(p[s])};return u(t),c}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(o=>typeof o=="string"?o:d(t,o,n).map(p=>typeof p=="string"?p:JSON.stringify(p)).join("")).join("")];case"UpdateOp":return[Mt(t,r.path,r.op,r.value,n)];case"Reduce":{let c=d(t,r.expr,n),o=d(t,r.init,n)[0],u=n.limits.maxDepth??bt;for(let p of c){let s;if(r.pattern){if(s=L(n,r.pattern,p),s===null)continue}else s=q(n,r.varName,p);if(o=d(o,r.update,s)[0],D(o,u+1)>u)return[null]}return[o]}case"Foreach":{let c=d(t,r.expr,n),o=d(t,r.init,n)[0],u=[];for(let p of c)try{let s;if(r.pattern){if(s=L(n,r.pattern,p),s===null)continue}else s=q(n,r.varName,p);if(o=d(o,r.update,s)[0],r.extract){let f=d(o,r.extract,s);u.push(...f)}else u.push(o)}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(c){if(c instanceof P&&c.label===r.name)return c.partialResults;throw c}case"Break":throw new P(r.name);case"Def":{let c=new Map(n.funcs??[]),o=`${r.name}/${r.params.length}`;c.set(o,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:c};return d(t,r.body,u)}default:{let c=r;throw new Error(`Unknown AST node type: ${c.type}`)}}}function dt(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Mt(t,r,e,n,c){function o(s,f){switch(e){case"=":return f;case"|=":return d(s,n,c)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?G(s,f):f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,i){switch(f.type){case"Identity":return i(s);case"Field":{if(!g(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a=O(h),y=Object.hasOwn(a,f.name)?a[f.name]:void 0;return A(a,f.name,i(y)),a}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h=O(s),a=Object.hasOwn(h,f.name)?h[f.name]:void 0;return A(h,f.name,i(a)),h}return s}case"Index":{let a=d(t,f.index,c)[0];if(typeof a=="number"&&Number.isNaN(a))throw new Error("Cannot set array element at NaN index");if(typeof a=="number"&&!Number.isInteger(a)&&(a=Math.trunc(a)),f.base)return u(s,f.base,y=>{if(typeof a=="number"&&Array.isArray(y)){let l=[...y],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(typeof a=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(a))return y;let l=O(y),m=Object.hasOwn(l,a)?l[a]:void 0;return A(l,a,i(m)),l}return y});if(typeof a=="number"){if(a>536870911)throw new Error("Array index too large");if(a<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(s==null){let l=[];for(;l.length<=a;)l.push(null);return l[a]=i(null),l}return s}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!g(a))return s;let y=O(s),l=Object.hasOwn(y,a)?y[a]:void 0;return A(y,a,i(l)),y}return s}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(y=>i(y));if(a&&typeof a=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(a))g(l)&&A(y,l,i(m));return y}return a};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,a=>a);return u(h,f.right,i)}default:return i(s)}}return u(t,r,s=>{if(e==="|=")return o(s,s);let f=d(t,n,c);return o(s,f[0]??null)})}function jt(t,r,e){function n(o,u,p){switch(u.type){case"Identity":return p;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0],f=n(s,{type:"Field",name:u.name},p);return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){let s=O(o);return A(s,u.name,p),s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0],h=n(i,{type:"Index",index:u.index},p);return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h=0&&h=0&&NS(s)?d(t,n,c).map(i=>S(i)):[!1]);if(r==="or")return d(t,e,c).flatMap(s=>S(s)?[!0]:d(t,n,c).map(i=>S(i)));if(r==="//"){let s=d(t,e,c).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,c)}let o=d(t,e,c),u=d(t,n,c);return o.flatMap(p=>u.map(s=>{switch(r){case"+":return p===null?s:s===null?p:typeof p=="number"&&typeof s=="number"||typeof p=="string"&&typeof s=="string"?p+s:Array.isArray(p)&&Array.isArray(s)?[...p,...s]:p&&s&&typeof p=="object"&&typeof s=="object"&&!Array.isArray(p)&&!Array.isArray(s)?G(p,s):null;case"-":if(typeof p=="number"&&typeof s=="number")return p-s;if(Array.isArray(p)&&Array.isArray(s)){let f=new Set(s.map(i=>JSON.stringify(i)));return p.filter(i=>!f.has(JSON.stringify(i)))}if(typeof p=="string"&&typeof s=="string"){let f=i=>i.length>10?`"${i.slice(0,10)}...`:JSON.stringify(i);throw new Error(`string (${f(p)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":if(typeof p=="number"&&typeof s=="number")return p*s;if(typeof p=="string"&&typeof s=="number")return p.repeat(s);{let f=E(p),i=E(s);if(f&&i)return v(f,i)}return null;case"/":if(typeof p=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${p}) and number (${s}) cannot be divided because the divisor is zero`);return p/s}return typeof p=="string"&&typeof s=="string"?p.split(s):null;case"%":if(typeof p=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${p}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(p)&&!Number.isNaN(p)?!Number.isFinite(s)&&!Number.isNaN(s)&&p<0&&s>0?-1:0:p%s}return null;case"==":return I(p,s);case"!=":return!I(p,s);case"<":return U(p,s)<0;case"<=":return U(p,s)<=0;case">":return U(p,s)>0;case">=":return U(p,s)>=0;default:return null}}))}function gt(t,r,e,n){let c=Ct.get(r);if(c)return typeof t=="number"?[c(t)]:[null];let o=rt(t,r,e,n,d);if(o!==null)return o;let u=ft(t,r,e,n,d);if(u!==null)return u;let p=Z(t,r,e,n,d);if(p!==null)return p;let s=tt(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ct(t,r);if(f!==null)return f;let i=st(t,r,e,n,d);if(i!==null)return i;let h=W(t,r,e,n,d,mt,$,S,F,B);if(h!==null)return h;let a=it(t,r,e,n,d,S,K,V,jt,J);if(a!==null)return a;let y=et(t,r,e,n,d,I);if(y!==null)return y;let l=z(t,r,e,n,d,mt,S,B);if(l!==null)return l;let m=nt(t,r,e,n,d,S,Rt,gt);if(m!==null)return m;let b=ot(t,r,e,n,d,I);if(b!==null)return b;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let w=e.length>0?d(t,e[0],n)[0]:t;throw new H(w)}case"env":return[n.env?X(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let w=`${r}/${e.length}`,k=n.funcs?.get(w);if(k){let N=k.closure??n.funcs??new Map,C=new Map(N);C.set(w,k);for(let _=0;_=0;Q--)x={type:"Comma",left:{type:"Literal",value:j[Q]},right:x}}C.set(`${kt}/0`,{params:[],body:x})}}let wt={...n,funcs:C};return d(t,k.body,wt)}throw new Error(`Unknown function: ${r}`)}}}function J(t,r,e,n,c){if(r.type==="Comma"){let p=r;J(t,p.left,e,n,c),J(t,p.right,e,n,c);return}let o=M(r);if(o!==null){c.push([...n,...o]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let p=0;p{if(c.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let i=0;i0&&c.push(n)}var At=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]),Y=new Set(At.values());function Et(t){let r=[],e=0,n=(f=0)=>t[e+f],c=()=>t[e++],o=()=>e>=t.length,u=f=>f>="0"&&f<="9",p=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>p(f)||u(f);for(;!o();){let f=e,i=c();if(!(i===" "||i===" "||i===` +`||i==="\r")){if(i==="#"){for(;!o()&&n()!==` +`;)c();continue}if(i==="."&&n()==="."){c(),r.push({type:"DOTDOT",pos:f});continue}if(i==="="&&n()==="="){c(),r.push({type:"EQ",pos:f});continue}if(i==="!"&&n()==="="){c(),r.push({type:"NE",pos:f});continue}if(i==="<"&&n()==="="){c(),r.push({type:"LE",pos:f});continue}if(i===">"&&n()==="="){c(),r.push({type:"GE",pos:f});continue}if(i==="/"&&n()==="/"){c(),n()==="="?(c(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(i==="+"&&n()==="="){c(),r.push({type:"UPDATE_ADD",pos:f});continue}if(i==="-"&&n()==="="){c(),r.push({type:"UPDATE_SUB",pos:f});continue}if(i==="*"&&n()==="="){c(),r.push({type:"UPDATE_MUL",pos:f});continue}if(i==="/"&&n()==="="){c(),r.push({type:"UPDATE_DIV",pos:f});continue}if(i==="%"&&n()==="="){c(),r.push({type:"UPDATE_MOD",pos:f});continue}if(i==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(i==="."){r.push({type:"DOT",pos:f});continue}if(i==="|"){n()==="="?(c(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(i===","){r.push({type:"COMMA",pos:f});continue}if(i===":"){r.push({type:"COLON",pos:f});continue}if(i===";"){r.push({type:"SEMICOLON",pos:f});continue}if(i==="("){r.push({type:"LPAREN",pos:f});continue}if(i===")"){r.push({type:"RPAREN",pos:f});continue}if(i==="["){r.push({type:"LBRACKET",pos:f});continue}if(i==="]"){r.push({type:"RBRACKET",pos:f});continue}if(i==="{"){r.push({type:"LBRACE",pos:f});continue}if(i==="}"){r.push({type:"RBRACE",pos:f});continue}if(i==="?"){r.push({type:"QUESTION",pos:f});continue}if(i==="+"){r.push({type:"PLUS",pos:f});continue}if(i==="-"){r.push({type:"MINUS",pos:f});continue}if(i==="*"){r.push({type:"STAR",pos:f});continue}if(i==="/"){r.push({type:"SLASH",pos:f});continue}if(i==="%"){r.push({type:"PERCENT",pos:f});continue}if(i==="<"){r.push({type:"LT",pos:f});continue}if(i===">"){r.push({type:"GT",pos:f});continue}if(u(i)){let h=i;for(;!o()&&(u(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[e+1]==="+"||t[e+1]==="-")&&(h+=c()),h+=c();r.push({type:"NUMBER",value:Number(h),pos:f});continue}if(i==='"'){let h="",a=0;for(;!o();){let y=n();if(a===0&&y==='"')break;if(a===0&&y==="\\"){if(c(),o())break;let l=c();switch(l){case"n":h+=` +`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(",a=1;break;default:h+=l}continue}if(a>0){if(y==='"'){for(h+=c();!o();){let l=n();if(l==="\\"){h+=c(),o()||(h+=c());continue}if(h+=c(),l==='"')break}continue}y==="("?a++:y===")"&&a--,h+=c();continue}h+=c()}o()||c(),r.push({type:"STRING",value:h,pos:f});continue}if(p(i)||i==="$"||i==="@"){let h=i;for(;!o()&&s(n());)h+=c();let a=At.get(h);a?r.push({type:a,value:h,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${i}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ut=class t{tokens;pos=0;constructor(r){this.tokens=r}peek(r=0){return this.tokens[this.pos+r]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(r){return this.peek().type===r}match(...r){for(let e of r)if(this.check(e))return this.advance();return null}expect(r,e){if(!this.check(r))throw new Error(`${e} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}isFieldNameAfterDot(r=0){let e=this.peek(r),n=this.peek(r+1);return n.type==="STRING"?!0:n.type==="IDENT"||Y.has(n.type)?n.pos===e.pos+1:!1}isIdentLike(){let r=this.peek().type;return r==="IDENT"||Y.has(r)}consumeFieldNameAfterDot(r){let e=this.peek();return e.type==="STRING"?this.advance().value:(e.type==="IDENT"||Y.has(e.type))&&e.pos===r.pos+1?this.advance().value:null}parse(){let r=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return r}parseExpr(){return this.parsePipe()}parsePattern(){if(this.match("LBRACKET")){let n=[];if(!this.check("RBRACKET"))for(n.push(this.parsePattern());this.match("COMMA")&&!this.check("RBRACKET");)n.push(this.parsePattern());return this.expect("RBRACKET","Expected ']' after array pattern"),{type:"array",elements:n}}if(this.match("LBRACE")){let n=[];if(!this.check("RBRACE"))for(n.push(this.parsePatternField());this.match("COMMA")&&!this.check("RBRACE");)n.push(this.parsePatternField());return this.expect("RBRACE","Expected '}' after object pattern"),{type:"object",fields:n}}let r=this.expect("IDENT","Expected variable name in pattern"),e=r.value;if(!e.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);return{type:"var",name:e}}parsePatternField(){if(this.match("LPAREN")){let e=this.parseExpr();this.expect("RPAREN","Expected ')' after computed key"),this.expect("COLON","Expected ':' after computed key");let n=this.parsePattern();return{key:e,pattern:n}}let r=this.peek();if(r.type==="IDENT"||Y.has(r.type)){let e=r.value;if(e.startsWith("$")){if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e.slice(1),pattern:n,keyVar:e}}return{key:e.slice(1),pattern:{type:"var",name:e}}}if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e,pattern:n}}return{key:e,pattern:{type:"var",name:`$${e}`}}}throw new Error(`Expected field name in object pattern at position ${r.pos}`)}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let e=this.parseComma();r={type:"Pipe",left:r,right:e}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let e=this.parseVarBind();r={type:"Comma",left:r,right:e}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let e=this.parsePattern(),n=[];for(;this.check("QUESTION")&&this.peekAhead(1)?.type==="ALT";)this.advance(),this.advance(),n.push(this.parsePattern());this.expect("PIPE","Expected '|' after variable binding");let c=this.parseExpr();return e.type==="var"&&n.length===0?{type:"VarBind",name:e.name,value:r,body:c}:{type:"VarBind",name:e.type==="var"?e.name:"",value:r,body:c,pattern:e.type!=="var"?e:void 0,alternatives:n.length>0?n:void 0}}return r}peekAhead(r){let e=this.pos+r;return e"],["GE",">="]]),n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let c=e.get(n.type);if(c){let o=this.parseAddSub();r={type:"BinaryOp",op:c,left:r,right:o}}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:e}}else if(this.match("MINUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:e}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let e=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:e}}else if(this.match("SLASH")){let e=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:e}}else if(this.match("PERCENT")){let e=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:e}}else break;return r}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let r=this.parsePrimary();for(;;)if(this.match("QUESTION"))r={type:"Optional",expr:r};else if(this.check("DOT")&&this.isFieldNameAfterDot())this.advance(),r={type:"Field",name:this.advance().value,base:r};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))r={type:"Iterate",base:r};else if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:e,base:r}}else{let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:e,end:n,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:e,base:r}}else break;return r}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.check("DOT")){let r=this.advance();if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let c=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:c}}let n=this.parseExpr();if(this.match("COLON")){let c=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:n,end:c}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:n}}let e=this.consumeFieldNameAfterDot(r);return e!==null?{type:"Field",name:e}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let e=this.advance().value;return e.includes("\\(")?this.parseStringInterpolation(e):{type:"Literal",value:e}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let r=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:r}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let r=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:r}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let r=this.parsePostfix(),e;return this.match("CATCH")&&(e=this.parsePostfix()),{type:"Try",body:r,catch:e}}if(this.match("REDUCE")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after reduce expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let c=this.parseExpr();this.expect("RPAREN","Expected ')' after update expression");let o=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:o,init:n,update:c,pattern:e.type!=="var"?e:void 0}}if(this.match("FOREACH")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after foreach expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let c=this.parseExpr(),o;this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions");let u=e.type==="var"?e.name:"";return{type:"Foreach",expr:r,varName:u,init:n,update:c,extract:o,pattern:e.type!=="var"?e:void 0}}if(this.match("LABEL")){let r=this.expect("IDENT","Expected label name (e.g., $out)"),e=r.value;if(!e.startsWith("$"))throw new Error(`Label name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after label name");let n=this.parseExpr();return{type:"Label",name:e,body:n}}if(this.match("BREAK")){let r=this.expect("IDENT","Expected label name to break to"),e=r.value;if(!e.startsWith("$"))throw new Error(`Break label must start with $ at position ${r.pos}`);return{type:"Break",name:e}}if(this.match("DEF")){let e=this.expect("IDENT","Expected function name after def").value,n=[];if(this.match("LPAREN")){if(!this.check("RPAREN")){let u=this.expect("IDENT","Expected parameter name");for(n.push(u.value);this.match("SEMICOLON");){let p=this.expect("IDENT","Expected parameter name");n.push(p.value)}}this.expect("RPAREN","Expected ')' after parameters")}this.expect("COLON","Expected ':' after function name");let c=this.parseExpr();this.expect("SEMICOLON","Expected ';' after function body");let o=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:c,body:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let e=this.advance().value;if(e.startsWith("$"))return{type:"VarRef",name:e};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:e,args:n}}return{type:"Call",name:e,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let e,n;if(this.match("LPAREN"))e=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.isIdentLike()){let c=this.advance().value;this.match("COLON")?(e=c,n=this.parseObjectValue()):(e=c,n={type:"Field",name:c})}else if(this.check("STRING"))e=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:e,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let e=this.parseVarBind();r={type:"Pipe",left:r,right:e}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let e=this.parseExpr(),n=[];for(;this.match("ELIF");){let o=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:o,then:u})}let c;return this.match("ELSE")&&(c=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:e,elifs:n,else:c}}parseStringInterpolation(r){let e=[],n="",c=0;for(;c0;){let f=r[c];if(f==='"'){for(u+=f,c++;c0&&(u+=f),c++}let p=Et(u),s=new t(p);e.push(s.parse())}else n+=r[c],c++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function Ne(t){let r=Et(t);return new ut(r).parse()}export{d as a,Ne as b}; diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-LMA4D2KK.js b/packages/just-bash/dist/bin/shell/chunks/chunk-LMA4D2KK.js deleted file mode 100644 index 0d8786f1..00000000 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-LMA4D2KK.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as g,b as A,c as T,d as at,e as E,g as O,h as G}from"./chunk-MLUOPG3W.js";import{a as X,c as lt}from"./chunk-MROECM42.js";import{a as yt}from"./chunk-AZH64XMJ.js";import{a as R}from"./chunk-52FZYTIX.js";import{k as B}from"./chunk-47WZ2U6M.js";function W(t,r,e,n,p,o,u,c,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,a)=>{let y=p(h,e[0],n)[0],l=p(a,e[0],n)[0];return u(y,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:p(t,e[0],n).map(h=>{let a=0,y=t.length;for(;a>>1;u(t[l],h)<0?a=l+1:y=l}return au(a.key,y.key)),[h.map(a=>a.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let h of t){let a=JSON.stringify(p(h,e[0],n)[0]);i.has(a)||i.set(a,[]),i.get(a)?.push(h)}return[[...i.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)>0?i:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)>0?i:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)<0?i:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)<0?i:h})];case"add":{let i=h=>{let a=h.filter(y=>y!==null);return a.length===0?null:a.every(y=>typeof y=="number")?a.reduce((y,l)=>y+l,0):a.every(y=>typeof y=="string")?a.join(""):a.every(y=>Array.isArray(y))?a.flat():a.every(y=>y&&typeof y=="object"&&!Array.isArray(y))?lt(...a):null};if(e.length>=1){let h=p(t,e[0],n);return[i(h)]}return Array.isArray(t)?[i(t)]:[null]}case"any":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(p(h,e[1],n).some(c))return[!0]}catch(i){if(i instanceof f)throw i}return[!1]}return e.length===1?Array.isArray(t)?[t.some(i=>c(p(i,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(c)]:[!1]}case"all":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(!p(h,e[1],n).some(c))return[!1]}catch(i){if(i instanceof f)throw i}return[!0]}return e.length===1?Array.isArray(t)?[t.every(i=>c(p(i,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(c)]:[!0]}case"select":return e.length===0?[t]:p(t,e[0],n).some(c)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>p(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(i=>p(i,e[0],n))];if(t&&typeof t=="object"){let i=Object.create(null);for(let[h,a]of Object.entries(t)){if(!g(h))continue;let y=p(a,e[0],n);y.length>0&&A(i,h,y[0])}return[i]}return[null]}case"has":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h=0&&t0)try{let s=o(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof c)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=p(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=p(t,e[0],n);if(e.length>1){for(let i of s)if(i<0)throw new Error("nth doesn't support negative indices");let f;try{f=o(t,e[1],n)}catch(i){if(i instanceof c)throw i;f=[]}return s.flatMap(i=>{let h=i;return h{let i=f;if(i<0)throw new Error("nth doesn't support negative indices");return il.length>=s,i=p(t,e[0],n);if(e.length===1){let l=[];for(let m of i){let b=m;for(let w=0;w0){for(let C=w;Ck;C+=N)if(y.push(C),f(y))return y}}return y}case"limit":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("limit doesn't support negative count");if(i===0)return[];let h;try{h=o(t,e[1],n)}catch(a){if(a instanceof c)throw a;h=[]}return h.slice(0,i)});case"isempty":{if(e.length<1)return[!0];try{return[o(t,e[0],n).length===0]}catch(s){if(s instanceof c)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[p(t,e[0],n).length>0]}catch(s){if(s instanceof c)throw s;return[!1]}}case"skip":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("skip doesn't support negative count");return p(t,e[1],n).slice(i)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let i=0;i=i)throw new c(`jq while: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,i=n.limits.maxIterations;for(let h=0;h=i)throw new c(`jq repeat: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function Z(t,r,e,n,p){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let o=new Date(t*1e3),u=o.getUTCFullYear(),c=o.getUTCMonth(),s=o.getUTCDate(),f=o.getUTCHours(),i=o.getUTCMinutes(),h=o.getUTCSeconds(),a=o.getUTCDay(),y=Date.UTC(u,0,1),l=Math.floor((o.getTime()-y)/(1440*60*1e3));return[[u,c,s,f,i,h,a,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[o,u,c,s=0,f=0,i=0]=t;if(typeof o!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(o,u,c??1,s??0,f??0,i??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let c;if(typeof t=="number")c=new Date(t*1e3);else if(Array.isArray(t)){let[a,y,l,m=0,b=0,w=0]=t;if(typeof a!="number"||typeof y!="number")throw new Error("strftime/1 requires parsed datetime inputs");c=new Date(Date.UTC(a,y,l??1,m??0,b??0,w??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],i=(a,y=2)=>String(a).padStart(y,"0");return[u.replace(/%Y/g,String(c.getUTCFullYear())).replace(/%m/g,i(c.getUTCMonth()+1)).replace(/%d/g,i(c.getUTCDate())).replace(/%H/g,i(c.getUTCHours())).replace(/%M/g,i(c.getUTCMinutes())).replace(/%S/g,i(c.getUTCSeconds())).replace(/%A/g,s[c.getUTCDay()]).replace(/%B/g,f[c.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,i,h,a,y,l]=s.map(Number),m=new Date(Date.UTC(f,i-1,h,a,y,l)),b=m.getUTCDay(),w=Date.UTC(f,0,1),k=Math.floor((m.getTime()-w)/(1440*60*1e3));return[[f,i-1,h,a,y,l,b,k]]}}let c=new Date(t);if(!Number.isNaN(c.getTime())){let s=c.getUTCFullYear(),f=c.getUTCMonth(),i=c.getUTCDate(),h=c.getUTCHours(),a=c.getUTCMinutes(),y=c.getUTCSeconds(),l=c.getUTCDay(),m=Date.UTC(s,0,1),b=Math.floor((c.getTime()-m)/(1440*60*1e3));return[[s,f,i,h,a,y,l,b]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let o=new Date(t);if(Number.isNaN(o.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(o.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function S(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function U(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function v(t,r){let e=O(t);for(let n of Object.keys(r)){if(!g(n))continue;let p=T(e,n)?E(e[n]):null,o=E(r[n]);p&&o?A(e,n,v(p,o)):A(e,n,r[n])}return e}function D(t,r=3e3){let e=0,n=t;for(;ec===null?0:typeof c=="boolean"?1:typeof c=="number"?2:typeof c=="string"?3:Array.isArray(c)?4:typeof c=="object"?5:6,n=e(t),p=e(r);if(n!==p)return n-p;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let c=0;ct.some(o=>F(o,p)));let e=E(t),n=E(r);return e&&n?Object.keys(n).every(p=>T(e,p)&&F(e[p],n[p])):!1}var Ot=2e3;function tt(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(p=>{if(p===null)return"";if(typeof p=="boolean")return p?"true":"false";if(typeof p=="number")return String(p);let o=String(p);return o.includes(",")||o.includes('"')||o.includes(` -`)||o.includes("\r")?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??Ot;return D(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function et(t,r,e,n,p,o){switch(r){case"index":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){if(c===""&&t==="")return null;let s=t.indexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let f=0;f<=t.length-c.length;f++){let i=!0;for(let h=0;ho(f,c));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){let s=t.lastIndexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let s=t.length-c.length;s>=0;s--){let f=!0;for(let i=0;i=0;s--)if(o(t[s],c))return s;return null}return null});case"indices":return e.length===0?[[]]:p(t,e[0],n).map(c=>{let s=[];if(typeof t=="string"&&typeof c=="string"){let f=t.indexOf(c);for(;f!==-1;)s.push(f),f=t.indexOf(c,f+1)}else if(Array.isArray(t))if(Array.isArray(c)){let f=c.length;if(f===0)for(let i=0;i<=t.length;i++)s.push(i);else for(let i=0;i<=t.length-f;i++){let h=!0;for(let a=0;a{if(y.push(m),Array.isArray(m))for(let b of m)l(b);else if(m&&typeof m=="object")for(let b of Object.keys(m))l(m[b])};return l(t),y}let s=[],f=e.length>=2?e[1]:null,i=1e4,h=0,a=y=>{if(h++>i||f&&!p(y,f,n).some(o))return;s.push(y);let l=p(y,e[0],n);for(let m of l)m!=null&&a(m)};return a(t),s}case"recurse_down":return c(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=i=>{if(i&&typeof i=="object"){if(s.has(i))return i;s.add(i)}let h;if(Array.isArray(i))h=i.map(f);else if(i&&typeof i=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(i))g(l)&&A(y,l,f(m));h=y}else h=i;return p(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(i=>Array.isArray(i)?i.length:0)),f=[];for(let i=0;iArray.isArray(h)?h[i]:null));return[f]}case"combinations":{if(e.length>0){let h=p(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let a=[],y=(l,m)=>{if(m===h){a.push([...l]);return}for(let b of t)l.push(b),y(l,m+1),l.pop()};return y([],0),a}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let i of t)if(!Array.isArray(i))return[];let s=[],f=(i,h)=>{if(i===t.length){s.push([...h]);return}let a=t[i];for(let y of a)h.push(y),f(i+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?p(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let i=s.slice(0,s.length-f);return[u(n.root,i)]}else{let i=-f-1;if(i>=s.length)return[t];let h=s.slice(0,i);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let i=s.length-1;i>=0;i--)f.push(u(n.root,s.slice(0,i)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var Nt=2e3;function st(t,r,e,n,p){switch(r){case"keys":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) only strings have UTF-8 byte length`)}case"to_entries":{let o=E(t);return o?[Object.entries(o).map(([u,c])=>({key:u,value:c}))]:[null]}case"from_entries":if(Array.isArray(t)){let o=Object.create(null);for(let u of t){let c=E(u);if(c){let s=c.key??c.Key??c.name??c.Name??c.k,f=c.value??c.Value??c.v;if(s!==void 0){let i=String(s);g(i)&&A(o,i,f)}}}return[o]}return[null];case"with_entries":{if(e.length===0)return[t];let o=E(t);if(o){let c=Object.entries(o).map(([f,i])=>({key:f,value:i})).flatMap(f=>p(f,e[0],n)),s=Object.create(null);for(let f of c){let i=E(f);if(i){let h=i.key??i.name??i.k,a=i.value??i.v;if(h!==void 0){let y=String(h);g(y)&&A(s,y,a)}}}return[s]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?p(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let c=u;if(c<0)throw new Error("flatten depth must not be negative");return t.flat(c)}):[null];case"unique":if(Array.isArray(t)){let o=new Set,u=[];for(let c of t){let s=JSON.stringify(c);o.has(s)||(o.add(s),u.push(c))}return[u]}return[null];case"tojson":case"tojsonstream":{let o=n.limits.maxDepth??Nt;return D(t,o+1)>o?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let o=t.trim().toLowerCase();if(o==="nan")return[Number.NaN];if(o==="inf"||o==="infinity")return[Number.POSITIVE_INFINITY];if(o==="-inf"||o==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[at(JSON.parse(t))]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let o=Number(t);if(Number.isNaN(o))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[o]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) cannot be parsed as a boolean`)}case"tostream":{let o=[],u=(c,s)=>{if(c===null||typeof c!="object")o.push([s,c]);else if(Array.isArray(c))if(c.length===0)o.push([s,[]]);else for(let f=0;fo&&u.push([f.slice(o)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],i=s[1];f.length>o&&u.push([f.slice(o),i])}}return u}default:return null}}function it(t,r,e,n,p,o,u,c,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let i=p(t,e[0],n),h=[];for(let a of i){let y=a,l=t;for(let m of y){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof m=="string"){let b=E(l);if(!b||!Object.hasOwn(b,m)){l=null;break}l=b[m]}else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=p(t,e[0],n)[0],y=p(t,e[1],n)[0];return[u(t,h,y)]}case"delpaths":{if(e.length===0)return[t];let h=p(t,e[0],n)[0],a=t;for(let y of h.sort((l,m)=>m.length-l.length))a=c(a,y);return[a]}case"path":{if(e.length===0)return[[]];let i=[];return f(t,e[0],n,[],i),i}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let i=[];for(let a of e)f(t,a,n,[],i);let h=null;for(let a of i){for(let l of a)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let y=t;for(let l of a){if(y==null)break;if(Array.isArray(y)&&typeof l=="number")y=y[l];else if(typeof l=="string"){let m=E(y);if(!m||!Object.hasOwn(m,l)){y=null;break}y=m[l]}else{y=null;break}}h=u(h,a,y)}return[h]}case"paths":{let i=[],h=(a,y)=>{if(a&&typeof a=="object")if(Array.isArray(a))for(let l=0;l0?i.filter(a=>{let y=t;for(let m of a)if(Array.isArray(y)&&typeof m=="number")y=y[m];else if(typeof m=="string"){let b=E(y);if(!b||!Object.hasOwn(b,m))return!1;y=b[m]}else return!1;return p(y,e[0],n).some(o)}):i}case"leaf_paths":{let i=[],h=(a,y)=>{if(a===null||typeof a!="object")i.push(y);else if(Array.isArray(a))for(let l=0;lJSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[Object.create(null)];if(e.length===1){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=String(i);g(h)&&A(f,h,i)}return[f]}if(e.length===2){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=p(i,e[1],n);if(h.length>0){let a=String(h[0]);g(a)&&A(f,a,i)}}return[f]}let u=p(t,e[0],n),c=Object.create(null);for(let s of u){let f=p(s,e[1],n),i=p(s,e[2],n);if(f.length>0&&i.length>0){let h=String(f[0]);g(h)&&A(c,h,i[0])}}return[c]}case"JOIN":{if(e.length<2)return[null];let u=E(p(t,e[0],n)[0]);if(!u)return[null];if(!Array.isArray(t))return[null];let c=[];for(let s of t){let f=p(s,e[1],n),i=f.length>0?String(f[0]):"",h=T(u,i)?u[i]:null;c.push([s,h])}return[c]}default:return null}}function ft(t,r,e,n,p){switch(r){case"join":{if(!Array.isArray(t))return[null];let o=e.length>0?p(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return o.map(u=>t.map(c=>c===null?"":typeof c=="string"?c:String(c)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"g";return R(u,c.includes("g")?c:`${c}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[...R(u,c.includes("g")?c:`${c}g`).matchAll(t)].map(i=>i.length>1?i.slice(1):i[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[R(u,c).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,`${c}d`).exec(t);if(!f)return[];let i=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,a)=>({offset:i?.[a+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,c).match(t);return!f||!f.groups?[Object.create(null)]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"";return[R(c,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"g",i=f.includes("g")?f:`${f}g`;return[R(c,i).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,o=>String.fromCharCode(o.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,o=>String.fromCharCode(o.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);if(u==="")return[t];let c=t;return c.startsWith(u)&&(c=c.slice(u.length)),c.endsWith(u)&&(c=c.slice(0,-u.length)),[c]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n);return[t.startsWith(String(o[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n);return[t.endsWith(String(o[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(o=>o.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(c=>{if(typeof c=="string")throw new Error(`string (${JSON.stringify(c)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof c!="number"||Number.isNaN(c))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(c);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function ct(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function K(t,r,e){if(r.length===0)return e;let[n,...p]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let f=Array.isArray(t)?[...t]:[];for(;f.length<=n;)f.push(null);return f[n]=K(f[n],p,e),f}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!g(n))return t??Object.create(null);let o=E(t),u=o?O(o):Object.create(null),c=Object.hasOwn(u,n)?u[n]:void 0;return A(u,n,K(c,p,e)),u}function V(t,r){if(r.length===0)return null;if(r.length===1){let p=r[0];if(Array.isArray(t)&&typeof p=="number"){let o=[...t];return o.splice(p,1),o}if(t&&typeof t=="object"&&!Array.isArray(t)){let o=String(p);if(!g(o))return t;let u=O(t);return delete u[o],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let p=[...t];return p[e]=V(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!g(p))return t;let o=O(t);return Object.hasOwn(o,p)&&A(o,p,V(o[p],n)),o}return t}var P=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},H=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},St=1e4,bt=2e3,Ct=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function Tt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??St,maxDepth:t?.limits?.maxDepth??bt},env:t?.env,coverage:t?.coverage,requireDefenseContext:t?.requireDefenseContext,defenseContextChecked:!1}}function q(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,requireDefenseContext:t.requireDefenseContext,defenseContextChecked:t.defenseContextChecked,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels,coverage:t.coverage}}function L(t,r,e){switch(r.type){case"var":return q(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let p=0;p0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=pt(t,r.left);return e===null?null:pt(e,r.right)}return r.type==="Identity"?t:null}function mt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof B)throw p;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(p){if(p instanceof B)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Tt(e);switch(n.defenseContextChecked||(yt(n.requireDefenseContext,"query-engine","evaluation"),n={...n,defenseContextChecked:!0}),n.root===void 0&&(n={...n,root:t,currentPath:[]}),n.coverage?.hit(`jq:node:${r.type}`),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(o=>{let u=E(o);if(u){if(!Object.hasOwn(u,r.name))return[null];let s=u[r.name];return[s===void 0?null:s]}if(o===null)return[null];let c=Array.isArray(o)?"array":typeof o;throw new Error(`Cannot index ${c} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(o=>d(o,r.index,n).flatMap(c=>{if(typeof c=="number"&&Array.isArray(o)){if(Number.isNaN(c))return[null];let s=Math.trunc(c),f=s<0?o.length+s:s;return f>=0&&f{if(o===null)return[null];if(!Array.isArray(o)&&typeof o!="string")throw new Error(`Cannot slice ${typeof o} (${JSON.stringify(o)})`);let u=o.length,c=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return c.flatMap(f=>s.map(i=>{let h=f,a=i,y=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(a)?u:Number.isInteger(a)?a:Math.ceil(a),m=dt(y,u),b=dt(l,u);return Array.isArray(o),o.slice(m,b)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(o=>Array.isArray(o)?o:o&&typeof o=="object"?Object.values(o):[]);case"Pipe":{let p=d(t,r.left,n),o=M(r.left),u=[];for(let c of p)try{if(o!==null){let s={...n,currentPath:[...n.currentPath??[],...o]};u.push(...d(c,r.right,s))}else u.push(...d(c,r.right,n))}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Comma":{let p=d(t,r.left,n),o=d(t,r.right,n);return[...p,...o]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let p=[Object.create(null)];for(let o of r.entries){let u=typeof o.key=="string"?[o.key]:d(t,o.key,n),c=d(t,o.value,n),s=[];for(let f of p)for(let i of u){if(typeof i!="string"){let h=i===null?"null":Array.isArray(i)?"array":typeof i;throw new Error(`Cannot use ${h} (${JSON.stringify(i)}) as object key`)}if(!g(i)){for(let h of c)s.push(O(f));continue}for(let h of c){let a=O(f);A(a,i,h),s.push(a)}}p.length=0,p.push(...s)}return p}case"Paren":return d(t,r.expr,n);case"BinaryOp":return xt(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(o=>{if(r.op==="-"){if(typeof o=="number")return-o;if(typeof o=="string"){let u=c=>c.length>5?`"${c.slice(0,3)}...`:JSON.stringify(c);throw new Error(`string (${u(o)}) cannot be negated`)}return null}return r.op==="not"?!S(o):null});case"Cond":return d(t,r.cond,n).flatMap(o=>{if(S(o))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(S))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(p){if(r.catch){let o=p instanceof H?p.value:p instanceof Error?p.message:String(p);return d(o,r.catch,n)}return[]}case"Call":return gt(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(o=>{let u=null,c=[];r.pattern?c.push(r.pattern):r.name&&c.push({type:"var",name:r.name}),r.alternatives&&c.push(...r.alternatives);for(let s of c)if(u=L(n,s,o),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?X(n.env):Object.create(null)];let p=n.vars.get(r.name);return p!==void 0?[p]:[null]}case"Recurse":{let p=[],o=new WeakSet,u=c=>{if(c&&typeof c=="object"){if(o.has(c))return;o.add(c)}if(p.push(c),Array.isArray(c))for(let s of c)u(s);else if(c&&typeof c=="object")for(let s of Object.keys(c))u(c[s])};return u(t),p}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(o=>typeof o=="string"?o:d(t,o,n).map(c=>typeof c=="string"?c:JSON.stringify(c)).join("")).join("")];case"UpdateOp":return[Mt(t,r.path,r.op,r.value,n)];case"Reduce":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=n.limits.maxDepth??bt;for(let c of p){let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],D(o,u+1)>u)return[null]}return[o]}case"Foreach":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=[];for(let c of p)try{let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],r.extract){let f=d(o,r.extract,s);u.push(...f)}else u.push(o)}catch(s){throw s instanceof P?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(p){if(p instanceof P&&p.label===r.name)return p.partialResults;throw p}case"Break":throw new P(r.name);case"Def":{let p=new Map(n.funcs??[]),o=`${r.name}/${r.params.length}`;p.set(o,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:p};return d(t,r.body,u)}default:{let p=r;throw new Error(`Unknown AST node type: ${p.type}`)}}}function dt(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Mt(t,r,e,n,p){function o(s,f){switch(e){case"=":return f;case"|=":return d(s,n,p)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?G(s,f):f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,i){switch(f.type){case"Identity":return i(s);case"Field":{if(!g(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a=O(h),y=Object.hasOwn(a,f.name)?a[f.name]:void 0;return A(a,f.name,i(y)),a}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h=O(s),a=Object.hasOwn(h,f.name)?h[f.name]:void 0;return A(h,f.name,i(a)),h}return s}case"Index":{let a=d(t,f.index,p)[0];if(typeof a=="number"&&Number.isNaN(a))throw new Error("Cannot set array element at NaN index");if(typeof a=="number"&&!Number.isInteger(a)&&(a=Math.trunc(a)),f.base)return u(s,f.base,y=>{if(typeof a=="number"&&Array.isArray(y)){let l=[...y],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(typeof a=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(a))return y;let l=O(y),m=Object.hasOwn(l,a)?l[a]:void 0;return A(l,a,i(m)),l}return y});if(typeof a=="number"){if(a>536870911)throw new Error("Array index too large");if(a<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(s==null){let l=[];for(;l.length<=a;)l.push(null);return l[a]=i(null),l}return s}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!g(a))return s;let y=O(s),l=Object.hasOwn(y,a)?y[a]:void 0;return A(y,a,i(l)),y}return s}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(y=>i(y));if(a&&typeof a=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(a))g(l)&&A(y,l,i(m));return y}return a};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,a=>a);return u(h,f.right,i)}default:return i(s)}}return u(t,r,s=>{if(e==="|=")return o(s,s);let f=d(t,n,p);return o(s,f[0]??null)})}function jt(t,r,e){function n(o,u,c){switch(u.type){case"Identity":return c;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0],f=n(s,{type:"Field",name:u.name},c);return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){let s=O(o);return A(s,u.name,c),s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0],h=n(i,{type:"Index",index:u.index},c);return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h=0&&h=0&&NS(s)?d(t,n,p).map(i=>S(i)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>S(s)?[!0]:d(t,n,p).map(i=>S(i)));if(r==="//"){let s=d(t,e,p).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,p)}let o=d(t,e,p),u=d(t,n,p);return o.flatMap(c=>u.map(s=>{switch(r){case"+":return c===null?s:s===null?c:typeof c=="number"&&typeof s=="number"||typeof c=="string"&&typeof s=="string"?c+s:Array.isArray(c)&&Array.isArray(s)?[...c,...s]:c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?G(c,s):null;case"-":if(typeof c=="number"&&typeof s=="number")return c-s;if(Array.isArray(c)&&Array.isArray(s)){let f=new Set(s.map(i=>JSON.stringify(i)));return c.filter(i=>!f.has(JSON.stringify(i)))}if(typeof c=="string"&&typeof s=="string"){let f=i=>i.length>10?`"${i.slice(0,10)}...`:JSON.stringify(i);throw new Error(`string (${f(c)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":if(typeof c=="number"&&typeof s=="number")return c*s;if(typeof c=="string"&&typeof s=="number")return c.repeat(s);{let f=E(c),i=E(s);if(f&&i)return v(f,i)}return null;case"/":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided because the divisor is zero`);return c/s}return typeof c=="string"&&typeof s=="string"?c.split(s):null;case"%":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(c)&&!Number.isNaN(c)?!Number.isFinite(s)&&!Number.isNaN(s)&&c<0&&s>0?-1:0:c%s}return null;case"==":return I(c,s);case"!=":return!I(c,s);case"<":return U(c,s)<0;case"<=":return U(c,s)<=0;case">":return U(c,s)>0;case">=":return U(c,s)>=0;default:return null}}))}function gt(t,r,e,n){let p=Ct.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let o=rt(t,r,e,n,d);if(o!==null)return o;let u=ft(t,r,e,n,d);if(u!==null)return u;let c=Z(t,r,e,n,d);if(c!==null)return c;let s=tt(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ct(t,r);if(f!==null)return f;let i=st(t,r,e,n,d);if(i!==null)return i;let h=W(t,r,e,n,d,mt,$,S,F,B);if(h!==null)return h;let a=it(t,r,e,n,d,S,K,V,jt,J);if(a!==null)return a;let y=et(t,r,e,n,d,I);if(y!==null)return y;let l=z(t,r,e,n,d,mt,S,B);if(l!==null)return l;let m=nt(t,r,e,n,d,S,Rt,gt);if(m!==null)return m;let b=ot(t,r,e,n,d,I);if(b!==null)return b;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let w=e.length>0?d(t,e[0],n)[0]:t;throw new H(w)}case"env":return[n.env?X(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let w=`${r}/${e.length}`,k=n.funcs?.get(w);if(k){let N=k.closure??n.funcs??new Map,C=new Map(N);C.set(w,k);for(let _=0;_=0;Q--)x={type:"Comma",left:{type:"Literal",value:j[Q]},right:x}}C.set(`${kt}/0`,{params:[],body:x})}}let wt={...n,funcs:C};return d(t,k.body,wt)}throw new Error(`Unknown function: ${r}`)}}}function J(t,r,e,n,p){if(r.type==="Comma"){let c=r;J(t,c.left,e,n,p),J(t,c.right,e,n,p);return}let o=M(r);if(o!==null){p.push([...n,...o]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let c=0;c{if(p.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let i=0;i0&&p.push(n)}var At=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]),Y=new Set(At.values());function Et(t){let r=[],e=0,n=(f=0)=>t[e+f],p=()=>t[e++],o=()=>e>=t.length,u=f=>f>="0"&&f<="9",c=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>c(f)||u(f);for(;!o();){let f=e,i=p();if(!(i===" "||i===" "||i===` -`||i==="\r")){if(i==="#"){for(;!o()&&n()!==` -`;)p();continue}if(i==="."&&n()==="."){p(),r.push({type:"DOTDOT",pos:f});continue}if(i==="="&&n()==="="){p(),r.push({type:"EQ",pos:f});continue}if(i==="!"&&n()==="="){p(),r.push({type:"NE",pos:f});continue}if(i==="<"&&n()==="="){p(),r.push({type:"LE",pos:f});continue}if(i===">"&&n()==="="){p(),r.push({type:"GE",pos:f});continue}if(i==="/"&&n()==="/"){p(),n()==="="?(p(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(i==="+"&&n()==="="){p(),r.push({type:"UPDATE_ADD",pos:f});continue}if(i==="-"&&n()==="="){p(),r.push({type:"UPDATE_SUB",pos:f});continue}if(i==="*"&&n()==="="){p(),r.push({type:"UPDATE_MUL",pos:f});continue}if(i==="/"&&n()==="="){p(),r.push({type:"UPDATE_DIV",pos:f});continue}if(i==="%"&&n()==="="){p(),r.push({type:"UPDATE_MOD",pos:f});continue}if(i==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(i==="."){r.push({type:"DOT",pos:f});continue}if(i==="|"){n()==="="?(p(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(i===","){r.push({type:"COMMA",pos:f});continue}if(i===":"){r.push({type:"COLON",pos:f});continue}if(i===";"){r.push({type:"SEMICOLON",pos:f});continue}if(i==="("){r.push({type:"LPAREN",pos:f});continue}if(i===")"){r.push({type:"RPAREN",pos:f});continue}if(i==="["){r.push({type:"LBRACKET",pos:f});continue}if(i==="]"){r.push({type:"RBRACKET",pos:f});continue}if(i==="{"){r.push({type:"LBRACE",pos:f});continue}if(i==="}"){r.push({type:"RBRACE",pos:f});continue}if(i==="?"){r.push({type:"QUESTION",pos:f});continue}if(i==="+"){r.push({type:"PLUS",pos:f});continue}if(i==="-"){r.push({type:"MINUS",pos:f});continue}if(i==="*"){r.push({type:"STAR",pos:f});continue}if(i==="/"){r.push({type:"SLASH",pos:f});continue}if(i==="%"){r.push({type:"PERCENT",pos:f});continue}if(i==="<"){r.push({type:"LT",pos:f});continue}if(i===">"){r.push({type:"GT",pos:f});continue}if(u(i)){let h=i;for(;!o()&&(u(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[e+1]==="+"||t[e+1]==="-")&&(h+=p()),h+=p();r.push({type:"NUMBER",value:Number(h),pos:f});continue}if(i==='"'){let h="";for(;!o()&&n()!=='"';)if(n()==="\\"){if(p(),o())break;let a=p();switch(a){case"n":h+=` -`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(";break;default:h+=a}}else h+=p();o()||p(),r.push({type:"STRING",value:h,pos:f});continue}if(c(i)||i==="$"||i==="@"){let h=i;for(;!o()&&s(n());)h+=p();let a=At.get(h);a?r.push({type:a,value:h,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${i}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ut=class t{tokens;pos=0;constructor(r){this.tokens=r}peek(r=0){return this.tokens[this.pos+r]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(r){return this.peek().type===r}match(...r){for(let e of r)if(this.check(e))return this.advance();return null}expect(r,e){if(!this.check(r))throw new Error(`${e} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}isFieldNameAfterDot(r=0){let e=this.peek(r),n=this.peek(r+1);return n.type==="STRING"?!0:n.type==="IDENT"||Y.has(n.type)?n.pos===e.pos+1:!1}isIdentLike(){let r=this.peek().type;return r==="IDENT"||Y.has(r)}consumeFieldNameAfterDot(r){let e=this.peek();return e.type==="STRING"?this.advance().value:(e.type==="IDENT"||Y.has(e.type))&&e.pos===r.pos+1?this.advance().value:null}parse(){let r=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return r}parseExpr(){return this.parsePipe()}parsePattern(){if(this.match("LBRACKET")){let n=[];if(!this.check("RBRACKET"))for(n.push(this.parsePattern());this.match("COMMA")&&!this.check("RBRACKET");)n.push(this.parsePattern());return this.expect("RBRACKET","Expected ']' after array pattern"),{type:"array",elements:n}}if(this.match("LBRACE")){let n=[];if(!this.check("RBRACE"))for(n.push(this.parsePatternField());this.match("COMMA")&&!this.check("RBRACE");)n.push(this.parsePatternField());return this.expect("RBRACE","Expected '}' after object pattern"),{type:"object",fields:n}}let r=this.expect("IDENT","Expected variable name in pattern"),e=r.value;if(!e.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);return{type:"var",name:e}}parsePatternField(){if(this.match("LPAREN")){let e=this.parseExpr();this.expect("RPAREN","Expected ')' after computed key"),this.expect("COLON","Expected ':' after computed key");let n=this.parsePattern();return{key:e,pattern:n}}let r=this.peek();if(r.type==="IDENT"||Y.has(r.type)){let e=r.value;if(e.startsWith("$")){if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e.slice(1),pattern:n,keyVar:e}}return{key:e.slice(1),pattern:{type:"var",name:e}}}if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e,pattern:n}}return{key:e,pattern:{type:"var",name:`$${e}`}}}throw new Error(`Expected field name in object pattern at position ${r.pos}`)}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let e=this.parseComma();r={type:"Pipe",left:r,right:e}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let e=this.parseVarBind();r={type:"Comma",left:r,right:e}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let e=this.parsePattern(),n=[];for(;this.check("QUESTION")&&this.peekAhead(1)?.type==="ALT";)this.advance(),this.advance(),n.push(this.parsePattern());this.expect("PIPE","Expected '|' after variable binding");let p=this.parseExpr();return e.type==="var"&&n.length===0?{type:"VarBind",name:e.name,value:r,body:p}:{type:"VarBind",name:e.type==="var"?e.name:"",value:r,body:p,pattern:e.type!=="var"?e:void 0,alternatives:n.length>0?n:void 0}}return r}peekAhead(r){let e=this.pos+r;return e"],["GE",">="]]),n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let p=e.get(n.type);if(p){let o=this.parseAddSub();r={type:"BinaryOp",op:p,left:r,right:o}}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:e}}else if(this.match("MINUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:e}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let e=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:e}}else if(this.match("SLASH")){let e=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:e}}else if(this.match("PERCENT")){let e=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:e}}else break;return r}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let r=this.parsePrimary();for(;;)if(this.match("QUESTION"))r={type:"Optional",expr:r};else if(this.check("DOT")&&this.isFieldNameAfterDot())this.advance(),r={type:"Field",name:this.advance().value,base:r};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))r={type:"Iterate",base:r};else if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:e,base:r}}else{let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:e,end:n,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:e,base:r}}else break;return r}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.check("DOT")){let r=this.advance();if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:p}}let n=this.parseExpr();if(this.match("COLON")){let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:n,end:p}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:n}}let e=this.consumeFieldNameAfterDot(r);return e!==null?{type:"Field",name:e}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let e=this.advance().value;return e.includes("\\(")?this.parseStringInterpolation(e):{type:"Literal",value:e}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let r=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:r}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let r=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:r}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let r=this.parsePostfix(),e;return this.match("CATCH")&&(e=this.parsePostfix()),{type:"Try",body:r,catch:e}}if(this.match("REDUCE")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after reduce expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr();this.expect("RPAREN","Expected ')' after update expression");let o=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:o,init:n,update:p,pattern:e.type!=="var"?e:void 0}}if(this.match("FOREACH")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after foreach expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr(),o;this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions");let u=e.type==="var"?e.name:"";return{type:"Foreach",expr:r,varName:u,init:n,update:p,extract:o,pattern:e.type!=="var"?e:void 0}}if(this.match("LABEL")){let r=this.expect("IDENT","Expected label name (e.g., $out)"),e=r.value;if(!e.startsWith("$"))throw new Error(`Label name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after label name");let n=this.parseExpr();return{type:"Label",name:e,body:n}}if(this.match("BREAK")){let r=this.expect("IDENT","Expected label name to break to"),e=r.value;if(!e.startsWith("$"))throw new Error(`Break label must start with $ at position ${r.pos}`);return{type:"Break",name:e}}if(this.match("DEF")){let e=this.expect("IDENT","Expected function name after def").value,n=[];if(this.match("LPAREN")){if(!this.check("RPAREN")){let u=this.expect("IDENT","Expected parameter name");for(n.push(u.value);this.match("SEMICOLON");){let c=this.expect("IDENT","Expected parameter name");n.push(c.value)}}this.expect("RPAREN","Expected ')' after parameters")}this.expect("COLON","Expected ':' after function name");let p=this.parseExpr();this.expect("SEMICOLON","Expected ';' after function body");let o=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:p,body:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let e=this.advance().value;if(e.startsWith("$"))return{type:"VarRef",name:e};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:e,args:n}}return{type:"Call",name:e,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let e,n;if(this.match("LPAREN"))e=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.isIdentLike()){let p=this.advance().value;this.match("COLON")?(e=p,n=this.parseObjectValue()):(e=p,n={type:"Field",name:p})}else if(this.check("STRING"))e=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:e,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let e=this.parseVarBind();r={type:"Pipe",left:r,right:e}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let e=this.parseExpr(),n=[];for(;this.match("ELIF");){let o=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:o,then:u})}let p;return this.match("ELSE")&&(p=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:e,elifs:n,else:p}}parseStringInterpolation(r){let e=[],n="",p=0;for(;p0;)r[p]==="("?o++:r[p]===")"&&o--,o>0&&(u+=r[p]),p++;let c=Et(u),s=new t(c);e.push(s.parse())}else n+=r[p],p++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function Ne(t){let r=Et(t);return new ut(r).parse()}export{d as a,Ne as b}; diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-PDS5TEMS.js b/packages/just-bash/dist/bin/shell/chunks/chunk-PDS5TEMS.js deleted file mode 100644 index 1c9f4c65..00000000 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-PDS5TEMS.js +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as O}from"./chunk-52FZYTIX.js";import{e as J,f as Y,g as $,h as ae,i as xe,j as _t,k as W}from"./chunk-47WZ2U6M.js";function _(e,t){for(;t>=","&=","|=","^="];function be(e){if(e.includes("#")){let[r,s]=e.split("#"),n=Number.parseInt(r,10);if(n<2||n>64)return Number.NaN;if(n<=36){let i=Number.parseInt(s,n);return i>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:i}let a=0;for(let i of s){let l;if(/[0-9]/.test(i))l=i.charCodeAt(0)-48;else if(/[a-z]/.test(i))l=i.charCodeAt(0)-97+10;else if(/[A-Z]/.test(i))l=i.charCodeAt(0)-65+36;else if(i==="@")l=62;else if(i==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(a=a*n+l,a>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return a}if(e.startsWith("0x")||e.startsWith("0X")){let r=Number.parseInt(e.slice(2),16);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let r=Number.parseInt(e,8);return r>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:r}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function $t(e,t,r,s){if(r.slice(s,s+3)!=="$((")return null;let n=s+3,a=1,i=n;for(;n0;)r[n]==="("&&r[n+1]==="("?(a++,n+=2):r[n]===")"&&r[n+1]===")"?(a--,a>0&&(n+=2)):n++;let l=r.slice(i,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Ct(e,t){if(e.slice(t,t+2)!=="$'")return null;let r=t+2,s="";for(;r=e.length}function j(e,t,r){return _r(e,t,r)}function _r(e,t,r){let{expr:s,pos:n}=we(e,t,r);for(n=_(t,n);t[n]===",";){if(n++,Z(t,n))return Q(",",n);let{expr:i,pos:l}=we(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=_(t,l)}return{expr:s,pos:n}}function we(e,t,r){let{expr:s,pos:n}=$r(e,t,r);if(n=_(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=j(e,t,n);if(n=_(t,i),t[n]===":"){n++;let{expr:l,pos:o}=j(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function $r(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="||";){if(n+=2,Z(t,n))return Q("||",n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="&&";){if(n+=2,Z(t,n))return Q("&&",n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=_(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,Z(t,n))return Q("|",n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Mt(e,t,r);for(;n=_(t,n),t[n]==="^";){if(n++,Z(t,n))return Q("^",n);let{expr:i,pos:l}=Mt(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Mt(e,t,r){let{expr:s,pos:n}=Vt(e,t,r);for(;n=_(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,Z(t,n))return Q("&",n);let{expr:i,pos:l}=Vt(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Vt(e,t,r){let{expr:s,pos:n}=qt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=qt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function qt(e,t,r){let{expr:s,pos:n}=Qe(e,t,r);for(;;)if(n=_(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Qe(e,t,r){let{expr:s,pos:n}=Bt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Bt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Bt(e,t,r){let{expr:s,pos:n}=Ft(e,t,r);for(;n=_(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=Ft(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Ft(e,t,r){let{expr:s,pos:n}=_e(e,t,r);for(;;)if(n=_(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,Z(t,n))return Q("*",n);let{expr:i,pos:l}=_e(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,Z(t,n))return Q(a,n);let{expr:i,pos:l}=_e(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function _e(e,t,r){let{expr:s,pos:n}=Ze(e,t,r),a=_(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,Z(t,a))return Q("**",a);let{expr:l,pos:o}=_e(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function Ze(e,t,r){let s=_(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=Ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=Ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Or(e,t,s)}function Cr(e,t){let r=e[t];return r==="$"||r==="`"}function Or(e,t,r){let{expr:s,pos:n}=zt(e,t,r,!1),a=[s];for(;Cr(t,n);){let{expr:l,pos:o}=zt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=j(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=_(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of ve)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=we(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:u}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function zt(e,t,r,s=!1){let n=_(t,r),a=$t(j,e,t,n);if(a)return a;let i=Ct(t,n);if(i)return i;let l=Ot(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let h=t.slice(u,f),d=f+1;if(t[d]==="#"){let m=d+1;for(;m0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(oa===" "||a===" "||a===` -`||a===";"||a==="&"||a==="|"||a==="<"||a===">"||a==="("||a===")";for(;s=e.length)return e.length;let i=e.indexOf(` -`,s);i===-1&&(i=e.length);let l=e.slice(s,i);if(a&&(l=l.replace(/^\t+/,"")),l===n){s=i+1;break}if(i>=e.length)return e.length;s=i+1}return Math.min(s,e.length)}function Zt(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,u=0,c=!1,f="",h=[],d=0;for(;i0;){let A=e[i];if(l)A==="'"&&(l=!1);else if(o)A==="\\"&&i+10&&d--,d===0&&A==="<"&&e[i+1]==="<"&&e[i+2]!=="<"){let S=i+2,y=!1;for(e[S]==="-"&&(y=!0,S++);e[S]===" "||e[S]===" ";)S++;let{delim:b,endPos:x}=Ue(e,S);if(b.length>0){h.push({delim:b,stripTabs:y}),f="",i=x;continue}}if(A===` -`&&h.length>0){let S=Lr(e,i,h);h.length=0,f="",i=S;continue}A==="'"?(l=!0,f=""):A==='"'?(o=!0,f=""):A==="\\"&&i+10?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",A==="("?i>0&&e[i-1]==="$"?a++:c||a++:A===")"?c?c=!1:a--:A===";"&&u>0&&i+10&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let m=e.slice(n,i),E=r().parse(m);return{part:w.commandSubstitution(E,!1),endIndex:i+1}}function Ut(e,t,r,s,n){let i=t+1,l="";for(;i=e.length&&n("unexpected EOF while looking for matching ``'");let u=s().parse(l);return{part:w.commandSubstitution(u,!0),endIndex:i+1}}var Wr=10485760,p;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(p||(p={}));var Ee=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},Ht=new Map([["if",p.IF],["then",p.THEN],["else",p.ELSE],["elif",p.ELIF],["fi",p.FI],["for",p.FOR],["while",p.WHILE],["until",p.UNTIL],["do",p.DO],["done",p.DONE],["case",p.CASE],["esac",p.ESAC],["in",p.IN],["function",p.FUNCTION],["select",p.SELECT],["time",p.TIME],["coproc",p.COPROC]]);function jt(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let r=e.slice(t[0].length);if(r===""||r==="+")return!0;if(r[0]==="["){let s=0,n=0;for(;n=r.length)return!1;let a=r.slice(n+1);return a===""||a==="+"}return!1}function Kt(e){let t=0;for(let r=0;r",">",p.AND_DGREAT]],Mr=[["[","[",p.DBRACK_START],["]","]",p.DBRACK_END],["(","(",p.DPAREN_START],[")",")",p.DPAREN_END],["&","&",p.AND_AND],["|","|",p.OR_OR],[";",";",p.DSEMI],[";","&",p.SEMI_AND],["|","&",p.PIPE_AMP],[">",">",p.DGREAT],["<","&",p.LESSAND],[">","&",p.GREATAND],["<",">",p.LESSGREAT],[">","|",p.CLOBBER],["&",">",p.AND_GREAT]],Vr=new Map([["|",p.PIPE],["&",p.AMP],[";",p.SEMICOLON],["(",p.LPAREN],[")",p.RPAREN],["<",p.LESS],[">",p.GREAT]]);function qr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Xt(e){return e===" "||e===" "||e===` -`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var $e=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,r){this.input=t,this.maxHeredocSize=r?.maxHeredocSize??Wr}tokenize(){let r=this.input.length,s=this.tokens,n=this.pendingHeredocs;for(;this.pos0&&s.length>0&&s[s.length-1].type===p.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=r)break;let a=this.nextToken();a&&s.push(a)}return s.push({type:p.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),s}skipWhitespace(){let t=this.input,r=t.length,s=this.pos,n=this.column,a=this.line;for(;s0?(this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n)):this.looksLikeNestedSubshells(r+2)||this.dparenClosesWithSpacedParens(r+2)?(this.pos=r+1,this.column=n+1,this.makeToken(p.LPAREN,"(",r,s,n)):(this.pos=r+2,this.column=n+2,this.dparenDepth=1,this.makeToken(p.DPAREN_START,"((",r,s,n));if(a===")"&&i===")")return this.dparenDepth===1?(this.pos=r+2,this.column=n+2,this.dparenDepth=0,this.makeToken(p.DPAREN_END,"))",r,s,n)):this.dparenDepth>1?(this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.RPAREN,")",r,s,n));for(let[u,c,f]of Mr)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===p.DSEMI||f===p.SEMI_AND||f===p.SEMI_SEMI_AND))&&a===u&&i===c){if(f===p.DBRACK_START||f===p.DBRACK_END){let h=t[r+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==` -`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,u+c,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(p.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(p.RPAREN,")",r,s,n);let o=Vr.get(a);if(o!==void 0)return this.pos=r+1,this.column=n+1,this.makeToken(o,a,r,s,n);if(a==="{"){let u=this.scanFdVariable(r);return u!==null?(this.pos=u.end,this.column=n+(u.end-r),{type:p.FD_VARIABLE,value:u.varname,start:r,end:u.end,line:s,column:n}):i==="}"?(this.pos=r+2,this.column=n+2,{type:p.WORD,value:"{}",start:r,end:r+2,line:s,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(r)!==null?this.readWordWithBraceExpansion(r,s,n):this.scanLiteralBraceWord(r)!==null?this.readWordWithBraceExpansion(r,s,n):i!==void 0&&i!==" "&&i!==" "&&i!==` -`?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.LBRACE,"{",r,s,n))}return a==="}"?this.isWordCharFollowing(r+1)?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(p.RBRACE,"}",r,s,n)):a==="!"?i==="="?(this.pos=r+2,this.column=n+2,this.makeToken(p.WORD,"!=",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(p.BANG,"!",r,s,n)):this.readWord(r,s,n)}looksLikeNestedSubshells(t){let r=this.input,s=r.length,n=t;for(;n=s)return!1;let a=r[n];if(a==="(")return this.looksLikeNestedSubshells(n+1);let i=/[a-zA-Z_]/.test(a),l=a==="!"||a==="[";if(!i&&!l)return!1;let o=n;for(;o=s)return!1;let c=r[u];if(c==="="&&r[u+1]!=="="||c===` -`||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&r[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;i++}if(i>l){let y=n[i];if(!(y==="("&&i>l&&"@*+?!".includes(n[i-1]))){if(i>=a||y===" "||y===" "||y===` -`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let x=Ht.get(b);if(x!==void 0)return{type:x,value:b,start:t,end:i,line:r,column:s};let H=Kt(b);return H>0&&jt(b.slice(0,H))?{type:p.ASSIGNMENT_WORD,value:b,start:t,end:i,line:r,column:s}:/^[0-9]+$/.test(b)?{type:p.NUMBER,value:b,start:t,end:i,line:r,column:s}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:p.NAME,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}:{type:p.WORD,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}}}}i=this.pos;let o=this.column,u=this.line,c="",f=!1,h=!1,d=!1,m=!1,g=n[i]==='"'||n[i]==="'",E=!1,A=0;for(;i0&&"@*+?!".includes(c[c.length-1])){let b=this.scanExtglobPattern(i);if(b!==null){c+=b.content,i=b.end,o+=b.content.length;continue}}if(y==="["&&A===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let b=i+10){c.length>0&&c[c.length-1]!=="\\"&&A++,c+=y,i++,o++;continue}else if(y==="]"&&A>0){c.length>0&&c[c.length-1]!=="\\"&&A--,c+=y,i++,o++;continue}if(A>0){if(y===` -`)break;c+=y,i++,o++;continue}if(y===" "||y===" "||y===` -`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+10&&i0&&De--,De===0&&L==="<"&&n[i+1]==="<"&&n[i+2]!=="<"){let V=i+2,ie=!1;for(n[V]==="-"&&(ie=!0,V++);n[V]===" "||n[V]===" ";)V++;let{delim:ce,endPos:C}=Ue(n,V);if(ce.length>0){c+=n.slice(i+1,C),o+=C-i,me.push({delim:ce,stripTabs:ie}),i=C;continue}}if(L===` -`&&me.length>0){u++,o=0;let V=i+1;for(let{delim:ie,stripTabs:ce}of me)for(;!(V>=a);){let C=n.indexOf(` -`,V);C===-1&&(C=a);let vt=n.slice(V,C),Dr=ce?vt.replace(/^\t+/,""):vt;c+=n.slice(V,Math.min(C+1,a)),C=a;if(V=C+1,Dr===ie||xr)break}me.length=0,o=0,i=Math.min(V,a);continue}if(L==="'")x=!0,z="";else if(L==='"')H=!0,z="";else if(L==="\\"&&i+10&&i0?X=!0:z==="esac"&&le>0&&(le--,X=!1),z="",L==="("?i>0&&n[i-1]==="$"?b++:X||b++:L===")"?X?X=!1:b--:L===";"&&le>0&&(i+10&&i0&&i="0"&&b<="9"){c+=y+b,i+=2,o+=2;continue}}if(y==="`"&&!d){for(c+=y,i++,o++;i=2){if(c[0]==="'"&&c[c.length-1]==="'"){let y=c.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(c=y,f=!0,h=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let y=c.slice(1,-1),b=!1;for(let x=0;x0&&jt(c.slice(0,y)))return{type:p.ASSIGNMENT_WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}return/^[0-9]+$/.test(c)?{type:p.NUMBER,value:c,start:t,end:i,line:r,column:s}:qr(c)?{type:p.NAME,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}:{type:p.WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:h}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let r=this.pos,s=this.line,n=this.column,a="";for(;this.posthis.maxHeredocSize)throw new Ee(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,s,n);this.pos&|()]/.test(i))break;if(i==="'"||i==='"'){a=!0;let l=i;for(this.pos++,this.column++;this.pos=this.input.length)return!1;let r=this.input[t];return!(r===" "||r===" "||r===` -`||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(t,r,s){let n=this.input,a=n.length,i=t,l=s;for(;i")break;if(u==="{"){if(this.scanBraceExpansion(i)!==null){let f=1;for(i++,l++;i0;)n[i]==="{"?f++:n[i]==="}"&&f--,i++,l++;continue}i++,l++;continue}if(u==="}"){i++,l++;continue}if(u==="$"&&i+10&&i0&&i0;){let o=r[n];if(o==="{")a++,n++;else if(o==="}")a--,n++;else if(o===","&&a===1)i=!0,n++;else if(o==="."&&n+10;){let i=r[n];if(i==="{")a++,n++;else if(i==="}"){if(a--,a===0)return r.slice(t,n+1);n++}else{if(i===" "||i===" "||i===` -`||i===";"||i==="&"||i==="|")return null;n++}}return null}scanExtglobPattern(t){let r=this.input,s=r.length,n=t+1,a=1;for(;n0;){let i=r[n];if(i==="\\"&&n+1="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===a)return null;let i=r.slice(a,n);if(n>=s||r[n]!=="}"||(n++,n>=s))return null;let l=r[n],o=n+1"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:i,end:n}:null}dollarDparenIsSubshell(t){let r=this.input,s=r.length,n=t+1,a=2,i=!1,l=!1,o=!1;for(;n0;){let u=r[n];if(i){u==="'"&&(i=!1),u===` -`&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===` -`&&(o=!0),n++;continue}if(u==="'"){i=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===` -`&&(o=!0),u==="("){a++,n++;continue}if(u===")"){if(a--,a===1){let c=n+1;if(c0;){let o=r[n];if(i){o==="'"&&(i=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){i=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){a++,n++;continue}if(o===")"){if(a--,a===1){let u=n+1;if(u=194){let n=(s&31)<<6|e[r+1]&63;t+=String.fromCharCode(n),r+=2;continue}t+=String.fromCharCode(s),r++;continue}if((s&240)===224){if(r+2=55296&&n<=57343){t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(n),r+=3;continue}t+=String.fromCharCode(s),r++;continue}if((s&248)===240&&s<=244){if(r+31114111){t+=String.fromCharCode(s),r++;continue}t+=String.fromCodePoint(n),r+=4;continue}t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(s),r++}return t}function rn(e,t,r){let s=r+1;for(;s0;)t[i]===s?a++:t[i]===n&&a--,a>0&&i++;return a===0?i:-1}function ge(e,t,r){let s=r,n=1;for(;s0;){let a=t[s];if(a==="\\"&&s+10&&s++}return s}function sn(e,t,r){let s=r,n=!1;for(;s0)l.push(c),o+=2+u.length;else break}l.length>0?(s+=Br(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2({type:"Word",word:w.word(s(e,c,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:nn(a).map(c=>({type:"Word",word:w.word([w.literal(c)])}))},endIndex:n+1}:null}function Ye(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(Ye(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function cn(e,t){return{[p.LESS]:"<",[p.GREAT]:">",[p.DGREAT]:">>",[p.LESSAND]:"<&",[p.GREATAND]:">&",[p.LESSGREAT]:"<>",[p.CLOBBER]:">|",[p.TLESS]:"<<<",[p.AND_GREAT]:"&>",[p.AND_DGREAT]:"&>>",[p.DLESS]:"<",[p.DLESSDASH]:"<"}[t]||">"}function Ce(e){let t=e.current(),r=t.type;if(r===p.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:en.has(s.type)}if(r===p.FD_VARIABLE){let s=e.peek(1);return tn.has(s.type)}return Yt.has(r)}function Oe(e){let t=null,r;e.check(p.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(p.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=cn(e,s.type);if(s.type===p.DLESS||s.type===p.DLESSDASH)return zr(e,n,t,s.type===p.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function zr(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function fn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(p.ASSIGNMENT_WORD)||Ce(e);)e.checkIterationLimit(),e.check(p.ASSIGNMENT_WORD)?r.push(Gr(e)):a.push(Oe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(p.DBRACK_START)||e.check(p.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(p.RBRACE))&&!e.check(p.PIPE,p.PIPE_AMP);)if(e.checkIterationLimit(),Ce(e))a.push(Oe(e));else if(e.check(p.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(p.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(p.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(p.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(p.LPAREN);let h=et(e);e.expect(p.RPAREN);let d=h.map(g=>Ye(e,g)),m=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(p.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Gr(e){let t=e.expect(p.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,h=i+1;for(;i2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(p.DPAREN_END),i[0].trim()&&(s=q(e,i[0].trim())),i[1].trim()&&(n=q(e,i[1].trim())),i[2].trim()&&(a=q(e,i[2].trim())),e.skipNewlines(),e.check(p.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(p.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(p.RBRACE)):(e.expect(p.DO),u=e.parseCompoundList(),e.expect(p.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:u,redirections:c,line:r}}function rt(e,t){e.expect(p.WHILE);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function st(e,t){e.expect(p.UNTIL);let r=e.parseCompoundList();e.expect(p.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(p.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function it(e,t){e.expect(p.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(p.IN),e.skipNewlines();let s=[];for(;!e.check(p.ESAC,p.EOF);){e.checkIterationLimit();let a=e.getPos(),i=Hr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(p.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function Hr(e){e.check(p.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(p.PIPE));)e.advance();if(t.length===0)return null;e.expect(p.RPAREN),e.skipNewlines();let r=[];for(;!e.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND,p.ESAC,p.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===p.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(p.LPAREN)&&e.peek(1).type===p.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(p.DSEMI)?(e.advance(),s=";;"):e.check(p.SEMI_AND)?(e.advance(),s=";&"):e.check(p.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function at(e,t){e.expect(p.LPAREN);let r=e.parseCompoundList();e.expect(p.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function ot(e,t){e.expect(p.LBRACE);let r=e.parseCompoundList();e.expect(p.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Kr=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Xr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function hn(e){return e.isWord()||e.check(p.LBRACE)||e.check(p.RBRACE)||e.check(p.ASSIGNMENT_WORD)}function pn(e){if(e.check(p.BANG)&&e.peek(1).type===p.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(p.EOF);)if(e.check(p.LPAREN))t++,r+="(",e.advance();else if(e.check(p.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(p.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function ct(e){return e.skipNewlines(),Jr(e)}function Jr(e){let t=dn(e);for(e.skipNewlines();e.check(p.OR_OR);){e.advance(),e.skipNewlines();let r=dn(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function dn(e){let t=lt(e);for(e.skipNewlines();e.check(p.AND_AND);){e.advance(),e.skipNewlines();let r=lt(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function lt(e){return e.skipNewlines(),e.check(p.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:lt(e)}):Yr(e)}function Yr(e){if(e.check(p.LPAREN)){e.advance();let t=ct(e);return e.expect(p.RPAREN),{type:"CondGroup",expression:t}}if(hn(e)){let t=e.current(),r=t.value;if(Kr.includes(r)&&!t.quoted){if(e.advance(),e.check(p.DBRACK_END)&&e.error(`Expected operand after ${r}`),hn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&Xr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=es(e):n==="=="||n==="!="?a=pn(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(p.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(p.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=pn(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function es(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(p.DBRACK_END)||e.check(p.AND_AND)||e.check(p.OR_OR)||e.check(p.NEWLINE)||e.check(p.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(p.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(p.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(p.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(p.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(p.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(p.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(p.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(p.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(p.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(p.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(p.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(p.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(p.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(p.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(p.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(p.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(p.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(p.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(p.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ne(e){return e.length>0?e:[w.literal("")]}function ns(e,t){let r=1,s=t+1;for(;s0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+10;)t[h]==="{"?f++:t[h]==="}"&&f--,f>0&&h++;let d=t.slice(r+2,h);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:h+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let c=1,f=n;for(;f0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new U("unexpected EOF while looking for matching '}'",0,0);let h=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:f+1}}let u=null;if(a){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n=t.length)throw new U("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,u),endIndex:n+1}}function ut(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=ge(e,t,a),S=t.slice(a,A),y=ue(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(Ne(y));if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let u=ge(e,t,a),c=t.slice(a,u),f=-1,h=0,d=0;for(let E=0;E0)d--;else{f=E;break}}let m=f>=0?c.slice(0,f):c,g=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Je(e,m),length:g!==null?Je(e,g):null},endIndex:u}}if("-=?+".includes(i)){a++;let o=ge(e,t,a),u=t.slice(a,o),c=ue(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(Ne(c));if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,u=i==="#"?"prefix":"suffix";a+=o?2:1;let c=ge(e,t,a),f=t.slice(a,c),h=ue(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(Ne(h)),side:u,greedy:o},endIndex:c}}if(i==="/"){let o=l==="/";a+=o?2:1;let u=null;t[a]==="#"?(u="start",a++):t[a]==="%"&&(u="end",a++);let c;u!==null&&(t[a]==="/"||t[a]==="}")?c=a:c=sn(e,t,a);let f=t.slice(a,c),h=ue(e,f,!1,!1,!1),d=w.word(Ne(h)),m=null,g=c;if(t[c]==="/"){let E=c+1,A=ge(e,t,E),S=t.slice(E,A),y=ue(e,S,!1,!1,!1);m=w.word(Ne(y)),g=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:m,all:o,anchor:u},endIndex:g}}if(i==="^"||i===","){let o=l===i,u=i==="^"?"upper":"lower";a+=o?2:1;let c=ge(e,t,a),f=t.slice(a,c),h=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:h},endIndex:c}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function ft(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),u=q(e,o);return{part:w.arithmeticExpansion(u),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?ss(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?rs(e,t,r):{part:w.literal("$"),endIndex:n}}function mn(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s{a&&(s.push(w.literal(a)),a="")};for(;n=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),g=!1;for(let E=0;E{h&&(c.push(w.literal(h)),h="")};for(;f0?t[f-1]:"";if(f===0||g==="="||n&&g===":"){let A=rn(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;c.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(m)&&f+1Jt)throw new U("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ke)throw new U(`Maximum parser nesting depth exceeded (${Ke})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,r){if(t.length>He)throw new U(`Input too large: ${t.length} bytes exceeds limit of ${He}`,1,1);this._input=t;let s=new $e(t,r);if(this.tokens=s.tokenize(),this.tokens.length>je)throw new U(`Too many tokens: ${this.tokens.length} exceeds limit of ${je}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new U(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new U(t,r.line,r.column,r)}skipNewlines(){for(;this.check(p.NEWLINE,p.COMMENT);)this.check(p.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(p.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(p.SEMICOLON,p.COMMENT)){this.advance();continue}if(t&&this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(p.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(p.EOF,p.NEWLINE,p.SEMICOLON,p.AMP,p.AND_AND,p.OR_OR,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===p.WORD||t===p.NAME||t===p.NUMBER||t===p.ASSIGNMENT_WORD||t===p.IF||t===p.FOR||t===p.WHILE||t===p.UNTIL||t===p.CASE||t===p.LPAREN||t===p.LBRACE||t===p.DPAREN_START||t===p.DBRACK_START||t===p.FUNCTION||t===p.BANG||t===p.TIME||t===p.IN||t===p.LESS||t===p.GREAT||t===p.DLESS||t===p.DGREAT||t===p.LESSAND||t===p.GREATAND||t===p.LESSGREAT||t===p.DLESSDASH||t===p.CLOBBER||t===p.TLESS||t===p.AND_GREAT||t===p.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(p.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(p.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===p.DO||t===p.DONE||t===p.THEN||t===p.ELSE||t===p.ELIF||t===p.FI||t===p.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.RBRACE||t===p.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===p.DSEMI||t===p.SEMI_AND||t===p.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===p.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===p.PIPE||t===p.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(p.AND_AND,p.OR_OR);){let o=this.advance();s.push(o.type===p.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();r.push(u)}this.check(p.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(p.TIME)&&(this.advance(),t=!0,this.check(p.WORD,p.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(p.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(p.PIPE,p.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===p.PIPE_AMP);let u=this.parseCommand();a.push(u)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(p.IF)?tt(this):this.check(p.FOR)?nt(this):this.check(p.WHILE)?rt(this):this.check(p.UNTIL)?st(this):this.check(p.CASE)?it(this):this.check(p.LPAREN)?at(this):this.check(p.LBRACE)?ot(this):this.check(p.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(p.DBRACK_START)?this.parseConditionalCommand():this.check(p.FUNCTION)?this.parseFunctionDef():this.check(p.NAME,p.WORD)&&this.peek(1).type===p.LPAREN&&this.peek(2).type===p.RPAREN?this.parseFunctionDef():fn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;rnew e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return Ut(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return Qt(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(p.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(p.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(p.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(p.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(p.DPAREN_START))s++,r+="((",this.advance();else if(this.check(p.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(p.LPAREN))n++,r+="(",this.advance();else if(this.check(p.RPAREN))n>0&&n--,r+=")",this.advance();else{let u=this.current().value,c=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(r+=" "),r+=u,this.advance()}}i||this.expect(p.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(p.DBRACK_START),r=ct(this);this.expect(p.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(p.FUNCTION)){if(this.advance(),this.check(p.NAME)||this.check(p.WORD))t=this.advance().value;else{let n=this.current();throw new U("Expected function name",n.line,n.column,n)}this.check(p.LPAREN)&&(this.advance(),this.expect(p.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(p.LPAREN),this.expect(p.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(p.LBRACE))return ot(this,{skipRedirections:r});if(this.check(p.LPAREN))return at(this,{skipRedirections:r});if(this.check(p.IF))return tt(this,{skipRedirections:r});if(this.check(p.FOR))return nt(this,{skipRedirections:r});if(this.check(p.WHILE))return rt(this,{skipRedirections:r});if(this.check(p.UNTIL))return st(this,{skipRedirections:r});if(this.check(p.CASE))return it(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(p.EOF,p.FI,p.ELSE,p.ELIF,p.THEN,p.DO,p.DONE,p.ESAC,p.RPAREN,p.RBRACE,p.DSEMI,p.SEMI_AND,p.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;Ce(this);){this.checkIterationLimit();let r=this.pos;if(t.push(Oe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return q(this,t)}};function Ni(e,t){return new B().parse(e,t)}var os=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function ht(e){return os.get(e)??""}function gn(e){let t=[],r="",s=0;for(;s0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function dt(e){let t=[],r="",s=0,n=!1,a=0;for(;athis.maxOps)throw new W(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return yn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i0?a.push(...l):a.push(t[i])}return a}async expand(t){if(this.globstar){let s=t.split("/"),n=0;for(let a of s)if(a==="**"&&(n++,n>En))throw new W(`Glob pattern has too many ** segments (max ${En})`,"glob_operations")}let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;um.name==="."),d=l.some(m=>m.name==="..");h||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let h of u)if(!(h.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(h.name,n)){let d=t==="/"?`/${h.name}`:`${t}/${h.name}`,m;r===""?m=h.name:r==="/"?m=`/${h.name}`:m=`${r}/${h.name}`,a.length===0?o.push(Promise.resolve([m])):h.isDirectory&&o.push(this.expandSegments(d,m,a))}let f=await Promise.all(o);for(let h of f)i.push(...h)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let h of u)if(!(h.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(h,n)){let d=t==="/"?`/${h}`:`${t}/${h}`,m;r===""?m=h:r==="/"?m=`/${h}`:m=`${r}/${h}`,a.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,m,a)}catch(g){if(g instanceof W)throw g}return[]})())}let f=await Promise.all(o);for(let h of f)i.push(...h)}}catch(l){if(l instanceof W)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let u of a){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&i.push(c)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let u=0;uthis.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let c of i){let f=t==="."?c:`${t}/${c}`,h=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory&&l.push(f)}catch(d){if(d instanceof W)throw d}}let o=t==="."?r:`${t}/${r}`,u=await this.expandRecursive(o);s.push(...u);for(let c=0;cthis.walkDirectoryMultiGlobstar(h,r,s)))}}}catch(a){if(a instanceof W)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):r&&this.matchPattern(o.name,r)&&i.push(u)}s.push(...i);for(let o=0;othis.walkDirectory(c,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o{let h=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,h);try{this.checkOpsLimit();let m=await this.fs.stat(d);return{name:f,path:h,isDirectory:m.isDirectory}}catch(m){if(m instanceof W)throw m;return null}}));i.push(...c.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;othis.walkDirectory(c.path,r,s)))}}}catch(a){if(a instanceof W)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;nthis.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(a==="@")r+=`(?:${c})`;else if(a==="*")r+=`(?:${c})*`;else if(a==="+")r+=`(?:${c})+`;else if(a==="?")r+=`(?:${c})?`;else if(a==="!")if(ithis.computePatternLength(m));if(h.every(m=>m!==null)&&h.every(m=>m===h[0])&&h[0]!==null){let m=h[0];if(m===0)r+="(?:.+)";else{let g=[];m>0&&g.push(`.{0,${m-1}}`),g.push(`.{${m+1},}`),g.push(`(?!(?:${c})).{${m}}`),r+=`(?:${g.join("|")})`}}else r+=`(?:(?!(?:${c})).)*?`}else r+=`(?!(?:${c})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";ithis.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){r+=u[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function ls(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new $("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new $("division by 0");return e%t;case"**":if(t<0)throw new $("exponent less than 0");return e**t;case"<<":return e<>":return e>>t;case"<":return e":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function An(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function cs(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function us(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await D(e,t)}function fs(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new B,{expr:n,pos:a}=j(s,r,0);if(a100)throw new $("maximum variable indirection depth exceeded");if(r.has(t))return 0;r.add(t);let n=await us(e,t);if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n.trim()))return a;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await gt(e,i,r,s+1);let l=new B,{expr:o,pos:u}=j(l,i,0);if(u0&&(s===-1||h64)return 0;let a=`${n}#${t.value}`;return be(a)}case"ArithDynamicNumber":{let n=await Le(e,t.prefix)+t.suffix;return be(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await mt(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await D(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript -`,0;let f=Math.max(...o.map(([h])=>typeof h=="number"?h:0))+1+a;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript -`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return mt(e,l);if(a===0){let o=e.state.env.get(t.array);if(o!==void 0)return mt(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new J(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new $("double subscript","","");case"ArithNumberSubscript":throw new $(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new $(t.message,"","",!0);case"ArithSingleQuote":{if(r)throw new $(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await R(e,t.left,r)||await R(e,t.right,r)?1:0;if(t.operator==="&&")return await R(e,t.left,r)&&await R(e,t.right,r)?1:0;let s=await R(e,t.left,r),n=await R(e,t.right,r);return ls(s,n,t.operator)}case"ArithUnary":{let s=await R(e,t.operand,r);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,a=Number.parseInt(await D(e,n),10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,a=e.state.associativeArrays?.has(n),i;if(t.operand.stringKey!==void 0)i=`${n}_${t.operand.stringKey}`;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)i=`${n}_${t.operand.index.name}`;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await D(e,t.operand.index.name);i=`${n}_${u}`}else if(t.operand.index){let u=await R(e,t.operand.index,r);i=`${n}_${u}`}else return s;let l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let a of t.operand.parts)n+=await Ae(e,a,r);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)n+=await Ae(e,a,r);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await D(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=await R(e,t.operand.subscript,r),i=`${n}_${a}`,l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}}return s}return cs(s,t.operator)}case"ArithTernary":return await R(e,t.condition,r)?await R(e,t.consequent,r):await R(e,t.alternate,r);case"ArithAssignment":{let s=t.variable,n=s;if(t.stringKey!==void 0)n=`${s}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(s);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${s}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await D(e,t.subscript.name);n=`${s}_${u||"\\"}`}else if(o){let u=await R(e,t.subscript,r);n=`${s}_${u}`}else{let u=await R(e,t.subscript,r);if(u<0){let c=P(e,s);c.length>0&&(u=Math.max(...c.map(([h])=>typeof h=="number"?h:0))+1+u)}n=`${s}_${u}`}}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=An(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await R(e,t.expression,r);case"ArithConcat":{let s="";for(let n of t.parts)s+=await Ae(e,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)?await gt(e,s):Number.parseInt(s,10)||0}case"ArithDynamicAssignment":{let s="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)s+=await Ae(e,o,r);else t.target.type==="ArithVariable"&&(s=t.target.hasDollarPrefix?await D(e,t.target.name):t.target.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=s;if(t.subscript){let o=await R(e,t.subscript,r);n=`${s}_${o}`}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=An(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let s="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)s+=await Ae(e,l,r);else t.nameExpr.type==="ArithVariable"&&(s=t.nameExpr.hasDollarPrefix?await D(e,t.nameExpr.name):t.nameExpr.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=await R(e,t.subscript,r),a=`${s}_${n}`,i=e.state.env.get(a);return i!==void 0?fs(i):0}default:return 0}}async function Ae(e,t,r=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await R(e,t,r));case"ArithVariable":return t.hasDollarPrefix?await D(e,t.name):t.name;case"ArithSpecialVar":return await D(e,t.name);case"ArithBracedExpansion":return await Le(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let n of t.parts)s+=await Ae(e,n,r);return s}default:return String(await R(e,t,r))}}function yt(e){for(let t=0;tn-a)}function Fi(e,t){let r=`${t}_`;for(let s of e.state.env.keys())s.startsWith(r)&&e.state.env.delete(s)}function At(e,t){let r=`${t}_`,s=`${t}__length`,n=[];for(let a of e.state.env.keys())if(a!==s&&a.startsWith(r)){let i=a.slice(r.length);if(i.startsWith("_length"))continue;n.push(i)}return n.sort()}function We(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function zi(e){if(e.parts.length<2)return null;let t=e.parts[0],r=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let s,n=r,a=1;if(r.type==="Literal"&&r.value.startsWith("]")){let f=r.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))s=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let h=e.parts[2];if(h.type!=="Literal"||!h.value.startsWith("=")&&!h.value.startsWith("+="))return null;s=t.pattern.slice(1),n=h,a=2}else return null}else if(t.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(r.type==="SingleQuoted")s=r.value;else{s="";for(let h of r.parts)(h.type==="Literal"||h.type==="Escaped")&&(s+=h.value)}n=f,a=2}else if(t.pattern.endsWith("]")){if(r.type!=="Literal"||!r.value.startsWith("=")&&!r.value.startsWith("+="))return null;s=t.pattern.slice(1,-1)}else return null;s=We(s);let i;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?i=n.value.slice(1):i=n.value;let l=i.startsWith("+=");if(!l&&!i.startsWith("="))return null;let o=[],u=l?2:1,c=i.slice(u);c&&o.push({type:"Literal",value:c});for(let f=a+1;f{if(r.type==="Range"){let s=r.startStr??String(r.start),n=r.endStr??String(r.end),a=`${s}..${n}`;return r.step&&(a+=`..${r.step}`),a}return wn(r.word)}).join(",")}}`}function wn(e){let t="";for(let r of e.parts)switch(r.type){case"Literal":t+=r.value;break;case"Glob":t+=r.pattern;break;case"SingleQuoted":t+=r.value;break;case"DoubleQuoted":for(let s of r.parts)(s.type==="Literal"||s.type==="Escaped")&&(t+=s.value);break;case"Escaped":t+=r.value;break;case"BraceExpansion":t+="{",t+=r.items.map(s=>s.type==="Range"?`${s.startStr}..${s.endStr}${s.step?`..${s.step}`:""}`:wn(s.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",r.user&&(t+=r.user);break}return t}function M(e){return e.get("IFS")??` -`}function F(e){return e.get("IFS")===""}function Te(e){let t=M(e);if(t==="")return!0;for(let r of t)if(r!==" "&&r!==" "&&r!==` -`)return!1;return!0}function Nn(e){let t=!1,r=[];for(let s of e.split(""))s==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(s)?r.push(`\\${s}`):s===" "?r.push("\\t"):s===` -`?r.push("\\n"):r.push(s);return t&&r.push("\\-"),r.join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var ds=` -`;function ms(e){return ds.includes(e)}function St(e){let t=new Set,r=new Set;for(let s of e)ms(s)?t.add(s):r.add(s);return{whitespace:t,nonWhitespace:r}}function Qi(e,t,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:a}=St(t),i=[],l=[],o=0;for(;o=e.length)return{words:[],wordStarts:[]};if(a.has(e[o]))for(i.push(""),l.push(o),o++;o=r);){let u=o;for(l.push(u);o=e.length)break;for(;o=r);)for(i.push(""),l.push(o),o++;oo&&(i=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(n.push(""),a++;a=e.length){l=!1;break}let c=a;for(;a=e.length&&a>c&&(l=!0)}return{words:n,hadLeadingDelimiter:i,hadTrailingDelimiter:l}}function v(e,t){return Me(e,t).words}function gs(e,t){for(let r of e)if(t.has(r))return!0;return!1}function Zi(e,t,r){if(t==="")return e;let{whitespace:s,nonWhitespace:n}=St(t),a=e.length;for(;a>0&&s.has(e[a-1]);){if(!r&&a>=2){let l=0,o=a-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}a--}let i=e.substring(0,a);if(i.length>=1&&n.has(i[i.length-1])){if(!r&&i.length>=2){let o=0,u=i.length-2;for(;u>=0&&i[u]==="\\";)o++,u--;if(o%2===1)return i}let l=i.substring(0,i.length-1);if(!gs(l,n))return l}return i}function T(e,t){return e.state.namerefs?.has(t)??!1}function Hi(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function ji(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Ki(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function kn(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Xi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ys(e,t){let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],a=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),i=e.state.associativeArrays?.has(n)??!1;return a||i}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function ye(e,t,r=100){if(!T(e,t)||kn(e,t))return t;let s=new Set,n=t;for(;r-- >0;){if(s.has(n))return;if(s.add(n),!T(e,n))return n;let a=e.state.env.get(n);if(a===void 0||a===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return n;n=a}}function Pe(e,t){if(T(e,t))return e.state.env.get(t)}function Ji(e,t,r,s=100){if(!T(e,t)||kn(e,t))return t;let n=new Set,a=t;for(;s-- >0;){if(n.has(a))return;if(n.add(a),!T(e,a))return a;let i=e.state.env.get(a);if(i===void 0||i==="")return r!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ys(e,r)?a:null:a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return a;a=i}}function Es(e,t){let r=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(s,n)=>e.state.env.get(n)??"");return r=r.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(s,n)=>e.state.env.get(n)??""),r}function P(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((a,i)=>[i,a]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((a,i)=>[i,String(a)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((a,i)=>[i,a]):e.state.associativeArrays?.has(t)?At(e,t).map(a=>[a,e.state.env.get(`${t}_${a}`)??""]):Et(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function Re(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?At(e,t).length>0:Et(e,t).length>0}async function D(e,t,r=!0,s=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let l=[];for(let o=1;o<=i;o++)l.push(e.state.env.get(String(o))||"");return l.join(N(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return bn;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new J("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(r&&e.state.options.nounset)throw new J("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new J("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new ae(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let i=n[1],l=n[2];if(T(e,i)){let f=ye(e,i);if(f&&f!==i){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=f}}if(l==="@"||l==="*"){let f=P(e,i);if(f.length>0)return f.map(([,d])=>d).join(" ");let h=e.state.env.get(i);return h!==void 0?h:""}if(i==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(i==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let h=e.state.callLineStack?.[f];return h!==void 0?String(h):""}return""}if(i==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(i)){let f=We(l);f=Es(e,f);let h=e.state.env.get(`${i}_${f}`);if(h===void 0&&r&&e.state.options.nounset)throw new J(`${i}[${l}]`);return h||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new B,h=q(f,l);u=await R(e,h.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=P(e,i),h=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript -`,"";let m=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+u;return m<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${h}: ${i}: bad array subscript -`,""):e.state.env.get(`${i}_${m}`)||""}let c=e.state.env.get(`${i}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new J(`${i}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new J(t);return i||""}if(T(e,t)){let i=ye(e,t);if(i===void 0)return"";if(i!==t)return await D(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new J(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(Re(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new J(t);return""}async function re(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(T(e,n)){let o=ye(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=We(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new B,u=q(o,a);l=await R(e,u.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(T(e,t)){let n=ye(e,t);return n===void 0||n===t?e.state.env.has(t):re(e,n)}return!!(e.state.env.has(t)||Re(e,t))}async function Pn(e,t){let r="",s=0;for(;s0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let u=r.slice(i+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let u=r.slice(i+2,o-1),c=await D(e,u);a+=c,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l{if(o>0){let f=c<0,h=String(Math.abs(c)).padStart(o,"0");return f?`-${h}`:h}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f=t&&f="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let h=r!==void 0?`..${r}`:"";throw new _t(`{${e}..${t}${h}}: invalid sequence`)}let f=[];if(n<=a)for(let h=n,d=0;h<=a&&d=a&&dk(f,t,r)),c=u.length>0?u.join("|"):"(?:)";a==="@"?s+=`(?:${c})`:a==="*"?s+=`(?:${c})*`:a==="+"?s+=`(?:${c})+`:a==="?"?s+=`(?:${c})?`:a==="!"&&(s+=`(?!(?:${c})$).*`),n=i+1;continue}}if(a==="\\")if(n+10;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ws(e){let t=[],r="",s=0,n=0;for(;n0&&r=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function Se(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&a.add(u[1])}let i=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function Is(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function Ie(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,h=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=` -`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=u,s+=2;break;case"W":r+=c,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${h[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+20&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!r){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.lengtha.startsWith(`${t}_`)&&/^[0-9]+$/.test(a.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return s&&!n&&(r+="a"),n&&(r+="A"),e.state.integerVars?.has(t)&&(r+="i"),T(e,t)&&(r+="n"),Pt(e,t)&&(r+="r"),e.state.exportedVars?.has(t)&&(r+="x"),r}async function In(e,t,r,s){return e.coverage?.hit("bash:expansion:default_value"),(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):r.effectiveValue}async function Dn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:assign_default"),(s.isUnset||r.checkEmpty&&s.isEmpty)&&r.word){let i=await n(e,r.word.parts,s.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let h=new B,d=q(h,u);c=await R(e,d.expression)}catch{let h=e.state.env.get(u);c=h?Number.parseInt(h,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,i);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,i);return i}return s.effectiveValue}async function xn(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),s.isUnset||r.checkEmpty&&s.isEmpty){let i=r.word?await n(e,r.word.parts,s.inDoubleQuotes):`${t}: parameter null or not set`;throw new Y(1,"",`bash: ${i} -`)}return s.effectiveValue}async function vn(e,t,r,s){return e.coverage?.hit("bash:expansion:use_alternative"),!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function _n(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_removal");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let o of r.pattern.parts)if(o.type==="Glob")a+=k(o.pattern,r.greedy,i);else if(o.type==="Literal")a+=k(o.value,r.greedy,i);else if(o.type==="SingleQuoted"||o.type==="Escaped")a+=I(o.value);else if(o.type==="DoubleQuoted"){let u=await s(e,o.parts);a+=I(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);a+=k(u,r.greedy,i)}else{let u=await n(e,o);a+=I(u)}if(r.side==="prefix")return O(`^${a}`,"s").replace(t,"");let l=O(`${a}$`,"s");if(r.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function $n(e,t,r,s,n){e.coverage?.hit("bash:expansion:pattern_replacement");let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let u of r.pattern.parts)if(u.type==="Glob")a+=k(u.pattern,!0,i);else if(u.type==="Literal")a+=k(u.value,!0,i);else if(u.type==="SingleQuoted"||u.type==="Escaped")a+=I(u.value);else if(u.type==="DoubleQuoted"){let c=await s(e,u.parts);a+=I(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);a+=k(c,!0,i)}else{let c=await n(e,u);a+=I(c)}let l=r.replacement?await s(e,r.replacement.parts):"";if(r.anchor==="start"?a=`^${a}`:r.anchor==="end"&&(a=`${a}$`),a==="")return t;let o=r.all?"gs":"s";try{let u=O(a,o);if(r.all){let c="",f=0,h=0,d=e.limits.maxStringLength,m=u.exec(t);for(;m!==null&&!(m[0].length===0&&m.index===t.length);){if(c+=t.slice(f,m.index)+l,f=m.index+m[0].length,m[0].length===0&&f++,h++,h%100===0&&c.length>d)throw new W(`pattern replacement: string length limit exceeded (${d} bytes)`,"string_length");m=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof W)throw u;return t}}function Cn(e,t,r){e.coverage?.hit("bash:expansion:length");let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(s){let n=s[1],a=P(e,n);return a.length>0?String(a.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&Re(e,t)){if(t==="FUNCNAME"){let a=e.state.funcNameStack?.[0]||"";return String([...a].length)}if(t==="BASH_LINENO"){let a=e.state.callLineStack?.[0];return String(a!==void 0?[...String(a)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...r].length)}async function On(e,t,r,s){e.coverage?.hit("bash:expansion:substring");let n=await R(e,s.offset.expression),a=s.length?await R(e,s.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let m=1;m<=u;m++)c.push(e.state.env.get(String(m))||"");let f=e.state.env.get("0")||"bash",h,d;if(n<=0)if(h=[f,...c],n<0){if(d=h.length+n,d<0)return""}else d=0;else h=c,d=n-1;if(d<0||d>=h.length)return"";if(a!==void 0){let m=a<0?h.length+a:d+a;return h.slice(d,Math.max(d,m)).join(" ")}return h.slice(d).join(" ")}let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i){let u=i[1];if(e.state.associativeArrays?.has(u))throw new Y(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution -`);let c=P(e,u),f=0;if(n<0){if(c.length>0){let h=c[c.length-1][0],m=(typeof h=="number"?h:0)+1+n;if(m<0||(f=c.findIndex(([g])=>typeof g=="number"&&g>=m),f<0))return""}}else if(f=c.findIndex(([h])=>typeof h=="number"&&h>=n),f<0)return"";if(a!==void 0){if(a<0)throw new $(`${i[1]}[@]: substring expression < 0`);return c.slice(f,f+a).map(([,h])=>h).join(" ")}return c.slice(f).map(([,h])=>h).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let u=l.length+a;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function Ln(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:case_modification"),r.pattern){let a=e.state.shoptOptions.extglob,i="";for(let f of r.pattern.parts)if(f.type==="Glob")i+=k(f.pattern,!0,a);else if(f.type==="Literal")i+=k(f.value,!0,a);else if(f.type==="SingleQuoted"||f.type==="Escaped")i+=I(f.value);else if(f.type==="DoubleQuoted"){let h=await s(e,f.parts);i+=I(h)}else if(f.type==="ParameterExpansion"){let h=await n(e,f);i+=k(h,!0,a)}let l=O(`^(?:${i})$`),o=r.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!r.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return r.direction==="upper"?r.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):r.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Wn(e,t,r,s,n){e.coverage?.hit("bash:expansion:transform");let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,u])=>he(u)).join(" ");if(a&&n.operator==="a")return pe(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return pe(e,i[1]);switch(n.operator){case"Q":return s?"":he(r);case"P":return Ie(e,r);case"a":return pe(e,t);case"A":return s?"":`${t}=${he(r)}`;case"E":return r.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return` -`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":he(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function Tn(e,t,r,s,n,a,i=!1){if(e.coverage?.hit("bash:expansion:indirection"),T(e,t))return Pe(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new ae(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new ae(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new ae(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,c,i)}return await D(e,o)}function Mn(e,t){e.coverage?.hit("bash:expansion:array_keys");let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function Vn(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let r=Se(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function qn(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=N(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:s?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Bn(e){let t=0;for(;t0;){let i=e[s];if(i==="\\"&&!n&&s+1E);if(c.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let h="";u.pattern&&(h=await vs(e,u.pattern,r,s));let d=u.replacement?await r(e,u.replacement.parts):"",m=h;u.anchor==="start"?m=`^${h}`:u.anchor==="end"&&(m=`${h}$`);let g=[];try{let E=O(m,u.all?"g":"");for(let A of f)g.push(E.replace(A,d))}catch{g.push(...f)}if(o){let E=N(e.state.env);return{values:[g.join(E)],quoted:!0}}return{values:g,quoted:!0}}async function Zn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,g])=>g);if(c.length===0){let g=e.state.env.get(l);g!==void 0&&f.push(g)}if(f.length===0)return{values:[],quoted:!0};let h="",d=e.state.shoptOptions.extglob;if(u.pattern)for(let g of u.pattern.parts)if(g.type==="Glob")h+=k(g.pattern,u.greedy,d);else if(g.type==="Literal")h+=k(g.value,u.greedy,d);else if(g.type==="SingleQuoted"||g.type==="Escaped")h+=I(g.value);else if(g.type==="DoubleQuoted"){let E=await r(e,g.parts);h+=I(E)}else if(g.type==="ParameterExpansion"){let E=await s(e,g);h+=k(E,u.greedy,d)}else{let E=await s(e,g);h+=I(E)}let m=[];for(let g of f)m.push(oe(g,h,u.side,u.greedy));if(o){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}async function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let u=P(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,d])=>d===""),h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(h&&f):i=!c||h&&f,!i){if(u.length>0){let m=u.map(([,g])=>g);if(l){let g=N(e.state.env);return{values:[m.join(g)],quoted:!0}}return{values:m,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,u=await re(e,o),c=await D(e,o),f=c==="",h=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(h&&f):i=!u||h&&f,!i)return{values:[c],quoted:!0}}if(i&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let h=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(h){u=h[1],c=h[2]==="*";break}}if(u){let f=P(e,u);if(f.length>0){let d=f.map(([,m])=>m);if(c||l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}return null}async function Hn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,u=null;for(let g=0;gg);if(h.length===0){let g=e.state.env.get(l);if(g!==void 0)d=[g];else{if(o)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let g=u,E="",A=e.state.shoptOptions.extglob;if(g.pattern)for(let S of g.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,g.greedy,A);else if(S.type==="Literal")E+=k(S.value,g.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,g.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>oe(S,E,g.side,g.greedy))}else if(u?.type==="PatternReplacement"){let g=u,E="";if(g.pattern)for(let y of g.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=g.replacement?await n(e,g.replacement.parts):"",S=E;g.anchor==="start"?S=`^${E}`:g.anchor==="end"&&(S=`${E}$`);try{let y=O(S,g.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let g=N(e.state.env);return{values:[c+d.join(g)+f],quoted:!0}}return d.length===1?{values:[c+d[0]+f],quoted:!0}:{values:[c+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function jn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;dd);if(c.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let m=o+u;return{values:m?[m]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Kn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new Y(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution -`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),h=0;if(u<0){if(f.length>0){let m=f[f.length-1][0],E=(typeof m=="number"?m:0)+1+u;if(E<0)return{values:[],quoted:!0};h=f.findIndex(([A])=>typeof A=="number"&&A>=E),h<0&&(h=f.length)}}else h=f.findIndex(([m])=>typeof m=="number"&&m>=u),h<0&&(h=f.length);let d;if(c!==void 0){if(c<0)throw new $(`${i}[@]: substring expression < 0`);d=f.slice(h,h+c).map(([,m])=>m)}else d=f.slice(h).map(([,m])=>m);if(d.length===0)return{values:[],quoted:!0};if(l){let m=N(e.state.env);return{values:[d.join(m)],quoted:!0}}return{values:d,quoted:!0}}function Xn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let h;switch(l.operator){case"a":h="";break;case"P":h=Ie(e,f);break;case"Q":h=he(f);break;default:h=f}return{values:[h],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=pe(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>Ie(e,f));break;case"Q":c=o.map(([,f])=>he(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Jn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(T(e,a)){let o=Pe(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Yn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!T(e,n))return null;let a=Pe(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function er(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await D(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let m=Number.parseInt(e.state.env.get("#")||"0",10),g=[];for(let E=1;E<=m;E++)g.push(e.state.env.get(String(E))||"");return o==="*"?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}return null}let c=u[1],f=u[2]==="*",h=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return _s(e,h,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return $s(e,h,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let g=pe(e,c),E=h.map(()=>g);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let m=[];for(let[,g]of h){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",g);try{let S=await s(e,E,!0);m.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}if(h.length>0){let m=h.map(([,g])=>g);return f?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function _s(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],h=(typeof c=="number"?c:0)+1+a;if(h<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=h),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new $(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function $s(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function tr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await D(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await re(e,r.parameter),c=await D(e,r.parameter)==="",f=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=u&&!(f&&c):h=!u||f&&c,h){let d=o[1],m=o[2]==="*",g=P(e,d);if(g.length>0){let A=g.map(([,S])=>S);return m?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function nr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await D(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await D(e,r.parameter),f=await re(e,r.parameter),h=c==="",d=n.checkEmpty??!1,m;if(n.type==="UseAlternative"?m=f&&!(d&&h):m=!f||d&&h,m){let g=u[1],E=u[2]==="*",A=P(e,g);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(g);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function rr(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function sr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S=h.length)m=[];else if(c!==void 0){let y=c<0?h.length+c:S+c;m=h.slice(S,Math.max(S,y))}else m=h.slice(S)}let g="";for(let S=0;S0)s.push(...a);else{if(r.hasFailglob())throw new xe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function lr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;SS);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let h=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let m=[];try{let S=O(d,o.all?"g":"");for(let y of c)m.push(S.replace(y,h))}catch{m.push(...c)}let g=M(e.state.env),E=F(e.state.env);if(i){let S=N(e.state.env),y=m.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:v(y,g),quoted:!1}}if(E)return{values:m,quoted:!1};let A=[];for(let S of m)S===""?A.push(""):A.push(...v(S,g));return{values:A,quoted:!1}}async function cr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;AA);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,h);else if(A.type==="Literal")f+=k(A.value,o.greedy,h);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,h)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(oe(A,f,o.side,o.greedy));let m=M(e.state.env),g=F(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return g?{values:S?[S]:[],quoted:!1}:{values:v(S,m),quoted:!1}}if(g)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...v(A,m));return{values:E,quoted:!1}}async function ur(e,t,r,s){let n=-1,a=!1;for(let E=0;E=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let m="";for(let y=0;yu!=="");else{let u=N(e.state.env),c=n.join(u);o=v(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=v(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=v(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Be(e,o),quoted:!1}}async function pr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=M(e.state.env),o=F(e.state.env),u=Te(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),h=i.join(f);c=v(h,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let h=v(f,l);c.push(...h)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let h=v(f,l);c.push(...h)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Be(e,c),quoted:!1}}function dr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=Se(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=M(e.state.env),a=F(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=v(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=v(l,n);i.push(...o)}}return{values:i,quoted:!1}}function mr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=M(e.state.env),i=F(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=v(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=v(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function gr(e,t,r){let s=-1;for(let h=0;hd!=="");else if(c){f=[];for(let d of h){if(d==="")continue;let m=v(d,o);f.push(...m)}}else{f=[];for(let d of h)if(d==="")f.push("");else{let m=v(d,o);f.push(...m)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Be(e,f),quoted:!1}}async function Ar(e,t,r){e.coverage?.hit("bash:expansion:word_glob");let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ke(s),h=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(h&&h.length>1)return Os(e,h,n);let d=await Ls(e,s,l,u,c,r);if(d!==null)return d;let m=await Ts(e,s,r);if(m!==null)return m;let g=await Ms(e,s,r);if(g!==null)return g;let E=await qs(e,s,r.expandPart);if(E!==null)return Er(e,E);if((a||i||o)&&!F(e.state.env)){let S=M(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return Er(e,b)}let A=await r.expandWordAsync(e,t);return Bs(e,t,s,A,n,r.expandWordForGlobbing)}async function Os(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&se(n,e.state.shoptOptions.extglob)){let a=await Fe(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Ls(e,t,r,s,n,a){if(r){let i=Jn(e,t);if(i!==null)return i}{let i=Yn(e,t);if(i!==null)return i}{let i=await Un(e,t);if(i!==null)return i}{let i=await Hn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await jn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Kn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Xn(e,t);if(i!==null)return i}{let i=await Qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Ws(e,t);if(i!==null)return i}{let i=await er(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await tr(e,t);if(i!==null)return i}{let i=await nr(e,t);if(i!==null)return i}return null}function Ws(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=Se(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function Ts(e,t,r){{let s=await sr(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await ar(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await or(e,t,r.expandPart);if(s!==null)return s}return null}async function Ms(e,t,r){{let s=await lr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await cr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ur(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await fr(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await hr(e,t);if(s!==null)return s}{let s=await pr(e,t);if(s!==null)return s}{let s=dr(e,t);if(s!==null)return s}{let s=mr(e,t);if(s!==null)return s}{let s=await gr(e,t,r.expandPart);if(s!==null)return s}return null}function yr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;to),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function qs(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(yr(o)){s=!0;break}if(!s)return null;let n=M(e.state.env),a=F(e.state.env),i=[];for(let o of t){let u=yr(o);if(u&&o.type==="DoubleQuoted"){let c=await Vs(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=v(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=v(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c0)return s;if(r.hasFailglob())throw new xe(t);return r.hasNullglob()?[]:[t]}async function Bs(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(se(l,e.state.shoptOptions.extglob)){let u=await Fe(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=Nt(s);if(!F(e.state.env)){let u=M(e.state.env);return{values:v(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&se(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(se(l,e.state.shoptOptions.extglob)){let o=await Fe(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=Nt(s);if(!F(e.state.env)){let o=M(e.state.env);return{values:v(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function br(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await re(e,t.parameter),i=await D(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Fs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function zs(e,t){if(t.type!=="ParameterExpansion")return null;let r=await br(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Fs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Gs(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?yt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Sn(e))}async function wr(e,t,r,s,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let h=t[0],d=await br(e,h);if(d&&d.length>0&&d.length>1&&d.some(g=>g.type==="DoubleQuoted"||g.type==="SingleQuoted")&&d.some(g=>g.type==="Literal"||g.type==="ParameterExpansion"||g.type==="CommandSubstitution"||g.type==="ArithmeticExpansion"))return Sr(e,d,r,s,n)}let a=[],i=!1;for(let h of t){let d=Gs(h),m=h.type==="DoubleQuoted"||h.type==="SingleQuoted",g=d?await zs(e,h):null,E=await n(e,h);a.push({value:E,isSplittable:d,isQuoted:m,mixedDefaultParts:g??void 0}),d&&(i=!0)}if(!i){let h=a.map(d=>d.value).join("");return h?[h]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let h of a)if(!h.isSplittable)c?h.isQuoted&&h.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):h.value!==""?(o!==""&&l.push(o),o=h.value,c=!1,f=!1):(o+=h.value,f=!1):(o+=h.value,f=h.isQuoted&&h.value==="");else if(h.mixedDefaultParts){let d=await Sr(e,h.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let m=1;m0&&t.includes(e[0])}async function Sr(e,t,r,s,n){let a=[];for(let c of t){let h=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:h})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Qs(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:h,hadTrailingDelimiter:d}=Me(c.value,r);if(h.length===0)d&&(u=!0);else if(h.length===1)l+=h[0],o=!0,u=d;else{l+=h[0],i.push(l),o=!0;for(let m=1;mt)throw new W(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function te(e,t,r=!1){let s=[];for(let n of t)s.push(await K(e,n,r));return s.join("")}function Zs(e){return kr(e)}function Dl(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Zs(t))return!1;return!0}function Us(e,t,r=!1){let s=Nr(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Rt(e,t.pattern);default:return null}}async function Dt(e,t){return xt(e,t)}async function xl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await K(e,s);r.push(kt(n))}else r.push(await K(e,s));return r.join("")}async function vl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(ee(s.value));else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(ee(n))}else r.push(await K(e,s));return r.join("")}async function Pr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(ee(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await te(e,s.parts);r.push(ee(n))}else s.type==="Glob"?Bn(s.pattern)?r.push(await zn(e,s.pattern)):r.push(Rt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await K(e,s));return r.join("")}function Ge(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Ge(t.parts))return!0;return!1}var It=1e5;async function Rr(e,t,r={count:0}){if(r.count>It)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=wt(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let h of f.expanded)r.count++,a.push(h);else{i=!0,l=f.literal;break}}else{let f=await Rr(e,c.word.parts,r);for(let h of f){r.count++;let d=[];for(let m of h)typeof m=="string"?d.push(m):d.push(await K(e,m));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>e.limits.maxBraceExpansionResults||r.count>It)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>It)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function Ir(e,t){let r=t.parts;if(!Ge(r))return[await Dt(e,t)];let s=await Rr(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await K(e,l));n.push(Gn(e,i.join("")))}return n}function Hs(){return{expandWordAsync:xt,expandWordForGlobbing:Pr,expandWordWithBracesAsync:Ir,expandWordPartsAsync:te,expandPart:K,expandParameterAsync:ze,hasBraceExpansion:Ge,evaluateArithmetic:R,buildIfsCharClassPattern:Nn,smartWordSplit:wr}}async function _l(e,t){return Ar(e,t,Hs())}function js(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ks(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function $l(e,t){if(Ks(e,t))return{error:`bash: $@: ambiguous redirect -`};let r=t.parts,{hasQuoted:s}=ke(r);if(Ge(r)&&(await Ir(e,t)).length>1)return{error:`bash: ${r.map(d=>d.type==="Literal"?d.value:d.type==="BraceExpansion"?`{${d.items.map(g=>{if(g.type==="Range"){let E=g.step?`..${g.step}`:"";return`${g.startStr??g.start}..${g.endStr??g.end}${E}`}return g.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect -`};let n=await xt(e,t),{hasParamExpansion:a,hasCommandSub:i}=ke(r);if((a||i)&&!s&&!F(e.state.env)){let f=M(e.state.env);if(v(n,f).length>1)return{error:`bash: $${js(r)}: ambiguous redirect -`}}if(s||e.state.options.noglob)return{target:n};let o=await Pr(e,t);if(!se(o,e.state.shoptOptions.extglob))return{target:n};let u=new fe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n} -`}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect -`}}async function xt(e,t){let r=t.parts,s=r.length;if(s===1){let i=await K(e,r[0]);return de(i,e.limits.maxStringLength,"word expansion"),i}let n=[];for(let i=0;i=i)throw new W(`Command substitution nesting limit exceeded (${i})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=a+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),d=h.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=d,e.state.env.set("?",String(d)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=o,e.substitutionDepth=l;let m=h.stdout.replace(/\n+$/,"");return de(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,h instanceof W)throw h;if(h instanceof Y){e.state.lastExitCode=h.exitCode,e.state.env.set("?",String(h.exitCode)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let d=h.stdout.replace(/\n+$/,"");return de(d,e.limits.maxStringLength,"command substitution"),d}throw h}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let i=await Pn(e,n),l=new B,o=q(l,i);return String(await R(e,o.expression,!0))}return String(await R(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let a of t.items)if(a.type==="Range"){let i=wt(a.start,a.end,a.step,a.startStr,a.endStr);if(i.expanded)n.push(...i.expanded);else return i.literal}else n.push(await Dt(e,a.word));return n.join(" ")}default:return""}}async function ze(e,t,r=!1){let{parameter:s}=t,{operation:n}=t,a=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,h,d]=a;if(e.state.associativeArrays?.has(h)||d.includes("$(")||d.includes("`")||d.includes("${")){let g=await bt(e,d);s=`${h}[${g}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&T(e,s)){let h=ye(e,s);if(h&&h!==s){let d=h.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,m,g]=d;if(e.state.associativeArrays?.has(m)||g.includes("$(")||g.includes("`")||g.includes("${")){let A=await bt(e,g);s=`${m}[${A}]`}}}}let i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await D(e,s,!i);if(!n)return l;let o=!await re(e,s),{isEmpty:u,effectiveValue:c}=qn(e,s,l,r),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:r};switch(n.type){case"DefaultValue":return In(e,n,f,te);case"AssignDefault":return Dn(e,s,n,f,te);case"ErrorIfUnset":return xn(e,s,n,f,te);case"UseAlternative":return vn(e,n,f,te);case"PatternRemoval":{let h=await _n(e,l,n,te,K);return de(h,e.limits.maxStringLength,"pattern removal"),h}case"PatternReplacement":{let h=await $n(e,l,n,te,K);return de(h,e.limits.maxStringLength,"pattern replacement"),h}case"Length":return Cn(e,s,l);case"LengthSliceError":throw new ae(s);case"BadSubstitution":throw new ae(n.text);case"Substring":return On(e,s,l,n);case"CaseModification":{let h=await Ln(e,l,n,te,ze);return de(h,e.limits.maxStringLength,"case modification"),h}case"Transform":return Wn(e,s,l,o,n);case"Indirection":return Tn(e,s,l,o,n,ze,r);case"ArrayKeys":return Mn(e,n);case"VarNamePrefix":return Vn(e,n);default:return l}}export{Vi as a,qi as b,Ee as c,U as d,q as e,B as f,Ni as g,Et as h,Fi as i,At as j,zi as k,wn as l,M as m,Qi as n,Zi as o,T as p,Hi as q,ji as r,Ki as s,Xi as t,ys as u,ye as v,Pe as w,Ji as x,P as y,Re as z,D as A,ee as B,kt as C,wa as D,Pt as E,Na as F,ka as G,Pa as H,Dl as I,Dt as J,xl as K,vl as L,_l as M,Ks as N,$l as O,R as P}; diff --git a/packages/just-bash/dist/bin/shell/chunks/chunk-FJABJBIW.js b/packages/just-bash/dist/bin/shell/chunks/chunk-RO3XCUVQ.js similarity index 99% rename from packages/just-bash/dist/bin/shell/chunks/chunk-FJABJBIW.js rename to packages/just-bash/dist/bin/shell/chunks/chunk-RO3XCUVQ.js index 6dffab95..c52930ba 100644 --- a/packages/just-bash/dist/bin/shell/chunks/chunk-FJABJBIW.js +++ b/packages/just-bash/dist/bin/shell/chunks/chunk-RO3XCUVQ.js @@ -1,6 +1,6 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a as F,b,c as M,d as He,e as w,f as v,g as Y,h as Z}from"./chunk-NXYVRP6D.js";import{a as st}from"./chunk-MNWK4UIM.js";import{a as $}from"./chunk-LMA4D2KK.js";import{f as qe,g as X}from"./chunk-MLUOPG3W.js";import{a as J}from"./chunk-52FZYTIX.js";import{a as _e}from"./chunk-ZZP3RSWL.js";import{a as _}from"./chunk-DHIKZU63.js";import{a as D,b as G}from"./chunk-MUFNRCMY.js";import{b as We,d as et,e as tt,f as nt}from"./chunk-LNVSXNT7.js";var q,Je=We(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let r=new Map([["(","("],[")",")"],["[","["],["]","]"],["{","{"],["}","}"],[",",","],[":",":"],[";",";"],["+","+"],["-","-"],["*","*"],["%","%"],["<","<"],[">",">"],["!","!"],[".","."],["|","|"],["=","="]]).get(t);if(r!==void 0)return this.pos++,{type:r,value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.posH,parseNamedExpressions:()=>U});function U(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},a=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){a();continue}let d=[],u=0,p=r;for(;o().type!=="eof";){let i=o();if((i.type===","||i.type==="as")&&u===0)break;(i.type==="("||i.type==="["||i.type==="{")&&u++,(i.type===")"||i.type==="]"||i.type==="}")&&u--,d.push(a())}d.push({type:"eof",value:"",pos:0});let h=new z(d).parse(),l;if(o().type==="as")if(a(),o().type==="("){a();let i=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(i.push(o().value),a()),o().type===","&&a();o().type===")"&&a(),l=i}else if(o().type==="ident"||o().type==="string")l=o().value,a();else throw new Error(`Expected name after 'as', got ${o().type}`);else l=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),h.type==="identifier"&&(l=h.name);n.push({expr:h,name:l})}return n}function H(e){let t=new q(e).tokenize();return new z(t).parse()}var R,z,V=We(()=>{"use strict";Je();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},z=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=this.pos;if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=[this.peek().value];this.advance();let o=!0;for(;this.peek().type===",";)if(this.advance(),this.peek().type==="ident")r.push(this.peek().value),this.advance();else{o=!1;break}if(o&&this.peek().type===")"&&this.peekAt(1).type==="=>"){this.advance(),this.advance();let a=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:r,body:a},r)}this.pos=t}let s=this.parseExpr(0);return this.expect(")"),s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,a=this.pos+1;a0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let a=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:n},{expr:a}]}}if(s.type==="|"){this.advance();let a=this.parseExpr(t);return this.handlePipe(n,a)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}peekAt(n){return this.tokens[this.pos+n]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});V();function E(e,n){return n.length===0?I(e,[]):n.length===1?{type:"Pipe",left:n[0],right:I(e,[])}:{type:"Pipe",left:n[0],right:I(e,n.slice(1))}}var K={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>I("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?I("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?I("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?I("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>I("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>I("select",e),empty:()=>I("empty",[]),count:()=>I("length",[]),sum:e=>e.length===0?I("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:I("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",I("add",[]),I("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",I("add",[]),I("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?I("tonumber",[]):I("tonumber",e),tostring:e=>e.length===0?I("tostring",[]):I("tostring",e),if:e=>Ke(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return Ke(s,n,t.length===1?t[0]:K.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>I("now",[]),fmt:e=>I("tostring",e),format:e=>I("tostring",e)};Object.setPrototypeOf(K,null);function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function I(e,n){return{type:"Call",name:e,args:n}}var rt="then";function Ke(e,n,t){let s=qe({type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}});return s[rt]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function O(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>O(r.expr,n)),s=Object.hasOwn(K,e.name)?K[e.name]:void 0;return typeof s=="function"?s(t):I(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=O(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:O(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?O(e.start,n):void 0,end:e.end?O(e.end,n):void 0};case"lambda":return O(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function ee(e){let n=[],t=0;for(;t=e.length)break;let s=t;for(;t0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let d=e.slice(a,t).trim();for(t++;t0?r[0]:null}function te(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Be(r)?o=e.map(a=>a[r]).filter(a=>a!=null):o=e.map(a=>Q(a,r,t)).filter(a=>a!=null),s){case"count":return Be(r)?o.length:o.filter(a=>!!a).length;case"sum":return o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d))).reduce((d,u)=>d+u,0);case"mean":case"avg":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?a.reduce((d,u)=>d+u,0)/a.length:0}case"min":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.min(...a):null}case"max":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.max(...a):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let a=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(a.length===0)return null;let d=Math.floor(a.length/2);return a.length%2===0?(a[d-1]+a[d])/2:a[d]}case"mode":{let a=new Map;for(let p of o){let c=String(p);a.set(c,(a.get(c)||0)+1)}let d=0,u=null;for(let[p,c]of a)c>d&&(d=c,u=p);return u}case"cardinality":return new Set(o.map(d=>String(d))).size;case"values":return o.map(a=>String(a)).join("|");case"distinct_values":return[...new Set(o.map(d=>String(d)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let a of e)if(!Q(a,r,t))return!1;return!0}case"any":{for(let a of e)if(Q(a,r,t))return!0;return!1}default:return null}}function Ge(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,te(e,r,t));return s}async function ne(e,n){let t="",s=[];for(let c of e)c.startsWith("-")||(t?s.push(c):t=c);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression diff --git a/packages/just-bash/dist/bin/shell/chunks/expansion-PCODPDNZ.js b/packages/just-bash/dist/bin/shell/chunks/expansion-PCODPDNZ.js deleted file mode 100644 index 3317f47d..00000000 --- a/packages/just-bash/dist/bin/shell/chunks/expansion-PCODPDNZ.js +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{A as c,B as d,C as e,I as f,J as g,K as h,L as i,M as j,N as k,O as l,y as a,z as b}from"./chunk-PDS5TEMS.js";import"./chunk-52FZYTIX.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-LNVSXNT7.js";export{d as escapeGlobChars,e as escapeRegexChars,l as expandRedirectTarget,g as expandWord,i as expandWordForPattern,h as expandWordForRegex,j as expandWordWithGlob,a as getArrayElements,c as getVariable,k as hasQuotedMultiValueAt,b as isArray,f as isWordFullyQuoted}; diff --git a/packages/just-bash/dist/bin/shell/chunks/flag-coverage-DFXMJJWX.js b/packages/just-bash/dist/bin/shell/chunks/flag-coverage-K737BGC5.js similarity index 94% rename from packages/just-bash/dist/bin/shell/chunks/flag-coverage-DFXMJJWX.js rename to packages/just-bash/dist/bin/shell/chunks/flag-coverage-K737BGC5.js index f5d2b8c5..888b18db 100644 --- a/packages/just-bash/dist/bin/shell/chunks/flag-coverage-DFXMJJWX.js +++ b/packages/just-bash/dist/bin/shell/chunks/flag-coverage-K737BGC5.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{b as yr}from"./chunk-Y5OWCEDV.js";import{b as Ar}from"./chunk-J7XTZ47D.js";import{b as $r}from"./chunk-FJABJBIW.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import{c as Sr}from"./chunk-BTZKLEUT.js";import{b as wr}from"./chunk-WHUKZ3K3.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-MP77TJMM.js";import{d as Ir,e as Mr,f as jr}from"./chunk-BPZJYOUA.js";import{b as tr}from"./chunk-TKYWUEON.js";import{b as lr}from"./chunk-ZFUVUYWG.js";import{b as ur}from"./chunk-XPTYN6UE.js";import{b as pr}from"./chunk-W5OBQVJ2.js";import{b as er}from"./chunk-PKE7GKU5.js";import{b as dr}from"./chunk-JSZBZ2XU.js";import{b as cr}from"./chunk-7HK63L6Y.js";import"./chunk-HWNCK5BB.js";import{b as hr}from"./chunk-BZP56QBM.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-OVVMB2JI.js";import{b as mr}from"./chunk-4J4UC7OD.js";import"./chunk-LMA4D2KK.js";import{b as Fr}from"./chunk-6WJQNLR2.js";import{b as zr}from"./chunk-R36DS2UF.js";import{b as fr}from"./chunk-7NDRU2ZN.js";import{b as nr}from"./chunk-CX5CEEGI.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-WDWNEHHE.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-FYCT4DWY.js";import{b as G}from"./chunk-KMZUSEWI.js";import{b as H}from"./chunk-MTK7VLZG.js";import{b as J}from"./chunk-7VCQWCSH.js";import{b as K}from"./chunk-6JKLDBRW.js";import{b as L}from"./chunk-2ZAK22BG.js";import{b as O}from"./chunk-IX7LKVVH.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-JDFKEXLG.js";import{b as y}from"./chunk-PSJORJRS.js";import{b as A}from"./chunk-NMMVECGD.js";import{b as $}from"./chunk-RKBWTGBZ.js";import{b as S}from"./chunk-G7ZWT7BT.js";import{b as T}from"./chunk-C6JOQKE2.js";import{b as B}from"./chunk-AFAD5U2A.js";import{b as D}from"./chunk-FEENTUVZ.js";import{b as E}from"./chunk-JJC4ENJL.js";import{b as w}from"./chunk-RVGYO2OU.js";import{b as x}from"./chunk-OXZSG3ZZ.js";import{b as v}from"./chunk-UOMNSQEZ.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-Y2IUEWQD.js";import"./chunk-DWECIBLJ.js";import{b}from"./chunk-GXX3QUMM.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import{b as I}from"./chunk-TIRU5FOD.js";import{b as M}from"./chunk-D7YFPDMV.js";import{b as j}from"./chunk-KWCO3YXP.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-2AIXTPH2.js";import{b as u}from"./chunk-3WIMLJM7.js";import{b as p}from"./chunk-2GG3NVC4.js";import{b as e}from"./chunk-XHCCSVP6.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-XRUDFQG5.js";import{b as h}from"./chunk-6FYCU7QB.js";import"./chunk-N3FQJLPZ.js";import"./chunk-NYIPFY36.js";import"./chunk-UNWZQG7U.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import{b as i}from"./chunk-XBB73LFB.js";import{b as g}from"./chunk-GTO74SFS.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import{b as m}from"./chunk-HMCRB24D.js";import"./chunk-4BNS566Q.js";import"./chunk-JXLDT4KX.js";import"./chunk-47WZ2U6M.js";import{b as F}from"./chunk-N6YW4W3Z.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import"./chunk-PBOVSFTJ.js";import{b as f}from"./chunk-5XSZHUEI.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage}; +import{b as yr}from"./chunk-Y5OWCEDV.js";import{b as Ar}from"./chunk-HZR3FOJM.js";import{b as $r}from"./chunk-RO3XCUVQ.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import{c as Sr}from"./chunk-BTZKLEUT.js";import{b as wr}from"./chunk-WHUKZ3K3.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-MP77TJMM.js";import{d as Ir,e as Mr,f as jr}from"./chunk-BPZJYOUA.js";import{b as tr}from"./chunk-TKYWUEON.js";import{b as lr}from"./chunk-ZFUVUYWG.js";import{b as ur}from"./chunk-XPTYN6UE.js";import{b as pr}from"./chunk-W5OBQVJ2.js";import{b as er}from"./chunk-PKE7GKU5.js";import{b as dr}from"./chunk-JSZBZ2XU.js";import{b as cr}from"./chunk-7HK63L6Y.js";import"./chunk-HWNCK5BB.js";import{b as hr}from"./chunk-BZP56QBM.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-OVVMB2JI.js";import{b as mr}from"./chunk-63LSI3D6.js";import"./chunk-ISLENKSH.js";import{b as Fr}from"./chunk-6WJQNLR2.js";import{b as zr}from"./chunk-R36DS2UF.js";import{b as fr}from"./chunk-7NDRU2ZN.js";import{b as nr}from"./chunk-CX5CEEGI.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-WDWNEHHE.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-FYCT4DWY.js";import{b as G}from"./chunk-KMZUSEWI.js";import{b as H}from"./chunk-MTK7VLZG.js";import{b as J}from"./chunk-7VCQWCSH.js";import{b as K}from"./chunk-6JKLDBRW.js";import{b as L}from"./chunk-2ZAK22BG.js";import{b as O}from"./chunk-IX7LKVVH.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-JDFKEXLG.js";import{b as y}from"./chunk-PSJORJRS.js";import{b as A}from"./chunk-NMMVECGD.js";import{b as $}from"./chunk-RKBWTGBZ.js";import{b as S}from"./chunk-G7ZWT7BT.js";import{b as T}from"./chunk-C6JOQKE2.js";import{b as B}from"./chunk-AFAD5U2A.js";import{b as D}from"./chunk-FEENTUVZ.js";import{b as E}from"./chunk-JJC4ENJL.js";import{b as w}from"./chunk-RVGYO2OU.js";import{b as x}from"./chunk-OXZSG3ZZ.js";import{b as v}from"./chunk-UOMNSQEZ.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-Y2IUEWQD.js";import"./chunk-DWECIBLJ.js";import{b}from"./chunk-BKQLXMS6.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import{b as I}from"./chunk-TIRU5FOD.js";import{b as M}from"./chunk-D7YFPDMV.js";import{b as j}from"./chunk-KWCO3YXP.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-2AIXTPH2.js";import{b as u}from"./chunk-3WIMLJM7.js";import{b as p}from"./chunk-2GG3NVC4.js";import{b as e}from"./chunk-XHCCSVP6.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-XRUDFQG5.js";import{b as h}from"./chunk-6FYCU7QB.js";import"./chunk-N3FQJLPZ.js";import"./chunk-NYIPFY36.js";import"./chunk-UNWZQG7U.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import{b as i}from"./chunk-XBB73LFB.js";import{b as g}from"./chunk-GTO74SFS.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import{b as m}from"./chunk-HMCRB24D.js";import"./chunk-4BNS566Q.js";import"./chunk-JXLDT4KX.js";import"./chunk-47WZ2U6M.js";import{b as F}from"./chunk-N6YW4W3Z.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import"./chunk-PBOVSFTJ.js";import{b as f}from"./chunk-5XSZHUEI.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage}; diff --git a/packages/just-bash/dist/bin/shell/chunks/jq-33GJJXTL.js b/packages/just-bash/dist/bin/shell/chunks/jq-3V5HDGLJ.js similarity index 88% rename from packages/just-bash/dist/bin/shell/chunks/jq-33GJJXTL.js rename to packages/just-bash/dist/bin/shell/chunks/jq-3V5HDGLJ.js index 97bbc75f..f1fc9fd5 100644 --- a/packages/just-bash/dist/bin/shell/chunks/jq-33GJJXTL.js +++ b/packages/just-bash/dist/bin/shell/chunks/jq-3V5HDGLJ.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-4J4UC7OD.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as jqCommand}; +import{a,b}from"./chunk-63LSI3D6.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as jqCommand}; diff --git a/packages/just-bash/dist/bin/chunks/rg-2YWJS6TE.js b/packages/just-bash/dist/bin/shell/chunks/rg-DZKA632H.js similarity index 83% rename from packages/just-bash/dist/bin/chunks/rg-2YWJS6TE.js rename to packages/just-bash/dist/bin/shell/chunks/rg-DZKA632H.js index fd2f6b21..3f7b0b10 100644 --- a/packages/just-bash/dist/bin/chunks/rg-2YWJS6TE.js +++ b/packages/just-bash/dist/bin/shell/chunks/rg-DZKA632H.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-GXX3QUMM.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as rgCommand}; +import{a,b}from"./chunk-BKQLXMS6.js";import"./chunk-MLUOPG3W.js";import"./chunk-3MRB66F4.js";import"./chunk-UI7CV277.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as rgCommand}; diff --git a/packages/just-bash/dist/bin/chunks/xan-TSDTZVY3.js b/packages/just-bash/dist/bin/shell/chunks/xan-TCTFON2Q.js similarity index 77% rename from packages/just-bash/dist/bin/chunks/xan-TSDTZVY3.js rename to packages/just-bash/dist/bin/shell/chunks/xan-TCTFON2Q.js index bc0e6eb0..787fa2df 100644 --- a/packages/just-bash/dist/bin/chunks/xan-TSDTZVY3.js +++ b/packages/just-bash/dist/bin/shell/chunks/xan-TCTFON2Q.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-FJABJBIW.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as xanCommand}; +import{a,b}from"./chunk-RO3XCUVQ.js";import"./chunk-NXYVRP6D.js";import"./chunk-MNWK4UIM.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-ZZP3RSWL.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-7JZKVC3F.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as xanCommand}; diff --git a/packages/just-bash/dist/bin/shell/chunks/yq-KU5YTNAK.js b/packages/just-bash/dist/bin/shell/chunks/yq-OB6PB5GY.js similarity index 75% rename from packages/just-bash/dist/bin/shell/chunks/yq-KU5YTNAK.js rename to packages/just-bash/dist/bin/shell/chunks/yq-OB6PB5GY.js index 8c307a62..321fab36 100644 --- a/packages/just-bash/dist/bin/shell/chunks/yq-KU5YTNAK.js +++ b/packages/just-bash/dist/bin/shell/chunks/yq-OB6PB5GY.js @@ -1,3 +1,3 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{a,b}from"./chunk-J7XTZ47D.js";import"./chunk-MNWK4UIM.js";import"./chunk-LMA4D2KK.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as yqCommand}; +import{a,b}from"./chunk-HZR3FOJM.js";import"./chunk-MNWK4UIM.js";import"./chunk-ISLENKSH.js";import"./chunk-MLUOPG3W.js";import"./chunk-MROECM42.js";import"./chunk-AZH64XMJ.js";import"./chunk-LX2H4DPL.js";import"./chunk-52FZYTIX.js";import"./chunk-DHIKZU63.js";import"./chunk-47WZ2U6M.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-LNVSXNT7.js";export{b as flagsForFuzzing,a as yqCommand}; diff --git a/packages/just-bash/dist/bin/shell/shell.js b/packages/just-bash/dist/bin/shell/shell.js index 14a7108f..b543f901 100644 --- a/packages/just-bash/dist/bin/shell/shell.js +++ b/packages/just-bash/dist/bin/shell/shell.js @@ -1,159 +1,233 @@ #!/usr/bin/env node import{createRequire} from"node:module";const require=createRequire(import.meta.url); -import{B as Gn,C as Kn,D as ue,E as Ze,F as ee,G as Ae,H as Ft,I as Xn,J as I,K as Yn,L as Qn,M as ke,N as ks,O as Mt,P as j,a as zn,b as $s,c as Vn,d as Rt,e as Q,f as V,g as Ee,h as ne,i as Ce,j as Me,k as Es,l as Lt,m as Bn,n as Ss,o as jn,p as ge,q as Ie,r as Hn,s as Un,t as As,u as _s,v as We,w as Zn,x as qn,y as Se,z as Cs}from"./chunks/chunk-PDS5TEMS.js";import{a as et,b as tt,c as Fe}from"./chunks/chunk-O2BCKSMK.js";import{c as bs}from"./chunks/chunk-NYIPFY36.js";import{a as xn,b as Rn}from"./chunks/chunk-UNWZQG7U.js";import{a as Le,b as ye,c as vs}from"./chunks/chunk-MROECM42.js";import{a as yt,b as Wn}from"./chunks/chunk-AZH64XMJ.js";import{a as Je,b as be}from"./chunks/chunk-LX2H4DPL.js";import{a as mt}from"./chunks/chunk-52FZYTIX.js";import{b as He,d as Ln,e as gs,f as ws}from"./chunks/chunk-DHIKZU63.js";import{a as de,b as he,c as ce,d as pe,e as Fn,f as B,g as Ue,h as Dt,i as Tt,j as Mn,k as Y,l as It,m as Re,n as xt,o as me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as Te}from"./chunks/chunk-PBOVSFTJ.js";import{a as $e}from"./chunks/chunk-I4IRHQDW.js";import{a as In}from"./chunks/chunk-LNVSXNT7.js";import*as Gi from"node:fs";import*as Ki from"node:readline";var st=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-2YWJS6TE.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-33GJJXTL.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(st.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),st.push({name:"yq",load:async()=>(await import("./chunks/yq-KU5YTNAK.js")).yqCommand}),st.push({name:"xan",load:async()=>(await import("./chunks/xan-TSDTZVY3.js")).xanCommand}),st.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-2ZD7O55W.js")).sqlite3Command}));var Ps=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ps.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),Ps.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var Ns=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ns.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),Ns.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var Ji=[{name:"curl",load:async()=>(await import("./chunks/curl-VWGTXT4F.js")).curlCommand}],Jn=new Map;function Wt(e){return{name:e.name,async execute(t,s){let n=Jn.get(e.name);if(n||(n=await be.runTrustedAsync(()=>e.load()),Jn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-DFXMJJWX.js");r(s.coverage,e.name,t)}return n.execute(t,s)}}}function er(e){return(e?st.filter(s=>e.includes(s.name)):st).map(Wt)}function tr(){return Ji.map(Wt)}function sr(){return Ps.map(Wt)}function nr(){return Ns.map(Wt)}function rr(e){return"load"in e&&typeof e.load=="function"}function ir(e){let t=null;return{name:e.name,trusted:!0,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}function L(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(r=>r&&r!=="."),n=[];for(let r of s)r===".."?n.pop():n.push(r);return`/${n.join("/")}`||"/"}function W(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function qe(e){let t=L(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function zt(e,t){if(t.startsWith("/"))return L(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return L(s)}function gt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function nt(e,t){if(t.startsWith("/"))return L(t);let s=qe(e);return L(gt(s,t))}var rt=new TextEncoder;function ea(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var wt=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))typeof n=="function"?this.writeFileLazy(s,n):ea(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}ensureParentDirs(t){let s=qe(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){W(t,"write");let i=L(t);this.ensureParentDirs(i);let a=Fe(n),o=et(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}writeFileLazy(t,s,n){W(t,"write");let r=L(t);this.ensureParentDirs(r),this.data.set(r,{type:"file",lazy:s,mode:n?.mode??420,mtime:n?.mtime??new Date})}async materializeLazy(t,s){let n=await s.lazy(),i={type:"file",content:typeof n=="string"?rt.encode(n):n,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let n=await this.readFileBuffer(t),r=Fe(s);return tt(n,r)}async readFileBytes(t){let s=await this.readFileBuffer(t);return tt(s,"binary")}async readFileBuffer(t){W(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in n){let r=await this.materializeLazy(s,n);return r.content instanceof Uint8Array?r.content:rt.encode(r.content)}return n.content instanceof Uint8Array?n.content:rt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){W(t,"append");let r=L(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=Fe(n),o=et(s,a);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(r,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:rt.encode("content"in l?l.content:""),c=new Uint8Array(u.length+o.length);c.set(u),c.set(o,u.length),this.data.set(r,{type:"file",content:c,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){W(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=rt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){W(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=rt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveIntermediateSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),l=0,u=40;for(;o&&o.type==="symlink"&&l=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){W(t,"mkdir");let n=L(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=qe(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){W(t,"scandir");let s=L(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=nt(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==s&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.namel.name?1:0)}async rm(t,s){W(t,"rm");let n=L(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=gt(n,a);await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){W(t,"cp"),W(s,"cp");let r=L(t),i=L(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let o=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:o})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let l of o){let u=gt(r,l),c=gt(i,l);await this.cp(u,c,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return zt(t,s)}async chmod(t,s){W(t,"chmod");let n=L(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){W(s,"symlink");let n=L(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){W(t,"link"),W(s,"link");let n=L(t),r=L(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(n,a)),this.ensureParentDirs(r),this.data.set(r,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){W(t,"readlink");let s=L(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){W(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){W(t,"utimes");let r=L(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function ta(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function sa(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function na(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function ra(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${zn} +import{a as Rt,b as xt,c as ht}from"./chunks/chunk-O2BCKSMK.js";import{c as An}from"./chunks/chunk-NYIPFY36.js";import{a as hi,b as pi}from"./chunks/chunk-UNWZQG7U.js";import{a as dt,b as Fe,c as Sn}from"./chunks/chunk-MROECM42.js";import{a as Xt,b as gi}from"./chunks/chunk-AZH64XMJ.js";import{a as Ct,b as Be}from"./chunks/chunk-LX2H4DPL.js";import{a as ae}from"./chunks/chunk-52FZYTIX.js";import{b as At,d as mi,e as bn,f as vn}from"./chunks/chunk-DHIKZU63.js";import{a as Ie,b as Ce,c as Ne,d as We,e as Re,f as U,g as te,h as xe,i as ut,j as ws,k as Q,l as Es,m as ft,n as bs,o as Me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as at}from"./chunks/chunk-PBOVSFTJ.js";import{a as qe}from"./chunks/chunk-I4IRHQDW.js";import{a as di}from"./chunks/chunk-LNVSXNT7.js";import*as mc from"node:fs";import*as gc from"node:readline";var Ot=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-DZKA632H.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-3V5HDGLJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ot.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),Ot.push({name:"yq",load:async()=>(await import("./chunks/yq-OB6PB5GY.js")).yqCommand}),Ot.push({name:"xan",load:async()=>(await import("./chunks/xan-TCTFON2Q.js")).xanCommand}),Ot.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-2ZD7O55W.js")).sqlite3Command}));var $n=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&($n.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),$n.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var Nn=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Nn.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),Nn.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var bc=[{name:"curl",load:async()=>(await import("./chunks/curl-VWGTXT4F.js")).curlCommand}],yi=new Map;function vs(e){return{name:e.name,async execute(t,s){let r=yi.get(e.name);if(r||(r=await Be.runTrustedAsync(()=>e.load()),yi.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-K737BGC5.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function wi(e){return(e?Ot.filter(s=>e.includes(s.name)):Ot).map(vs)}function Ei(){return bc.map(vs)}function bi(){return $n.map(vs)}function vi(){return Nn.map(vs)}function Si(e){return"load"in e&&typeof e.load=="function"}function Ai(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}function B(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(n=>n&&n!=="."),r=[];for(let n of s)n===".."?r.pop():r.push(n);return`/${r.join("/")}`||"/"}function K(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function $t(e){let t=B(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function Ss(e,t){if(t.startsWith("/"))return B(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return B(s)}function Yt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function Tt(e,t){if(t.startsWith("/"))return B(t);let s=$t(e);return B(Yt(s,t))}var Lt=new TextEncoder;function vc(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Jt=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):vc(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=$t(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){K(t,"write");let i=B(t);this.ensureParentDirs(i);let a=ht(r),l=Rt(s,a);this.data.set(i,{type:"file",content:l,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){K(t,"write");let n=B(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?Lt.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=ht(s);return xt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return xt(s,"binary")}async readFileBuffer(t){K(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:Lt.encode(n.content)}return r.content instanceof Uint8Array?r.content:Lt.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){K(t,"append");let n=B(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=ht(r),l=Rt(s,a);if(i?.type==="file"){let o=i;"lazy"in o&&(o=await this.materializeLazy(n,o));let u="content"in o&&o.content instanceof Uint8Array?o.content:Lt.encode("content"in o?o.content:""),c=new Uint8Array(u.length+l.length);c.set(u),c.set(l,u.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){K(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){K(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let a=0;a=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let a of r){n=`${n}/${a}`;let l=this.data.get(n),o=0,u=40;for(;l&&l.type==="symlink"&&o=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){K(t,"mkdir");let r=B(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=$t(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){K(t,"scandir");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=Tt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[l,o]of this.data.entries())if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}return Array.from(a.values()).sort((l,o)=>l.nameo.name?1:0)}async rm(t,s){K(t,"rm");let r=B(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let l=Yt(r,a);await this.rm(l,s)}}}this.data.delete(r)}async cp(t,s,r){K(t,"cp"),K(s,"cp");let n=B(t),i=B(s),a=this.data.get(n);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let l=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:l})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(n);for(let o of l){let u=Yt(n,o),c=Yt(i,o);await this.cp(u,c,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Ss(t,s)}async chmod(t,s){K(t,"chmod");let r=B(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){K(s,"symlink");let r=B(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){K(t,"link"),K(s,"link");let r=B(t),n=B(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(r,a)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){K(t,"readlink");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){K(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){K(t,"utimes");let n=B(t),i=this.resolvePathWithSymlinks(n),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var Ni="5.1.0(1)-release",ki="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function _n(e){let{pid:t,ppid:s,uid:r,gid:n}=e;return`Name: bash +State: R (running) +Pid: ${t} +PPid: ${s} +Uid: ${r} ${r} ${r} ${r} +Gid: ${n} ${n} ${n} ${n} +`}function Sc(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Ac(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function $c(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Nc(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${ki} `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash -`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>$s(t)):e.writeFileSync("/proc/self/status",$s(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function or(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){ta(e)&&(sa(e,t),na(e),ra(e,s))}var ia=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],aa=["braceexpand","hashall","interactive-comments"];function Ds(e){let t=[],s=[...aa.map(n=>({name:n,enabled:!0})),...ia.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function at(e){e.state.env.set("SHELLOPTS",Ds(e.state.options))}var oa=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ts(e){let t=[];for(let s of oa)e[s]&&t.push(s);return t.join(":")}function Is(e){e.state.env.set("BASHOPTS",Ts(e.state.shoptOptions))}var la="BASH_ALIAS_";function lr(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function cr(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ur(e,t){return e.env.get(`${la}${t}`)}function xs(e,t,s){if(!t.name||!lr(t.name))return t;let n=cr(t.name);if(!n)return t;let r=ur(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new V,a=r,o=r.endsWith(" ");if(!o)for(let f of t.args){let d=dr(f);a+=` ${d}`}let l;try{l=i.parse(a)}catch(f){if(f instanceof Rt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return fr(t,r);let u=l.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return fr(t,r);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(lr(f)){let d=cr(f);if(d&&ur(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},y=xs(e,h,s);y!==h&&(c={...c,name:y.name,args:[...y.args]})}}}return c}catch(i){throw s.delete(n),i}}function fr(e,t){let s=t;for(let a of e.args){let o=dr(a);s+=` ${o}`}let n=new V,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function dr(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function hr(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",l=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||l)&&(i.push(o),o="",l=!1):h&&(o+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=Lt({type:"Word",parts:[c]});else{(o||l)&&(i.push(o),o="",l=!1);let d=await ke(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(l=!0);let f=await I(e,{type:"Word",parts:[c]});o+=f}(o||l)&&i.push(o);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${r}=(${u.join(" ")})`}async function pr(e,t){let s=-1,n=-1,r=!1;for(let p=0;p0?await I(e,d):"";return`${f}${r?"+=":"="}${h}`}var ca=["tar","yq","xan","sqlite3","python3","python"];function mr(e){return ca.includes(e)}var M=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function k(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function X(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Pe(e,t,s="",n=""){throw new Y(e,t,s,n)}function ae(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Y(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Rs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Re;return M}if(t.length>1)throw new B(1,"",`bash: break: too many arguments -`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(128,"",`bash: break: ${t[0]}: numeric argument required -`);s=n}throw new de(s)}async function Ls(e,t){let s,n=!1,r=!1,i=0;for(;ih);for(let h of d){let y=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(y)).isDirectory){s=y,n=!0;break}}catch{}}}}let l=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${s}: Not a directory +`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>_n(t)):e.writeFileSync("/proc/self/status",_n(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function _i(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){Sc(e)&&(Ac(e,t),$c(e),Nc(e,s))}var kc=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],_c=["braceexpand","hashall","interactive-comments"];function Pn(e){let t=[],s=[..._c.map(r=>({name:r,enabled:!0})),...kc.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function Mt(e){e.state.env.set("SHELLOPTS",Pn(e.state.options))}var Pc=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Dn(e){let t=[];for(let s of Pc)e[s]&&t.push(s);return t.join(":")}function In(e){e.state.env.set("BASHOPTS",Dn(e.state.shoptOptions))}var x={script(e){return{type:"Script",statements:e}},statement(e,t=[],s=!1,r,n){let i={type:"Statement",pipelines:e,operators:t,background:s};return r&&(i.deferredError=r),n!==void 0&&(i.sourceText=n),i},pipeline(e,t=!1,s=!1,r=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:s,timePosix:r,pipeStderr:n}},simpleCommand(e,t=[],s=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:s,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,s=!1,r=null){return{type:"Assignment",name:e,value:t,append:s,array:r}},redirection(e,t,s=null,r){let n={type:"Redirection",fd:s,operator:e,target:t};return r&&(n.fdVariable=r),n},hereDoc(e,t,s=!1,r=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:s,quoted:r}},ifNode(e,t=null,s=[]){return{type:"If",clauses:e,elseBody:t,redirections:s}},forNode(e,t,s,r=[]){return{type:"For",variable:e,words:t,body:s,redirections:r}},whileNode(e,t,s=[]){return{type:"While",condition:e,body:t,redirections:s}},untilNode(e,t,s=[]){return{type:"Until",condition:e,body:t,redirections:s}},caseNode(e,t,s=[]){return{type:"Case",word:e,items:t,redirections:s}},caseItem(e,t,s=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:s}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,s=[],r){return{type:"FunctionDef",name:e,body:t,redirections:s,sourceFile:r}},conditionalCommand(e,t=[],s){return{type:"ConditionalCommand",expression:e,redirections:t,line:s}},arithmeticCommand(e,t=[],s){return{type:"ArithmeticCommand",expression:e,redirections:t,line:s}}};function Pi(e,t){let s=e.length,r=t+3,n=2,i=!1,a=!1;for(;r0;){let l=e[r];if(i){l==="'"&&(i=!1),r++;continue}if(a){if(l==="\\"){r+=2;continue}l==='"'&&(a=!1),r++;continue}if(l==="'"){i=!0,r++;continue}if(l==='"'){a=!0,r++;continue}if(l==="\\"){r+=2;continue}if(l==="("){n++,r++;continue}if(l===")"){if(n--,n===1){let o=r+1;return!(oi===" "||i===" "||i===` +`||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r=e.length)return e.length;let a=e.indexOf(` +`,r);a===-1&&(a=e.length);let l=e.slice(r,a);if(i&&(l=l.replace(/^\t+/,"")),l===n){r=a+1;break}if(a>=e.length)return e.length;r=a+1}return Math.min(r,e.length)}function Di(e,t,s,r){let n=t+2,i=1,a=n,l=!1,o=!1,u=0,c=!1,f="",d=[],h=0;for(;a0;){let b=e[a];if(l)b==="'"&&(l=!1);else if(o)b==="\\"&&a+10&&h--,h===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let v=a+2,E=!1;for(e[v]==="-"&&(E=!0,v++);e[v]===" "||e[v]===" ";)v++;let{delim:w,endPos:S}=Cn(e,v);if(w.length>0){d.push({delim:w,stripTabs:E}),f="",a=S;continue}}if(b===` +`&&d.length>0){let v=Dc(e,a,d);d.length=0,f="",a=v;continue}b==="'"?(l=!0,f=""):b==='"'?(o=!0,f=""):b==="\\"&&a+10?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:c||i++:b===")"?c?c=!1:i--:b===";"&&u>0&&a+10&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let p=e.slice(n,a),y=s().parse(p);return{part:x.commandSubstitution(y,!1),endIndex:a+1}}function Ii(e,t,s,r,n){let a=t+1,l="";for(;a=e.length&&n("unexpected EOF while looking for matching ``'");let u=r().parse(l);return{part:x.commandSubstitution(u,!0),endIndex:a+1}}var Ic=10485760,g;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(g||(g={}));var pt=class extends Error{line;column;constructor(t,s,r){super(`line ${s}: ${t}`),this.line=s,this.column=r,this.name="LexerError"}},Ci=new Map([["if",g.IF],["then",g.THEN],["else",g.ELSE],["elif",g.ELIF],["fi",g.FI],["for",g.FOR],["while",g.WHILE],["until",g.UNTIL],["do",g.DO],["done",g.DONE],["case",g.CASE],["esac",g.ESAC],["in",g.IN],["function",g.FUNCTION],["select",g.SELECT],["time",g.TIME],["coproc",g.COPROC]]);function Ri(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let s=e.slice(t[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n=s.length)return!1;let i=s.slice(n+1);return i===""||i==="+"}return!1}function xi(e){let t=0;for(let s=0;s",">",g.AND_DGREAT]],Rc=[["[","[",g.DBRACK_START],["]","]",g.DBRACK_END],["(","(",g.DPAREN_START],[")",")",g.DPAREN_END],["&","&",g.AND_AND],["|","|",g.OR_OR],[";",";",g.DSEMI],[";","&",g.SEMI_AND],["|","&",g.PIPE_AMP],[">",">",g.DGREAT],["<","&",g.LESSAND],[">","&",g.GREATAND],["<",">",g.LESSGREAT],[">","|",g.CLOBBER],["&",">",g.AND_GREAT]],xc=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function Oc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Oi(e){return e===" "||e===" "||e===` +`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var $s=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,s){this.input=t,this.maxHeredocSize=s?.maxHeredocSize??Ic}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=s)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,s=t.length,r=this.pos,n=this.column,i=this.line;for(;r0?(this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n)):this.looksLikeNestedSubshells(s+2)||this.dparenClosesWithSpacedParens(s+2)?(this.pos=s+1,this.column=n+1,this.makeToken(g.LPAREN,"(",s,r,n)):(this.pos=s+2,this.column=n+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",s,r,n));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=s+2,this.column=n+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",s,r,n)):this.dparenDepth>1?(this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.RPAREN,")",s,r,n));for(let[u,c,f]of Rc)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===g.DSEMI||f===g.SEMI_AND||f===g.SEMI_SEMI_AND))&&i===u&&a===c){if(f===g.DBRACK_START||f===g.DBRACK_END){let d=t[s+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==` +`&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=s+2,this.column=n+2,this.makeToken(f,u+c,s,r,n)}if(i==="("&&this.dparenDepth>0)return this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n);if(i===")"&&this.dparenDepth>1)return this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n);let o=xc.get(i);if(o!==void 0)return this.pos=s+1,this.column=n+1,this.makeToken(o,i,s,r,n);if(i==="{"){let u=this.scanFdVariable(s);return u!==null?(this.pos=u.end,this.column=n+(u.end-s),{type:g.FD_VARIABLE,value:u.varname,start:s,end:u.end,line:r,column:n}):a==="}"?(this.pos=s+2,this.column=n+2,{type:g.WORD,value:"{}",start:s,end:s+2,line:r,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(s)!==null?this.readWordWithBraceExpansion(s,r,n):this.scanLiteralBraceWord(s)!==null?this.readWordWithBraceExpansion(s,r,n):a!==void 0&&a!==" "&&a!==" "&&a!==` +`?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.LBRACE,"{",s,r,n))}return i==="}"?this.isWordCharFollowing(s+1)?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.RBRACE,"}",s,r,n)):i==="!"?a==="="?(this.pos=s+2,this.column=n+2,this.makeToken(g.WORD,"!=",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.BANG,"!",s,r,n)):this.readWord(s,r,n)}looksLikeNestedSubshells(t){let s=this.input,r=s.length,n=t;for(;n=r)return!1;let i=s[n];if(i==="(")return this.looksLikeNestedSubshells(n+1);let a=/[a-zA-Z_]/.test(i),l=i==="!"||i==="[";if(!a&&!l)return!1;let o=n;for(;o=r)return!1;let c=s[u];if(c==="="&&s[u+1]!=="="||c===` +`||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&s[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;a++}if(a>l){let E=n[a];if(!(E==="("&&a>l&&"@*+?!".includes(n[a-1]))){if(a>=i||E===" "||E===" "||E===` +`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let w=n.slice(l,a);this.pos=a,this.column=r+(a-l);let S=Ci.get(w);if(S!==void 0)return{type:S,value:w,start:t,end:a,line:s,column:r};let A=xi(w);return A>0&&Ri(w.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:w,start:t,end:a,line:s,column:r}:/^[0-9]+$/.test(w)?{type:g.NUMBER,value:w,start:t,end:a,line:s,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:g.NAME,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let o=this.column,u=this.line,c="",f=!1,d=!1,h=!1,p=!1,m=n[a]==='"'||n[a]==="'",y=!1,b=0;for(;a0&&"@*+?!".includes(c[c.length-1])){let w=this.scanExtglobPattern(a);if(w!==null){c+=w.content,a=w.end,o+=w.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let w=a+10){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=E,a++,o++;continue}else if(E==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=E,a++,o++;continue}if(b>0){if(E===` +`)break;c+=E,a++,o++;continue}if(E===" "||E===" "||E===` +`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&a+10&&a0&&D--,D===0&&C==="<"&&n[a+1]==="<"&&n[a+2]!=="<"){let N=a+2,O=!1;for(n[N]==="-"&&(O=!0,N++);n[N]===" "||n[N]===" ";)N++;let{delim:M,endPos:q}=Cn(n,N);if(M.length>0){c+=n.slice(a+1,q),o+=q-a,L.push({delim:M,stripTabs:O}),a=q;continue}}if(C===` +`&&L.length>0){u++,o=0;let N=a+1;for(let{delim:O,stripTabs:M}of L)for(;!(N>=i);){let q=n.indexOf(` +`,N);q===-1&&(q=i);let J=n.slice(N,q),ce=M?J.replace(/^\t+/,""):J;c+=n.slice(N,Math.min(q+1,i)),q=i;if(N=q+1,ce===O||pe)break}L.length=0,o=0,a=Math.min(N,i);continue}if(C==="'")S=!0,I="";else if(C==='"')A=!0,I="";else if(C==="\\"&&a+10&&a0?R=!0:I==="esac"&&$>0&&($--,R=!1),I="",C==="("?a>0&&n[a-1]==="$"?w++:R||w++:C===")"?R?R=!1:w--:C===";"&&$>0&&(a+10&&a0&&a="0"&&w<="9"){c+=E+w,a+=2,o+=2;continue}}if(E==="`"&&!h){for(c+=E,a++,o++;a=2){if(c[0]==="'"&&c[c.length-1]==="'"){let E=c.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(c=E,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let E=c.slice(1,-1),w=!1;for(let S=0;S0&&Ri(c.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:g.NUMBER,value:c,start:t,end:a,line:s,column:r}:Oc(c)?{type:g.NAME,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let s=this.pos,r=this.line,n=this.column,i="";for(;this.posthis.maxHeredocSize)throw new pt(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,n);this.pos&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let l=a;for(this.pos++,this.column++;this.pos=this.input.length)return!1;let s=this.input[t];return!(s===" "||s===" "||s===` +`||s===";"||s==="&"||s==="|"||s==="("||s===")"||s==="<"||s===">")}readWordWithBraceExpansion(t,s,r){let n=this.input,i=n.length,a=t,l=r;for(;a")break;if(u==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,l++;a0;)n[a]==="{"?f++:n[a]==="}"&&f--,a++,l++;continue}a++,l++;continue}if(u==="}"){a++,l++;continue}if(u==="$"&&a+10&&a0&&a0;){let o=s[n];if(o==="{")i++,n++;else if(o==="}")i--,n++;else if(o===","&&i===1)a=!0,n++;else if(o==="."&&n+10;){let a=s[n];if(a==="{")i++,n++;else if(a==="}"){if(i--,i===0)return s.slice(t,n+1);n++}else{if(a===" "||a===" "||a===` +`||a===";"||a==="&"||a==="|")return null;n++}}return null}scanExtglobPattern(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n0;){let a=s[n];if(a==="\\"&&n+1="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===i)return null;let a=s.slice(i,n);if(n>=r||s[n]!=="}"||(n++,n>=r))return null;let l=s[n],o=n+1"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:a,end:n}:null}dollarDparenIsSubshell(t){let s=this.input,r=s.length,n=t+1,i=2,a=!1,l=!1,o=!1;for(;n0;){let u=s[n];if(a){u==="'"&&(a=!1),u===` +`&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===` +`&&(o=!0),n++;continue}if(u==="'"){a=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===` +`&&(o=!0),u==="("){i++,n++;continue}if(u===")"){if(i--,i===1){let c=n+1;if(c0;){let o=s[n];if(a){o==="'"&&(a=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){a=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){i++,n++;continue}if(o===")"){if(i--,i===1){let u=n+1;if(u>=","&=","|=","^="];function es(e){if(e.includes("#")){let[s,r]=e.split("#"),n=Number.parseInt(s,10);if(n<2||n>64)return Number.NaN;if(n<=36){let a=Number.parseInt(r,n);return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:a}let i=0;for(let a of r){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+36;else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(i=i*n+l,i>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return i}if(e.startsWith("0x")||e.startsWith("0X")){let s=Number.parseInt(e.slice(2),16);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let s=Number.parseInt(e,8);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function Fi(e,t,s,r){if(s.slice(r,r+3)!=="$((")return null;let n=r+3,i=1,a=n;for(;n0;)s[n]==="("&&s[n+1]==="("?(i++,n+=2):s[n]===")"&&s[n+1]===")"?(i--,i>0&&(n+=2)):n++;let l=s.slice(a,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Vi(e,t){if(e.slice(t,t+2)!=="$'")return null;let s=t+2,r="";for(;s=e.length}function Oe(e,t,s){return Lc(e,t,s)}function Lc(e,t,s){let{expr:r,pos:n}=ts(e,t,s);for(n=oe(t,n);t[n]===",";){if(n++,_e(t,n))return ke(",",n);let{expr:a,pos:l}=ts(e,t,n);r={type:"ArithBinary",operator:",",left:r,right:a},n=oe(t,l)}return{expr:r,pos:n}}function ts(e,t,s){let{expr:r,pos:n}=Wc(e,t,s);if(n=oe(t,n),t[n]==="?"){n++;let{expr:i,pos:a}=Oe(e,t,n);if(n=oe(t,a),t[n]===":"){n++;let{expr:l,pos:o}=Oe(e,t,n);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:l},pos:o}}}return{expr:r,pos:n}}function Wc(e,t,s){let{expr:r,pos:n}=Bi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="||";){if(n+=2,_e(t,n))return ke("||",n);let{expr:a,pos:l}=Bi(e,t,n);r={type:"ArithBinary",operator:"||",left:r,right:a},n=l}return{expr:r,pos:n}}function Bi(e,t,s){let{expr:r,pos:n}=qi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="&&";){if(n+=2,_e(t,n))return ke("&&",n);let{expr:a,pos:l}=qi(e,t,n);r={type:"ArithBinary",operator:"&&",left:r,right:a},n=l}return{expr:r,pos:n}}function qi(e,t,s){let{expr:r,pos:n}=Ui(e,t,s);for(;n=oe(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,_e(t,n))return ke("|",n);let{expr:a,pos:l}=Ui(e,t,n);r={type:"ArithBinary",operator:"|",left:r,right:a},n=l}return{expr:r,pos:n}}function Ui(e,t,s){let{expr:r,pos:n}=Zi(e,t,s);for(;n=oe(t,n),t[n]==="^";){if(n++,_e(t,n))return ke("^",n);let{expr:a,pos:l}=Zi(e,t,n);r={type:"ArithBinary",operator:"^",left:r,right:a},n=l}return{expr:r,pos:n}}function Zi(e,t,s){let{expr:r,pos:n}=Hi(e,t,s);for(;n=oe(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,_e(t,n))return ke("&",n);let{expr:a,pos:l}=Hi(e,t,n);r={type:"ArithBinary",operator:"&",left:r,right:a},n=l}return{expr:r,pos:n}}function Hi(e,t,s){let{expr:r,pos:n}=ji(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=ji(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function ji(e,t,s){let{expr:r,pos:n}=Tn(e,t,s);for(;;)if(n=oe(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Tn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else if(t[n]==="<"||t[n]===">"){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Tn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function Tn(e,t,s){let{expr:r,pos:n}=Gi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Gi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Gi(e,t,s){let{expr:r,pos:n}=Qi(e,t,s);for(;n=oe(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Qi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Qi(e,t,s){let{expr:r,pos:n}=ks(e,t,s);for(;;)if(n=oe(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,_e(t,n))return ke("*",n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:"*",left:r,right:a},n=l}else if(t[n]==="/"||t[n]==="%"){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function ks(e,t,s){let{expr:r,pos:n}=Ln(e,t,s),i=oe(t,n);if(t.slice(i,i+2)==="**"){if(i+=2,_e(t,i))return ke("**",i);let{expr:l,pos:o}=ks(e,t,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:l},pos:o}}return{expr:r,pos:n}}function Ln(e,t,s){let r=oe(t,s);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let n=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let n=t[r];r++;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}return Fc(e,t,r)}function Mc(e,t){let s=e[t];return s==="$"||s==="`"}function Fc(e,t,s){let{expr:r,pos:n}=Ki(e,t,s,!1),i=[r];for(;Mc(t,n);){let{expr:l,pos:o}=Ki(e,t,n,!0);i.push(l),n=o}i.length>1&&(r={type:"ArithConcat",parts:i});let a;if(t[n]==="["&&r.type==="ArithConcat"){n++;let{expr:l,pos:o}=Oe(e,t,n);a=l,n=o,t[n]==="]"&&n++}if(a&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:a},a=void 0),n=oe(t,n),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let l of Ns)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=ts(e,t,n);return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r.nameExpr,subscript:r.subscript,value:o},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:r.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Ki(e,t,s,r=!1){let n=oe(t,s),i=Fi(Oe,e,t,n);if(i)return i;let a=Vi(t,n);if(a)return a;let l=zi(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p=194){let n=(r&31)<<6|e[s+1]&63;t+=String.fromCharCode(n),s+=2;continue}t+=String.fromCharCode(r),s++;continue}if((r&240)===224){if(s+2=55296&&n<=57343){t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(n),s+=3;continue}t+=String.fromCharCode(r),s++;continue}if((r&248)===240&&r<=244){if(s+31114111){t+=String.fromCharCode(r),s++;continue}t+=String.fromCodePoint(n),s+=4;continue}t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(r),s++}return t}function Ji(e,t,s){let r=s+1;for(;r0;)t[a]===r?i++:t[a]===n&&i--,i>0&&a++;return i===0?a:-1}function Nt(e,t,s){let r=s,n=1;for(;r0;){let i=t[r];if(i==="\\"&&r+10&&r++}return r}function ea(e,t,s){let r=s,n=!1;for(;r0)l.push(c),o+=2+u.length;else break}l.length>0?(r+=Vc(l),n=o):(r+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(r+="\\u",n+=2):(r+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2({type:"Word",word:x.word(r(e,c,!1,!1,!1))}))},endIndex:n+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Yi(i).map(c=>({type:"Word",word:x.word([x.literal(c)])}))},endIndex:n+1}:null}function Fn(e,t){let s="";for(let r of t.parts)switch(r.type){case"Literal":s+=r.value;break;case"SingleQuoted":s+=`'${r.value}'`;break;case"Escaped":s+=r.value;break;case"DoubleQuoted":s+='"';for(let n of r.parts)n.type==="Literal"||n.type==="Escaped"?s+=n.value:n.type==="ParameterExpansion"&&(s+=`\${${n.parameter}}`);s+='"';break;case"ParameterExpansion":s+=`\${${r.parameter}}`;break;case"Glob":s+=r.pattern;break;case"TildeExpansion":s+="~",r.user&&(s+=r.user);break;case"BraceExpansion":{s+="{";let n=[];for(let i of r.items)if(i.type==="Range"){let a=i.startStr??String(i.start),l=i.endStr??String(i.end);i.step!==void 0?n.push(`${a}..${l}..${i.step}`):n.push(`${a}..${l}`)}else n.push(Fn(e,i.word));n.length===1&&r.items[0].type==="Range"?s+=n[0]:s+=n.join(","),s+="}";break}default:s+=r.type}return s}function ra(e,t){return{[g.LESS]:"<",[g.GREAT]:">",[g.DGREAT]:">>",[g.LESSAND]:"<&",[g.GREATAND]:">&",[g.LESSGREAT]:"<>",[g.CLOBBER]:">|",[g.TLESS]:"<<<",[g.AND_GREAT]:"&>",[g.AND_DGREAT]:"&>>",[g.DLESS]:"<",[g.DLESSDASH]:"<"}[t]||">"}function _s(e){let t=e.current(),s=t.type;if(s===g.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:Wi.has(r.type)}if(s===g.FD_VARIABLE){let r=e.peek(1);return Mi.has(r.type)}return Li.has(s)}function Ps(e){let t=null,s;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(s=e.advance().value);let r=e.advance(),n=ra(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return Bc(e,n,t,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return x.redirection(n,i,t,s)}function Bc(e,t,s,r){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),i=n.value,a=n.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let l=x.redirection(r?"<<-":"<<",x.hereDoc(i,x.word([]),r,a),s);return e.addPendingHeredoc(l,i,r,a),l}function aa(e){let t=e.current().line,s=[],r=null,n=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||_s(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?s.push(qc(e)):i.push(Ps(e));if(e.isWord())r=e.parseWord();else if(s.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let l=e.advance();r=x.word([x.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),_s(e))i.push(Ps(e));else if(e.check(g.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(g.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(g.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(g.LPAREN);let d=Vn(e);e.expect(g.RPAREN);let h=d.map(m=>Fn(e,m)),p=`${f}=(${h.join(" ")})`;n.push(e.parseWordFromString(p,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=x.simpleCommand(r,n,s,i);return a.line=t,a}function qc(e){let t=e.expect(g.ASSIGNMENT_WORD),s=t.value,r=s.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${s}`);let n=r[0],i,a=n.length;if(s[a]==="["){let f=0,d=a+1;for(;a2)break}else f.value==="("&&o++,f.value===")"&&o--,a[l]+=f.value}e.expect(g.DPAREN_END),a[0].trim()&&(r=X(e,a[0].trim())),a[1].trim()&&(n=X(e,a[1].trim())),a[2].trim()&&(i=X(e,a[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(g.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),u=e.parseCompoundList(),e.expect(g.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:n,update:i,body:u,redirections:c,line:s}}function qn(e,t){e.expect(g.WHILE);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.whileNode(s,r,n)}function Un(e,t){e.expect(g.UNTIL);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.untilNode(s,r,n)}function Zn(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let s=e.parseWord();e.skipNewlines(),e.expect(g.IN),e.skipNewlines();let r=[];for(;!e.check(g.ESAC,g.EOF);){e.checkIterationLimit();let i=e.getPos(),a=jc(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(g.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.caseNode(s,r,n)}function jc(e){e.check(g.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(g.PIPE));)e.advance();if(t.length===0)return null;e.expect(g.RPAREN),e.skipNewlines();let s=[];for(;!e.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND,g.ESAC,g.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===g.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(g.LPAREN)&&e.peek(1).type===g.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),i=e.parseStatement();if(i&&s.push(i),e.skipSeparators(!1),e.getPos()===n&&!i)break}let r=";;";return e.check(g.DSEMI)?(e.advance(),r=";;"):e.check(g.SEMI_AND)?(e.advance(),r=";&"):e.check(g.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),x.caseItem(t,s,r)}function Hn(e,t){e.expect(g.LPAREN);let s=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.subshell(s,r)}function jn(e,t){e.expect(g.LBRACE);let s=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.group(s,r)}var Qc=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Kc=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function oa(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function la(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,s="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,s+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(s+=")"),e.advance();else if(e.isWord())s+=e.advance().value;else if(e.check(g.PIPE))s+="|",e.advance();else break;return s+=")",e.parseWordFromString(s,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function Qn(e){return e.skipNewlines(),Xc(e)}function Xc(e){let t=ca(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let s=ca(e);t={type:"CondOr",left:t,right:s},e.skipNewlines()}return t}function ca(e){let t=Gn(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let s=Gn(e);t={type:"CondAnd",left:t,right:s},e.skipNewlines()}return t}function Gn(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:Gn(e)}):Yc(e)}function Yc(e){if(e.check(g.LPAREN)){e.advance();let t=Qn(e);return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(oa(e)){let t=e.current(),s=t.value;if(Qc.includes(s)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${s}`),oa(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:s,operand:i}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&Kc.includes(e.current().value)){let n=e.advance().value,i;return n==="=~"?i=Jc(e):n==="=="||n==="!="?i=la(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:r,right:i}}if(e.check(g.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:n}}if(e.check(g.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=la(e);return{type:"CondBinary",operator:"==",left:r,right:n}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Jc(e){let t=[],s=0,r=-1,n=e.getInput(),i=()=>e.check(g.DBRACK_END)||e.check(g.AND_AND)||e.check(g.OR_OR)||e.check(g.NEWLINE)||e.check(g.EOF);for(;!i();){let a=e.current(),l=r>=0&&a.start>r;if(s===0&&l)break;if(s>0&&l){let o=n.slice(r,a.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),s++,r=o.end}else if(e.check(g.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),s+=2,r=o.end}else if(e.check(g.DPAREN_END))if(s>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),s-=2,r=o.end}else{if(s===1)break;break}else if(e.check(g.RPAREN))if(s>0){let o=e.advance();t.push({type:"Literal",value:")"}),s--,r=o.end}else break;else if(e.check(g.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),r=o.end}else if(e.check(g.SEMICOLON))if(s>0){let o=e.advance();t.push({type:"Literal",value:";"}),r=o.end}else break;else if(s>0&&e.check(g.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),r=o.end}else if(s>0&&e.check(g.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),r=o.end}else if(s>0&&e.check(g.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),r=o.end}else if(s>0&&e.check(g.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),r=o.end}else if(s>0&&e.check(g.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),r=o.end}else if(s>0&&e.check(g.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),r=o.end}else if(s>0&&e.check(g.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),r=o.end}else if(s>0&&e.check(g.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),r=o.end}else if(s>0&&e.check(g.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),r=o.end}else if(s>0&&e.check(g.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),r=o.end}else if(s>0&&e.check(g.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),r=o.end}else if(s>0&&e.check(g.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),r=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function ss(e){return e.length>0?e:[x.literal("")]}function tu(e,t){let s=1,r=t+1;for(;r0;){let n=e[r];if(n==="\\"){r+=2;continue}if("@*+?!".includes(n)&&r+10;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(s+2,d);return{part:x.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(l===""&&!i&&!a&&t[n]!=="}"){let c=1,f=n;for(;f0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new we("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(s+2,f);return{part:x.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n=t.length)throw new we("unexpected EOF while looking for matching '}'",0,0);return{part:x.parameterExpansion(l,u),endIndex:n+1}}function Kn(e,t,s,r,n=!1){let i=s,a=t[i],l=t[i+1]||"";if(a===":"){let o=l;if("-=?+".includes(o)){i+=2;let b=Nt(e,t,i),v=t.slice(i,b),E=mt(e,v,!1,!1,!0,!1,n,!1,!1,!0),w=x.word(ss(E));if(o==="-")return{operation:{type:"DefaultValue",word:w,checkEmpty:!0},endIndex:b};if(o==="=")return{operation:{type:"AssignDefault",word:w,checkEmpty:!0},endIndex:b};if(o==="?")return{operation:{type:"ErrorIfUnset",word:w,checkEmpty:!0},endIndex:b};if(o==="+")return{operation:{type:"UseAlternative",word:w,checkEmpty:!0},endIndex:b}}i++;let u=Nt(e,t,i),c=t.slice(i,u),f=-1,d=0,h=0;for(let y=0;y0)h--;else{f=y;break}}let p=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Mn(e,p),length:m!==null?Mn(e,m):null},endIndex:u}}if("-=?+".includes(a)){i++;let o=Nt(e,t,i),u=t.slice(i,o),c=mt(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=x.word(ss(c));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(a==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(a==="#"||a==="%"){let o=l===a,u=a==="#"?"prefix":"suffix";i+=o?2:1;let c=Nt(e,t,i),f=t.slice(i,c),d=mt(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:x.word(ss(d)),side:u,greedy:o},endIndex:c}}if(a==="/"){let o=l==="/";i+=o?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=ea(e,t,i);let f=t.slice(i,c),d=mt(e,f,!1,!1,!1),h=x.word(ss(d)),p=null,m=c;if(t[c]==="/"){let y=c+1,b=Nt(e,t,y),v=t.slice(y,b),E=mt(e,v,!1,!1,!1);p=x.word(ss(E)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:o,anchor:u},endIndex:m}}if(a==="^"||a===","){let o=l===a,u=a==="^"?"upper":"lower";i+=o?2:1;let c=Nt(e,t,i),f=t.slice(i,c),d=f?x.word([x.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:i+2}:{operation:null,endIndex:i}}function Xn(e,t,s,r=!1){let n=s+1;if(n>=t.length)return{part:x.literal("$"),endIndex:n};let i=t[n];if(i==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,s)?e.parseCommandSubstitution(t,s):e.parseArithmeticExpansion(t,s);if(i==="["){let a=1,l=n+1;for(;l0;)t[l]==="["?a++:t[l]==="]"&&a--,a>0&&l++;if(a===0){let o=t.slice(n+1,l),u=X(e,o);return{part:x.arithmeticExpansion(u),endIndex:l+1}}}return i==="("?e.parseCommandSubstitution(t,s):i==="{"?nu(e,t,s,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?su(e,t,s):{part:x.literal("$"),endIndex:n}}function ua(e,t){let s=[],r=0,n="",i=()=>{n&&(s.push(x.literal(n)),n="")};for(;r{i&&(r.push(x.literal(i)),i="")};for(;n=2&&t[0]==='"'&&t[t.length-1]==='"'){let p=t.slice(1,-1),m=!1;for(let y=0;y{d&&(c.push(x.literal(d)),d="")};for(;f0?t[f-1]:"";if(f===0||m==="="||n&&m===":"){let b=Ji(e,t,f),v=t[b];if(v===void 0||v==="/"||v===":"){h();let E=t.slice(f+1,b)||null;c.push({type:"TildeExpansion",user:E}),f=b;continue}}}if("@*+?!".includes(p)&&f+1Ti)throw new we("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>On)throw new we(`Maximum parser nesting depth exceeded (${On})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,s){if(t.length>Rn)throw new we(`Input too large: ${t.length} bytes exceeds limit of ${Rn}`,1,1);this._input=t;let r=new $s(t,s);if(this.tokens=r.tokenize(),this.tokens.length>xn)throw new we(`Too many tokens: ${this.tokens.length} exceeds limit of ${xn}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos0?i.includes(a):!1}expect(t,s){if(this.check(t))return this.advance();let r=this.current();throw new we(s||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let s=this.current();throw new we(t,s.line,s.column,s)}skipNewlines(){for(;this.check(g.NEWLINE,g.COMMENT);)this.check(g.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(g.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(g.SEMICOLON,g.COMMENT)){this.advance();continue}if(t&&this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,s,r,n){this.pendingHeredocs.push({redirect:t,delimiter:s,stripTabs:r,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let s=this.advance(),r;t.quoted?r=x.word([x.literal(s.value)]):r=this.parseWordFromString(s.value,!1,!1,!1,!0),t.redirect.target=x.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(g.EOF,g.NEWLINE,g.SEMICOLON,g.AMP,g.AND_AND,g.OR_OR,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.ASSIGNMENT_WORD||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||t===g.FUNCTION||t===g.BANG||t===g.TIME||t===g.IN||t===g.LESS||t===g.GREAT||t===g.DLESS||t===g.DGREAT||t===g.LESSAND||t===g.GREATAND||t===g.LESSGREAT||t===g.DLESSDASH||t===g.CLOBBER||t===g.TLESS||t===g.AND_GREAT||t===g.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.skipSeparators(!1),this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(g.EOF)&&this.advance()}return x.script(t)}checkUnexpectedToken(){let t=this.current().type,s=this.current().value;if((t===g.DO||t===g.DONE||t===g.THEN||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.ESAC)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${s}'`;return this.advance(),x.statement([x.pipeline([x.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:s})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${s}'`),(t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${s}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,s=[],r=[],n=!1,i=this.parsePipeline();for(s.push(i);this.check(g.AND_AND,g.OR_OR);){let o=this.advance();r.push(o.type===g.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();s.push(u)}this.check(g.AMP)&&(this.advance(),n=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,a);return x.statement(s,r,n,void 0,l)}parsePipeline(){let t=!1,s=!1;this.check(g.TIME)&&(this.advance(),t=!0,this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),s=!0));let r=0;for(;this.check(g.BANG);)this.advance(),r++;let n=r%2===1,i=[],a=[],l=this.parseCommand();for(i.push(l);this.check(g.PIPE,g.PIPE_AMP);){let o=this.advance();this.skipNewlines(),a.push(o.type===g.PIPE_AMP);let u=this.parseCommand();i.push(u)}return x.pipeline(i,n,t,s,a.length>0?a:void 0)}parseCommand(){return this.check(g.IF)?zn(this):this.check(g.FOR)?Bn(this):this.check(g.WHILE)?qn(this):this.check(g.UNTIL)?Un(this):this.check(g.CASE)?Zn(this):this.check(g.LPAREN)?Hn(this):this.check(g.LBRACE)?jn(this):this.check(g.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(g.DBRACK_START)?this.parseConditionalCommand():this.check(g.FUNCTION)?this.parseFunctionDef():this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():aa(this)}dparenClosesWithSpacedParens(){let t=1,s=1;for(;snew e,r=>this.error(r))}parseBacktickSubstitution(t,s,r=!1){return Ii(t,s,r,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,s){return Pi(t,s)}parseArithmeticExpansion(t,s){let r=s+3,n=1,i=0,a=r;for(;a0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(n++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(n++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(n--,n>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let l=t.slice(r,a),o=this.parseArithmeticExpression(l);return{part:x.arithmeticExpansion(o),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),s="",r=1,n=0,i=!1,a=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,n>0){n--,s+=")";continue}if(this.check(g.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,a=!0;continue}s+=")";continue}if(this.check(g.DPAREN_START))r++,s+="((",this.advance();else if(this.check(g.DPAREN_END))n>=2?(n-=2,s+="))",this.advance()):n===1?(n--,s+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(s+="))"),this.advance());else if(this.check(g.LPAREN))n++,s+="(",this.advance();else if(this.check(g.RPAREN))n>0&&n--,s+=")",this.advance();else{let u=this.current().value,c=s.length>0?s[s.length-1]:"";s.length>0&&!s.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(s))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(s+=" "),s+=u,this.advance()}}a||this.expect(g.DPAREN_END);let l=this.parseArithmeticExpression(s.trim()),o=this.parseOptionalRedirections();return x.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),s=Qn(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return x.conditionalCommand(s,r,t.line)}parseFunctionDef(){let t;if(this.check(g.FUNCTION)){if(this.advance(),this.check(g.NAME)||this.check(g.WORD))t=this.advance().value;else{let n=this.current();throw new we("Expected function name",n.line,n.column,n)}this.check(g.LPAREN)&&(this.advance(),this.expect(g.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(g.LPAREN),this.expect(g.RPAREN);this.skipNewlines();let s=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return x.functionDef(t,s,r)}parseCompoundCommandBody(t){let s=t?.forFunctionBody;if(this.check(g.LBRACE))return jn(this,{skipRedirections:s});if(this.check(g.LPAREN))return Hn(this,{skipRedirections:s});if(this.check(g.IF))return zn(this,{skipRedirections:s});if(this.check(g.FOR))return Bn(this,{skipRedirections:s});if(this.check(g.WHILE))return qn(this,{skipRedirections:s});if(this.check(g.UNTIL))return Un(this,{skipRedirections:s});if(this.check(g.CASE))return Zn(this,{skipRedirections:s});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),s=[];for(this.skipNewlines();!this.check(g.EOF,g.FI,g.ELSE,g.ELIF,g.THEN,g.DO,g.DONE,g.ESAC,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,n=this.parseStatement();if(n&&s.push(n),this.skipSeparators(),this.pos===r&&!n)break}return t(),s}parseOptionalRedirections(){let t=[];for(;_s(this);){this.checkIterationLimit();let s=this.pos;if(t.push(Ps(this)),this.pos===s)break}return t}parseArithmeticExpression(t){return X(this,t)}};function Ue(e,t){return new V().parse(e,t)}var au="BASH_ALIAS_";function fa(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function da(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ha(e,t){return e.env.get(`${au}${t}`)}function Yn(e,t,s){if(!t.name||!fa(t.name))return t;let r=da(t.name);if(!r)return t;let n=ha(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new V,a=n,l=n.endsWith(" ");if(!l)for(let f of t.args){let d=ma(f);a+=` ${d}`}let o;try{o=i.parse(a)}catch(f){if(f instanceof we)throw f;return t}if(o.statements.length!==1||o.statements[0].pipelines.length!==1||o.statements[0].pipelines[0].commands.length!==1)return pa(t,n);let u=o.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return pa(t,n);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(l&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(fa(f)){let d=da(f);if(d&&ha(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},p=Yn(e,h,s);p!==h&&(c={...c,name:p.name,args:[...p.args]})}}}return c}catch(i){throw s.delete(r),i}}function pa(e,t){let s=t;for(let a of e.args){let l=ma(a);s+=` ${l}`}let r=new V,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function ma(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}var ou=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Jn(e){return ou.get(e)??""}function ga(e){let t=[],s="",r=0;for(;r0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function tr(e){let t=[],s="",r=0,n=!1,i=0;for(;ithis.maxOps)throw new Q(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(s=>{let r=s.split("/").pop()||s;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(s,n))return!1}return!0})}matchGlobignorePattern(t,s){return ya(s).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,s){let r=t.map((a,l)=>(s?.[l]??!1)||!this.isGlobPattern(a)?null:this.expand(a)),n=await Promise.all(r.map(a=>a||Promise.resolve(null))),i=[];for(let a=0;a0?i.push(...l):i.push(t[a])}return i}async expand(t){if(this.globstar){let r=t.split("/"),n=0;for(let i of r)if(i==="**"&&(n++,n>wa))throw new Q(`Glob pattern has too many ** segments (max ${wa})`,"glob_operations")}let s;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))s=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");s=await this.expandSimple(r)}return this.filterGlobignore(s)}isGlobstarValid(t){let s=t.split("/");for(let r of s)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let s=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;up.name==="."),h=l.some(p=>p.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d.name,n)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;s===""?p=d.name:s==="/"?p=`/${d.name}`:p=`${s}/${d.name}`,i.length===0?o.push(Promise.resolve([p])):d.isDirectory&&o.push(this.expandSegments(h,p,i))}let f=await Promise.all(o);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d,n)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;s===""?p=d:s==="/"?p=`/${d}`:p=`${s}/${d}`,i.length===0?o.push(Promise.resolve([p])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof Q)throw m}return[]})())}let f=await Promise.all(o);for(let d of f)a.push(...d)}}catch(l){if(l instanceof Q)throw l}return a}async expandRecursive(t){let s=[],r=t.indexOf("**"),n=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(n,a,s),[...new Set(s)].sort()):(await this.walkDirectory(n,a,s),s.sort())}async walkDirectoryMultiGlobstar(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(i){let a=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let l=t==="."?s:`${t}/${s}`,o=await this.expandRecursive(l);r.push(...o);for(let u=0;uthis.walkDirectoryMultiGlobstar(f,s,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),l=[];for(let c of a){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&l.push(f)}catch(h){if(h instanceof Q)throw h}}let o=t==="."?s:`${t}/${s}`,u=await this.expandRecursive(o);r.push(...u);for(let c=0;cthis.walkDirectoryMultiGlobstar(d,s,r)))}}}catch(i){if(i instanceof Q)throw i}}async walkDirectory(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(n),a=[],l=[];for(let o of i){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):s&&this.matchPattern(o.name,s)&&a.push(u)}r.push(...a);for(let o=0;othis.walkDirectory(c,s,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),a=[];for(let o=0;o{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof Q)throw p;return null}}));a.push(...c.filter(f=>f!==null))}for(let o of a)!o.isDirectory&&s&&this.matchPattern(o.name,s)&&r.push(o.path);let l=a.filter(o=>o.isDirectory);for(let o=0;othis.walkDirectory(c.path,s,r)))}}}catch(i){if(i instanceof Q)throw i}}matchPattern(t,s){return this.patternToRegex(s).test(t)}patternToRegex(t){let s=this.patternToRegexStr(t);return ae(`^${s}$`)}patternToRegexStr(t){let s="",r=!1;for(let n=0;nthis.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")s+=`(?:${c})`;else if(i==="*")s+=`(?:${c})*`;else if(i==="+")s+=`(?:${c})+`;else if(i==="?")s+=`(?:${c})?`;else if(i==="!")if(athis.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)s+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${c})).{${p}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=a;continue}}if(i==="*")s+=".*";else if(i==="?")s+=".";else if(i==="["){let a=n+1,l="[";athis.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){s+=u[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){s+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){s+=1,r=a+1;continue}s+=1,r++;continue}if(i==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}};function sr(e){for(let t=0;tn-i)}function Xe(e,t){let s=`${t}_`;for(let r of e.state.env.keys())r.startsWith(s)&&e.state.env.delete(r)}function Ze(e,t){let s=`${t}_`,r=`${t}__length`,n=[];for(let i of e.state.env.keys())if(i!==r&&i.startsWith(s)){let a=i.slice(s.length);if(a.startsWith("_length"))continue;n.push(a)}return n.sort()}function Ds(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function nr(e){if(e.parts.length<2)return null;let t=e.parts[0],s=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,n=s,i=1;if(s.type==="Literal"&&s.value.startsWith("]")){let f=s.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),n=d,i=2}else return null}else if(t.pattern==="["&&(s.type==="DoubleQuoted"||s.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(s.type==="SingleQuoted")r=s.value;else{r="";for(let d of s.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}n=f,i=2}else if(t.pattern.endsWith("]")){if(s.type!=="Literal"||!s.value.startsWith("=")&&!s.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Ds(r);let a;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?a=n.value.slice(1):a=n.value;let l=a.startsWith("+=");if(!l&&!a.startsWith("="))return null;let o=[],u=l?2:1,c=a.slice(u);c&&o.push({type:"Literal",value:c});for(let f=i+1;f{if(s.type==="Range"){let r=s.startStr??String(s.start),n=s.endStr??String(s.end),i=`${r}..${n}`;return s.step&&(i+=`..${s.step}`),i}return Ft(s.word)}).join(",")}}`}function Ft(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value;break;case"Glob":t+=s.pattern;break;case"SingleQuoted":t+=s.value;break;case"DoubleQuoted":for(let r of s.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=s.value;break;case"BraceExpansion":t+="{",t+=s.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Ft(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",s.user&&(t+=s.user);break}return t}function he(e){return e.get("IFS")??` +`}function Ee(e){return e.get("IFS")===""}function Is(e){let t=he(e);if(t==="")return!0;for(let s of t)if(s!==" "&&s!==" "&&s!==` +`)return!1;return!0}function ba(e){let t=!1,s=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?s.push(`\\${r}`):r===" "?s.push("\\t"):r===` +`?s.push("\\n"):s.push(r);return t&&s.push("\\-"),s.join("")}function z(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var uu=` +`;function fu(e){return uu.includes(e)}function rr(e){let t=new Set,s=new Set;for(let r of e)fu(r)?t.add(r):s.add(r);return{whitespace:t,nonWhitespace:s}}function ir(e,t,s,r){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:i}=rr(t),a=[],l=[],o=0;for(;o=e.length)return{words:[],wordStarts:[]};if(i.has(e[o]))for(a.push(""),l.push(o),o++;o=s);){let u=o;for(l.push(u);o=e.length)break;for(;o=s);)for(a.push(""),l.push(o),o++;oo&&(a=!0),i>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(r.has(e[i]))for(n.push(""),i++;i=e.length){l=!1;break}let c=i;for(;i=e.length&&i>c&&(l=!0)}return{words:n,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function se(e,t){return Cs(e,t).words}function du(e,t){for(let s of e)if(t.has(s))return!0;return!1}function va(e,t,s){if(t==="")return e;let{whitespace:r,nonWhitespace:n}=rr(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!s&&i>=2){let l=0,o=i-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&n.has(a[a.length-1])){if(!s&&a.length>=2){let o=0,u=a.length-2;for(;u>=0&&a[u]==="\\";)o++,u--;if(o%2===1)return a}let l=a.substring(0,a.length-1);if(!du(l,n))return l}return a}function ee(e,t){return e.state.namerefs?.has(t)??!1}function lt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Sa(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Aa(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function $a(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ar(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Rs(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],i=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),a=e.state.associativeArrays?.has(n)??!1;return i||a}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function Se(e,t,s=100){if(!ee(e,t)||$a(e,t))return t;let r=new Set,n=t;for(;s-- >0;){if(r.has(n))return;if(r.add(n),!ee(e,n))return n;let i=e.state.env.get(n);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return n;n=i}}function kt(e,t){if(ee(e,t))return e.state.env.get(t)}function Na(e,t,s,r=100){if(!ee(e,t)||$a(e,t))return t;let n=new Set,i=t;for(;r-- >0;){if(n.has(i))return;if(n.add(i),!ee(e,i))return i;let a=e.state.env.get(i);if(a===void 0||a==="")return s!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&Rs(e,s)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function hu(e,t){let s=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,n)=>e.state.env.get(n)??"");return s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,n)=>e.state.env.get(n)??""),s}function F(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,a)=>[a,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,a)=>[a,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,a)=>[a,i]):e.state.associativeArrays?.has(t)?Ze(e,t).map(i=>[i,e.state.env.get(`${t}_${i}`)??""]):fe(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function He(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?Ze(e,t).length>0:fe(e,t).length>0}async function Y(e,t,s=!0,r=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let a="";return a+="h",e.state.options.errexit&&(a+="e"),e.state.options.noglob&&(a+="f"),e.state.options.nounset&&(a+="u"),e.state.options.verbose&&(a+="v"),e.state.options.xtrace&&(a+="x"),a+="B",e.state.options.noclobber&&(a+="C"),a+="s",a}case"*":{let a=Number.parseInt(e.state.env.get("#")||"0",10);if(a===0)return"";let l=[];for(let o=1;o<=a;o++)l.push(e.state.env.get(String(o))||"");return l.join(z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Ni;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let a=e.state.funcNameStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Re("FUNCNAME");return""}case"BASH_LINENO":{let a=e.state.callLineStack?.[0];if(a!==void 0)return String(a);if(s&&e.state.options.nounset)throw new Re("BASH_LINENO");return""}case"BASH_SOURCE":{let a=e.state.sourceStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Re("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new xe(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let a=n[1],l=n[2];if(ee(e,a)){let f=Se(e,a);if(f&&f!==a){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";a=f}}if(l==="@"||l==="*"){let f=F(e,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=e.state.env.get(a);return d!==void 0?d:""}if(a==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(a==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(a==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(a)){let f=Ds(l);f=hu(e,f);let d=e.state.env.get(`${a}_${f}`);if(d===void 0&&s&&e.state.options.nounset)throw new Re(`${a}[${l}]`);return d||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new V,d=X(f,l);u=await T(e,d.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=F(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript +`,"";let p=Math.max(...f.map(([y])=>typeof y=="number"?y:0))+1+u;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript +`,""):e.state.env.get(`${a}_${p}`)||""}let c=e.state.env.get(`${a}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(s&&e.state.options.nounset)throw new Re(`${a}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&s&&e.state.options.nounset)throw new Re(t);return a||""}if(ee(e,t)){let a=Se(e,t);if(a===void 0)return"";if(a!==t)return await Y(e,a,s,r);let l=e.state.env.get(t);if((l===void 0||l==="")&&s&&e.state.options.nounset)throw new Re(t);return l||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(a=>a.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(He(e,t)){let a=e.state.env.get(`${t}_0`);return a!==void 0?a:""}if(s&&e.state.options.nounset)throw new Re(t);return""}async function Ye(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],i=r[2];if(ee(e,n)){let o=Se(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(i==="@"||i==="*")return F(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=Ds(i);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(i))l=Number.parseInt(i,10);else try{let o=new V,u=X(o,i);l=await T(e,u.expression)}catch{let o=e.state.env.get(i);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=F(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(ee(e,t)){let n=Se(e,t);return n===void 0||n===t?e.state.env.has(t):Ye(e,n)}return!!(e.state.env.has(t)||He(e,t))}async function ka(e,t){let s="",r=0;for(;r0;)t[i]==="{"?n++:t[i]==="}"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let n=1,i=r+2;for(;i0;)t[i]==="("?n++:t[i]===")"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n0;)s[o]==="("&&s[o-1]==="$"||s[o]==="("?l++:s[o]===")"&&l--,o++;let u=s.slice(a+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}a=o}else if(s[a+1]==="{"){let l=1,o=a+2;for(;o0;)s[o]==="{"?l++:s[o]==="}"&&l--,o++;let u=s.slice(a+2,o-1),c=await Y(e,u);i+=c,a=o}else if(/[a-zA-Z_]/.test(s[a+1]||"")){let l=a+1;for(;l{if(o>0){let f=c<0,d=String(Math.abs(c)).padStart(o,"0");return f?`-${d}`:d}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f=t&&f="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let d=s!==void 0?`..${s}`:"";throw new ws(`{${e}..${t}${d}}: invalid sequence`)}let f=[];if(n<=i)for(let d=n,h=0;d<=i&&h=i&&hZ(f,t,s)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),n=a+1;continue}}if(i==="\\")if(n+10;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function yu(e){let t=[],s="",r=0,n=0;for(;n0&&s=0;i--){let a=e.slice(i);if(n.test(a))return e.slice(0,i)}return e}function Vt(e,t){let s=Array.from(e.state.env.keys()),r=new Set,n=e.state.associativeArrays??new Set,i=new Set;for(let l of s){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&i.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&i.add(u[1])}let a=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of s)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&r.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&r.add(o[1])}else a(l)||r.add(l);return[...r].sort()}function Su(e,t){let s=(i,a=2)=>String(i).padStart(a,"0");if(e===""){let i=s(t.getHours()),a=s(t.getMinutes()),l=s(t.getSeconds());return`${i}:${a}:${l}`}let r="",n=0;for(;n=e.length){r+="%",n++;continue}let i=e[n+1];switch(i){case"H":r+=s(t.getHours());break;case"M":r+=s(t.getMinutes());break;case"S":r+=s(t.getSeconds());break;case"d":r+=s(t.getDate());break;case"m":r+=s(t.getMonth()+1);break;case"Y":r+=t.getFullYear();break;case"y":r+=s(t.getFullYear()%100);break;case"I":{let a=t.getHours()%12;a===0&&(a=12),r+=s(a);break}case"p":r+=t.getHours()<12?"AM":"PM";break;case"P":r+=t.getHours()<12?"am":"pm";break;case"%":r+="%";break;case"a":{r+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{r+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:r+=`%${i}`}n+=2}else r+=e[n],n++;return r}function is(e,t){let s="",r=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r=t.length){s+="\\",r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",v=r+1;for(;v="0"&&t[v]<="7";)b+=t[v],v++;let E=Number.parseInt(b,8)%256;s+=String.fromCharCode(E),r=v;continue}switch(y){case"\\":s+="\\",r+=2;break;case"a":s+="\x07",r+=2;break;case"e":s+="\x1B",r+=2;break;case"n":s+=` +`,r+=2;break;case"r":s+="\r",r+=2;break;case"$":s+="$",r+=2;break;case"[":case"]":r+=2;break;case"u":s+=n,r+=2;break;case"h":s+=a,r+=2;break;case"H":s+=i,r+=2;break;case"w":s+=u,r+=2;break;case"W":s+=c,r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");s+=`${d[f.getDay()]} ${h[f.getMonth()]} ${b}`,r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");s+=`${b}:${v}:${E}`,r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");s+=`${v}:${E}:${w}`,r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=f.getHours()<12?"AM":"PM";s+=`${v}:${E} ${w}`,r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0");s+=`${b}:${v}`,r+=2;break}case"D":if(r+20&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!s){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.lengthi.startsWith(`${t}_`)&&/^[0-9]+$/.test(i.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return r&&!n&&(s+="a"),n&&(s+="A"),e.state.integerVars?.has(t)&&(s+="i"),ee(e,t)&&(s+="n"),et(e,t)&&(s+="r"),e.state.exportedVars?.has(t)&&(s+="x"),s}async function Pa(e,t,s,r){return e.coverage?.hit("bash:expansion:default_value"),(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):s.effectiveValue}async function Da(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||s.checkEmpty&&r.isEmpty)&&s.word){let a=await n(e,s.word.parts,r.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let d=new V,h=X(d,u);c=await T(e,h.expression)}catch{let d=e.state.env.get(u);c=d?Number.parseInt(d,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,a);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,a);return a}return r.effectiveValue}async function Ia(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||s.checkEmpty&&r.isEmpty){let a=s.word?await n(e,s.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new U(1,"",`bash: ${a} +`)}return r.effectiveValue}async function Ca(e,t,s,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):""}async function Ra(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_removal");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let o of s.pattern.parts)if(o.type==="Glob")i+=Z(o.pattern,s.greedy,a);else if(o.type==="Literal")i+=Z(o.value,s.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=j(o.value);else if(o.type==="DoubleQuoted"){let u=await r(e,o.parts);i+=j(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);i+=Z(u,s.greedy,a)}else{let u=await n(e,o);i+=j(u)}if(s.side==="prefix")return ae(`^${i}`,"s").replace(t,"");let l=ae(`${i}$`,"s");if(s.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function xa(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let u of s.pattern.parts)if(u.type==="Glob")i+=Z(u.pattern,!0,a);else if(u.type==="Literal")i+=Z(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=j(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=j(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);i+=Z(c,!0,a)}else{let c=await n(e,u);i+=j(c)}let l=s.replacement?await r(e,s.replacement.parts):"";if(s.anchor==="start"?i=`^${i}`:s.anchor==="end"&&(i=`${i}$`),i==="")return t;let o=s.all?"gs":"s";try{let u=ae(i,o);if(s.all){let c="",f=0,d=0,h=e.limits.maxStringLength,p=u.exec(t);for(;p!==null&&!(p[0].length===0&&p.index===t.length);){if(c+=t.slice(f,p.index)+l,f=p.index+p[0].length,p[0].length===0&&f++,d++,d%100===0&&c.length>h)throw new Q(`pattern replacement: string length limit exceeded (${h} bytes)`,"string_length");p=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof Q)throw u;return t}}function Oa(e,t,s){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let n=r[1],i=F(e,n);return i.length>0?String(i.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&He(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...s].length)}async function Ta(e,t,s,r){e.coverage?.hit("bash:expansion:substring");let n=await T(e,r.offset.expression),i=r.length?await T(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let p=1;p<=u;p++)c.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(n<=0)if(d=[f,...c],n<0){if(h=d.length+n,h<0)return""}else h=0;else d=c,h=n-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new U(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution +`);let c=F(e,u),f=0;if(n<0){if(c.length>0){let d=c[c.length-1][0],p=(typeof d=="number"?d:0)+1+n;if(p<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=n),f<0)return"";if(i!==void 0){if(i<0)throw new te(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let l=[...s],o=n;if(o<0&&(o=Math.max(0,l.length+o)),i!==void 0){if(i<0){let u=l.length+i;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+i).join("")}return l.slice(o).join("")}async function La(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:case_modification"),s.pattern){let i=e.state.shoptOptions.extglob,a="";for(let f of s.pattern.parts)if(f.type==="Glob")a+=Z(f.pattern,!0,i);else if(f.type==="Literal")a+=Z(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=j(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=j(d)}else if(f.type==="ParameterExpansion"){let d=await n(e,f);a+=Z(d,!0,i)}let l=ae(`^(?:${a})$`),o=s.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!s.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return s.direction==="upper"?s.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):s.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Wa(e,t,s,r,n){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&n.operator==="Q")return F(e,i[1]).map(([,u])=>yt(u)).join(" ");if(i&&n.operator==="a")return wt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&n.operator==="a")return wt(e,a[1]);switch(n.operator){case"Q":return r?"":yt(s);case"P":return is(e,s);case"a":return wt(e,t);case"A":return r?"":`${t}=${yt(s)}`;case"E":return s.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return` +`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return r?"":yt(s);case"u":return s.charAt(0).toUpperCase()+s.slice(1);case"U":return s.toUpperCase();case"L":return s.toLowerCase();default:return s}}async function Ma(e,t,s,r,n,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),ee(e,t))return kt(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(n.innerOp?.type==="UseAlternative")return"";throw new xe(`\${!${t}}`)}let o=s;if(l&&(o===""||o.includes(" ")))throw new xe(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new xe(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return i(e,c,a)}return await Y(e,o)}function Fa(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=F(e,t.array).map(([n])=>String(n));return t.star?r.join(z(e.state.env)):r.join(" ")}function Va(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let s=Vt(e,t.prefix);return t.star?s.join(z(e.state.env)):s.join(" ")}function za(e,t,s,r){let n=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:s};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:s};if(i){let[,a,l]=i,o=F(e,a);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=z(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:r?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:s==="",effectiveValue:s}}function Ba(e){let t=0;for(;t0;){let a=e[r];if(a==="\\"&&!n&&r+1y);if(c.length===0){let y=e.state.env.get(l);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await Nu(e,u.pattern,s,r));let h=u.replacement?await s(e,u.replacement.parts):"",p=d;u.anchor==="start"?p=`^${d}`:u.anchor==="end"&&(p=`${d}$`);let m=[];try{let y=ae(p,u.all?"g":"");for(let b of f)m.push(y.replace(b,h))}catch{m.push(...f)}if(o){let y=z(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function ja(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=F(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let d="",h=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")d+=Z(m.pattern,u.greedy,h);else if(m.type==="Literal")d+=Z(m.value,u.greedy,h);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=j(m.value);else if(m.type==="DoubleQuoted"){let y=await s(e,m.parts);d+=j(y)}else if(m.type==="ParameterExpansion"){let y=await r(e,m);d+=Z(y,u.greedy,h)}else{let y=await r(e,m);d+=j(y)}let p=[];for(let m of f)p.push(ct(m,d,u.side,u.greedy));if(o){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}async function Ga(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="DefaultValue"&&s.parts[0].operation?.type!=="UseAlternative"&&s.parts[0].operation?.type!=="AssignDefault")return null;let r=s.parts[0],n=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,l=!1;if(i){let o=i[1];l=i[2]==="*";let u=F(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,h])=>h===""),d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let p=u.map(([,m])=>m);if(l){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(o);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let o=r.parameter,u=await Ye(e,o),c=await Y(e,o),f=c==="",d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(a&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=F(e,u);if(f.length>0){let h=f.map(([,p])=>p);if(c||l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Qa(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,l="",o=!1,u=null;for(let m=0;mm);if(d.length===0){let m=e.state.env.get(l);if(m!==void 0)h=[m];else{if(o)return{values:[c+f],quoted:!0};let y=c+f;return{values:y?[y]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,y="",b=e.state.shoptOptions.extglob;if(m.pattern)for(let v of m.pattern.parts)if(v.type==="Glob")y+=Z(v.pattern,m.greedy,b);else if(v.type==="Literal")y+=Z(v.value,m.greedy,b);else if(v.type==="SingleQuoted"||v.type==="Escaped")y+=j(v.value);else if(v.type==="DoubleQuoted"){let E=await n(e,v.parts);y+=j(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);y+=Z(E,m.greedy,b)}else{let E=await r(e,v);y+=j(E)}h=h.map(v=>ct(v,y,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=Z(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=Z(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=j(E.value);else if(E.type==="DoubleQuoted"){let w=await n(e,E.parts);y+=j(w)}else if(E.type==="ParameterExpansion"){let w=await r(e,E);y+=Z(w,!0,e.state.shoptOptions.extglob)}else{let w=await r(e,E);y+=j(w)}let b=m.replacement?await n(e,m.replacement.parts):"",v=y;m.anchor==="start"?v=`^${y}`:m.anchor==="end"&&(v=`${y}$`);try{let E=ae(v,m.all?"g":"");h=h.map(w=>E.replace(w,b))}catch{}}if(o){let m=z(e.state.env);return{values:[c+h.join(m)+f],quoted:!0}}return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function Ka(e,t,s,r){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a="",l=!1;for(let h=0;hh);if(c.length===0){let h=e.state.env.get(a);if(h!==void 0)return{values:[o+h+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let p=o+u;return{values:p?[p]:[],quoted:!0}}if(l){let h=z(e.state.env);return{values:[o+f.join(h)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Xa(e,t,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let n=r.parts[0],i=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let a=i[1],l=i[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(a))throw new U(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution +`);let u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=F(e,a),d=0;if(u<0){if(f.length>0){let p=f[f.length-1][0],y=(typeof p=="number"?p:0)+1+u;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([p])=>typeof p=="number"&&p>=u),d<0&&(d=f.length);let h;if(c!==void 0){if(c<0)throw new te(`${a}[@]: substring expression < 0`);h=f.slice(d,d+c).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Ya(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Transform")return null;let r=s.parts[0],n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let i=n[1],a=n[2]==="*",l=r.operation,o=F(e,i);if(o.length===0){let f=e.state.env.get(i);if(f!==void 0){let d;switch(l.operator){case"a":d="";break;case"P":d=is(e,f);break;case"Q":d=yt(f);break;default:d=f}return{values:[d],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=wt(e,i),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>is(e,f));break;case"Q":c=o.map(([,f])=>yt(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(a){let f=z(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Ja(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion")return null;let r=s.parts[0];if(r.operation)return null;let n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let i=n[1];if(ee(e,i)){let o=kt(e,i);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let a=F(e,i);if(a.length>0)return{values:a.map(([,o])=>o),quoted:!0};let l=e.state.env.get(i);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function eo(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation)return null;let n=s.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!ee(e,n))return null;let i=kt(e,n);if(!i)return null;let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!a)return null;let l=a[1],o=F(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function to(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],l=a.operation,o=await Y(e,a.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=p;y++)m.push(e.state.env.get(String(y))||"");return o==="*"?{values:[m.join(z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=F(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ku(e,d,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return _u(e,d,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=wt(e,c),y=d.map(()=>m);return f?{values:[y.join(z(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let p=[];for(let[,m]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let v=await r(e,y,!0);p.push(v)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function ku(e,t,s,r,n){let i=n.offset?await T(e,n.offset.expression):0,a=n.length?await T(e,n.length.expression):void 0,l=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(l=t.findIndex(([h])=>typeof h=="number"&&h>=d),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=i),l<0)return{values:[],quoted:!0};let o;if(a!==void 0){if(a<0)throw new te(`${s}[@]: substring expression < 0`);o=t.slice(l,l+a)}else o=t.slice(l);let u=o.map(([,c])=>c);return r?{values:[u.join(z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function _u(e,t,s,r,n,i){let a=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||a&&o)&&n.word){let f=await i(e,n.word.parts,!0);return e.state.env.set(`${s}_0`,f),e.state.env.set(`${s}__length`,"1"),{values:[f],quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function so(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let s=t[0],r=s.operation,n=r?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let i=n.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],o=(await Y(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await Ye(e,s.parameter),c=await Y(e,s.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let h=o[1],p=o[2]==="*",m=F(e,h);if(m.length>0){let b=m.map(([,v])=>v);return p?{values:[b.join(z(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(h);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function no(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let s=t[0],n=s.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let i=n.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let l=a.parts[0],u=(await Y(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await Y(e,s.parameter),f=await Ye(e,s.parameter),d=c==="",h=n.checkEmpty??!1,p;if(n.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=u[1],y=u[2]==="*",b=F(e,m);if(b.length>0){let E=b.map(([,w])=>w);return y?{values:[E.join(z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let v=e.state.env.get(m);return v!==void 0?{values:[v],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function ro(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),s=[];for(let r=1;r<=t;r++)s.push(e.state.env.get(String(r))||"");return s}async function io(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let v=0;v=d.length)p=[];else if(c!==void 0){let E=c<0?d.length+c:v+c;p=d.slice(v,Math.max(v,E))}else p=d.slice(v)}let m="";for(let v=0;v0)r.push(...i);else{if(s.hasFailglob())throw new ut(n);s.hasNullglob()||r.push(n)}}else r.push(n);return r}async function co(e,t,s,r){let n=-1,i="",a=!1;for(let v=0;vv);if(u.length===0){let v=e.state.env.get(i);v!==void 0&&(c=[v])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let v of o.pattern.parts)if(v.type==="Glob")f+=Z(v.pattern,!0,e.state.shoptOptions.extglob);else if(v.type==="Literal")f+=Z(v.value,!0,e.state.shoptOptions.extglob);else if(v.type==="SingleQuoted"||v.type==="Escaped")f+=j(v.value);else if(v.type==="DoubleQuoted"){let E=await s(e,v.parts);f+=j(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);f+=Z(E,!0,e.state.shoptOptions.extglob)}else{let E=await r(e,v);f+=j(E)}let d=o.replacement?await s(e,o.replacement.parts):"",h=f;o.anchor==="start"?h=`^${f}`:o.anchor==="end"&&(h=`${f}$`);let p=[];try{let v=ae(h,o.all?"g":"");for(let E of c)p.push(v.replace(E,d))}catch{p.push(...c)}let m=he(e.state.env),y=Ee(e.state.env);if(a){let v=z(e.state.env),E=p.join(v);return y?{values:E?[E]:[],quoted:!1}:{values:se(E,m),quoted:!1}}if(y)return{values:p,quoted:!1};let b=[];for(let v of p)v===""?b.push(""):b.push(...se(v,m));return{values:b,quoted:!1}}async function uo(e,t,s,r){let n=-1,i="",a=!1;for(let b=0;bb);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")f+=Z(b.pattern,o.greedy,d);else if(b.type==="Literal")f+=Z(b.value,o.greedy,d);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=j(b.value);else if(b.type==="DoubleQuoted"){let v=await s(e,b.parts);f+=j(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=Z(v,o.greedy,d)}else{let v=await r(e,b);f+=j(v)}let h=[];for(let b of c)h.push(ct(b,f,o.side,o.greedy));let p=he(e.state.env),m=Ee(e.state.env);if(a){let b=z(e.state.env),v=h.join(b);return m?{values:v?[v]:[],quoted:!1}:{values:se(v,p),quoted:!1}}if(m)return{values:h,quoted:!1};let y=[];for(let b of h)b===""?y.push(""):y.push(...se(b,p));return{values:y,quoted:!1}}async function fo(e,t,s,r){let n=-1,i=!1;for(let y=0;y=f.length)h=[];else if(u!==void 0){let w=u<0?f.length+u:E+u;h=f.slice(E,Math.max(E,w))}else h=f.slice(E)}let p="";for(let E=0;Eu!=="");else{let u=z(e.state.env),c=n.join(u);o=se(c,i)}else if(a)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=se(u,i);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=se(u,i);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Ls(e,o),quoted:!1}}async function mo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let s=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let r=s[1],n=s[2]==="*",i=F(e,r),a;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)a=[f];else return{values:[],quoted:!1}}else a=i.map(([,f])=>f);let l=he(e.state.env),o=Ee(e.state.env),u=Is(e.state.env),c;if(n)if(o)c=a.filter(f=>f!=="");else{let f=z(e.state.env),d=a.join(f);c=se(d,l)}else if(o)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=se(f,l);c.push(...d)}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=se(f,l);c.push(...d)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ls(e,c),quoted:!1}}function go(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let s=t[0].operation,r=Vt(e,s.prefix);if(r.length===0)return{values:[],quoted:!1};let n=he(e.state.env),i=Ee(e.state.env),a;if(s.star)if(i)a=r;else{let l=z(e.state.env),o=r.join(l);a=se(o,n)}else if(i)a=r;else{a=[];for(let l of r){let o=se(l,n);a.push(...o)}}return{values:a,quoted:!1}}function yo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let s=t[0].operation,n=F(e,s.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let i=he(e.state.env),a=Ee(e.state.env),l;if(s.star)if(a)l=n;else{let o=z(e.state.env),u=n.join(o);l=se(u,i)}else if(a)l=n;else{l=[];for(let o of n){let u=se(o,i);l.push(...u)}}return{values:l,quoted:!1}}async function wo(e,t,s){let r=-1;for(let d=0;dh!=="");else if(c){f=[];for(let h of d){if(h==="")continue;let p=se(h,o);f.push(...p)}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=se(h,o);f.push(...p)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ls(e,f),quoted:!1}}async function vo(e,t,s){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:n,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ns(r),d=s.hasBraceExpansion(r)?await s.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Du(e,d,n);let h=await Iu(e,r,l,u,c,s);if(h!==null)return h;let p=await Ru(e,r,s);if(p!==null)return p;let m=await xu(e,r,s);if(m!==null)return m;let y=await Tu(e,r,s.expandPart);if(y!==null)return bo(e,y);if((i||a||o)&&!Ee(e.state.env)){let v=he(e.state.env),E=s.buildIfsCharClassPattern(v),w=await s.smartWordSplit(e,r,v,E,s.expandPart);return bo(e,w)}let b=await s.expandWordAsync(e,t);return Lu(e,t,r,b,n,s.expandWordForGlobbing)}async function Du(e,t,s){let r=[];for(let n of t)if(!(!s&&n===""))if(!s&&!e.state.options.noglob&&Je(n,e.state.shoptOptions.extglob)){let i=await Ws(e,n);r.push(...i)}else r.push(n);return{values:r,quoted:!1}}async function Iu(e,t,s,r,n,i){if(s){let a=Ja(e,t);if(a!==null)return a}{let a=eo(e,t);if(a!==null)return a}{let a=await Ga(e,t);if(a!==null)return a}{let a=await Qa(e,t,s,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Ka(e,t,s,i.expandPart);if(a!==null)return a}{let a=await Xa(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=Ya(e,t);if(a!==null)return a}{let a=await Ha(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await ja(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=Cu(e,t);if(a!==null)return a}{let a=await to(e,t,n,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await so(e,t);if(a!==null)return a}{let a=await no(e,t);if(a!==null)return a}return null}function Cu(e,t){let s=t[0];if(s.type!=="DoubleQuoted")return null;if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="VarNamePrefix"){let r=s.parts[0].operation,n=Vt(e,r.prefix);return r.star?{values:[n.join(z(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="ArrayKeys"){let r=s.parts[0].operation,i=F(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Ru(e,t,s){{let r=await io(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await ao(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await oo(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await lo(e,t,s.expandPart);if(r!==null)return r}return null}async function xu(e,t,s){{let r=await co(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await uo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await fo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await ho(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await po(e,t);if(r!==null)return r}{let r=await mo(e,t);if(r!==null)return r}{let r=go(e,t);if(r!==null)return r}{let r=yo(e,t);if(r!==null)return r}{let r=await wo(e,t,s.expandPart);if(r!==null)return r}return null}function Eo(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;to),a.length===0){let o=e.state.env.get(s.name);o!==void 0&&(a=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let o=1;o<=l;o++)a.push(e.state.env.get(String(o))||"")}if(s.isStar){let l=z(e.state.env),o=a.join(l);return[n+o+i]}if(a.length===0){let l=n+i;return l?[l]:[]}return a.length===1?[n+a[0]+i]:[n+a[0],...a.slice(1,-1),a[a.length-1]+i]}async function Tu(e,t,s){if(t.length<2)return null;let r=!1;for(let o of t)if(Eo(o)){r=!0;break}if(!r)return null;let n=he(e.state.env),i=Ee(e.state.env),a=[];for(let o of t){let u=Eo(o);if(u&&o.type==="DoubleQuoted"){let c=await Ou(e,o,u,s);a.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await s(e,o);a.push([c])}else if(o.type==="Literal")a.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}else{let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}}let l=[];for(let o of a)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c0)return r;if(s.hasFailglob())throw new ut(t);return s.hasNullglob()?[]:[t]}async function Lu(e,t,s,r,n,i){let a=s.some(l=>l.type==="Glob");if(!e.state.options.noglob&&a){let l=await i(e,t);if(Je(l,e.state.shoptOptions.extglob)){let u=await Ws(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=cr(r);if(!Ee(e.state.env)){let u=he(e.state.env);return{values:se(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&Je(r,e.state.shoptOptions.extglob)){let l=await i(e,t);if(Je(l,e.state.shoptOptions.extglob)){let o=await Ws(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(r===""&&!n)return{values:[],quoted:!1};if(a&&!n){let l=cr(r);if(!Ee(e.state.env)){let o=he(e.state.env);return{values:se(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[r],quoted:n}}async function Ao(e,t){let s=t.operation;if(!s||s.type!=="DefaultValue"&&s.type!=="AssignDefault"&&s.type!=="UseAlternative")return null;let r=s.word;if(!r||r.parts.length===0)return null;let n=await Ye(e,t.parameter),a=await Y(e,t.parameter,!1)==="",l=s.checkEmpty??!1,o;return s.type==="UseAlternative"?o=n&&!(l&&a):o=!n||l&&a,o?r.parts:null}function Wu(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(s=>s.type==="Literal"):!1}async function Mu(e,t){if(t.type!=="ParameterExpansion")return null;let s=await Ao(e,t);if(!s||s.length<=1)return null;let r=s.some(i=>Wu(i)),n=s.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&n?s:null}function Fu(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?sr(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Ea(e))}async function $o(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Ao(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return So(e,h,s,r,n)}let i=[],a=!1;for(let d of t){let h=Fu(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Mu(e,d):null,y=await n(e,d);i.push({value:y,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(a=!0)}if(!a){let d=i.map(h=>h.value).join("");return d?[d]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):d.value!==""?(o!==""&&l.push(o),o=d.value,c=!1,f=!1):(o+=d.value,f=!1):(o+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await So(e,d.mixedDefaultParts,s,r,n);if(h.length!==0)if(h.length===1)o+=h[0],u=!0;else{o+=h[0],l.push(o),u=!0;for(let p=1;p0&&t.includes(e[0])}async function So(e,t,s,r,n){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),h=await n(e,c);i.push({value:h,isSplittable:d})}let a=[],l="",o=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(l!==""&&a.push(l),l=c.value,u=!1):l+=c.value;else{Vu(c.value,s)&&l!==""&&(a.push(l),l="",o=!0);let{words:d,hadTrailingDelimiter:h}=Cs(c.value,s);if(d.length===0)h&&(u=!0);else if(d.length===1)l+=d[0],o=!0,u=h;else{l+=d[0],a.push(l),o=!0;for(let p=1;pt)throw new Q(`${s}: string length limit exceeded (${t} bytes)`,"string_length")}async function Ge(e,t,s=!1){let r=[];for(let n of t)r.push(await Le(e,n,s));return r.join("")}function zu(e){return ko(e)}function _o(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!zu(t))return!1;return!0}function Bu(e,t,s=!1){let r=No(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return s?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return ur(e,t.pattern);default:return null}}async function W(e,t){return dr(e,t)}async function Po(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped")s.push(`\\${r.value}`);else if(r.type==="SingleQuoted")s.push(r.value);else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(n)}else if(r.type==="TildeExpansion"){let n=await Le(e,r);s.push(rs(n))}else s.push(await Le(e,r));return s.join("")}async function Do(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped"){let n=r.value;"()|*?[]".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="SingleQuoted")s.push(Te(r.value));else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(Te(n))}else s.push(await Le(e,r));return s.join("")}async function Io(e,t){let s=[];for(let r of t.parts)if(r.type==="SingleQuoted")s.push(Te(r.value));else if(r.type==="Escaped"){let n=r.value;"*?[]\\()|".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(Te(n))}else r.type==="Glob"?Ba(r.pattern)?s.push(await Ua(e,r.pattern)):s.push(ur(e,r.pattern)):r.type==="Literal"?s.push(r.value):s.push(await Le(e,r));return s.join("")}function Fs(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Fs(t.parts))return!0;return!1}var fr=1e5;async function Co(e,t,s={count:0}){if(s.count>fr)return[[]];let r=[[]];for(let n of t)if(n.type==="BraceExpansion"){let i=[],a=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=lr(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let d of f.expanded)s.count++,i.push(d);else{a=!0,l=f.literal;break}}else{let f=await Co(e,c.word.parts,s);for(let d of f){s.count++;let h=[];for(let p of d)typeof p=="string"?h.push(p):h.push(await Le(e,p));i.push(h.join(""))}}if(a){for(let c of r)s.count++,c.push(l);continue}if(r.length*i.length>e.limits.maxBraceExpansionResults||s.count>fr)return r;let u=[];for(let c of r)for(let f of i){if(s.count++,s.count>fr)return u.length>0?u:r;u.push([...c,f])}r=u}else for(let i of r)s.count++,i.push(n);return r}async function Ro(e,t){let s=t.parts;if(!Fs(s))return[await W(e,t)];let r=await Co(e,s),n=[];for(let i of r){let a=[];for(let l of i)typeof l=="string"?a.push(l):a.push(await Le(e,l));n.push(Za(e,a.join("")))}return n}function qu(){return{expandWordAsync:dr,expandWordForGlobbing:Io,expandWordWithBracesAsync:Ro,expandWordPartsAsync:Ge,expandPart:Le,expandParameterAsync:Ms,hasBraceExpansion:Fs,evaluateArithmetic:T,buildIfsCharClassPattern:ba,smartWordSplit:$o}}async function tt(e,t){return vo(e,t,qu())}function Uu(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Vs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(n){for(let i of n)if(i.type==="DoubleQuoted"){for(let a of i.parts)if(a.type==="ParameterExpansion"&&a.parameter==="@"&&!a.operation)return!0}return!1}return r(t.parts)}async function zs(e,t){if(Vs(e,t))return{error:`bash: $@: ambiguous redirect +`};let s=t.parts,{hasQuoted:r}=ns(s);if(Fs(s)&&(await Ro(e,t)).length>1)return{error:`bash: ${s.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.items.map(m=>{if(m.type==="Range"){let y=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${y}`}return m.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect +`};let n=await dr(e,t),{hasParamExpansion:i,hasCommandSub:a}=ns(s);if((i||a)&&!r&&!Ee(e.state.env)){let f=he(e.state.env);if(se(n,f).length>1)return{error:`bash: $${Uu(s)}: ambiguous redirect +`}}if(r||e.state.options.noglob)return{target:n};let o=await Io(e,t);if(!Je(o,e.state.shoptOptions.extglob))return{target:n};let u=new gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n} +`}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect +`}}async function dr(e,t){let s=t.parts,r=s.length;if(r===1){let a=await Le(e,s[0]);return Et(a,e.limits.maxStringLength,"word expansion"),a}let n=[];for(let a=0;a=a)throw new Q(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=i+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let d=await e.executeScript(t.body),h=d.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=h,e.state.env.set("?",String(h)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr),e.state.bashPid=o,e.substitutionDepth=l;let p=d.stdout.replace(/\n+$/,"");return Et(p,e.limits.maxStringLength,"command substitution"),p}catch(d){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,d instanceof Q)throw d;if(d instanceof U){e.state.lastExitCode=d.exitCode,e.state.env.set("?",String(d.exitCode)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr);let h=d.stdout.replace(/\n+$/,"");return Et(h,e.limits.maxStringLength,"command substitution"),h}throw d}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let a=await ka(e,n),l=new V,o=X(l,a);return String(await T(e,o.expression,!0))}return String(await T(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let i of t.items)if(i.type==="Range"){let a=lr(i.start,i.end,i.step,i.startStr,i.endStr);if(a.expanded)n.push(...a.expanded);else return a.literal}else n.push(await W(e,i.word));return n.join(" ")}default:return""}}async function Ms(e,t,s=!1){let{parameter:r}=t,{operation:n}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await or(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ee(e,r)){let d=Se(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await or(e,m);r=`${p}[${b}]`}}}}let a=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await Y(e,r,!a);if(!n)return l;let o=!await Ye(e,r),{isEmpty:u,effectiveValue:c}=za(e,r,l,s),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:s};switch(n.type){case"DefaultValue":return Pa(e,n,f,Ge);case"AssignDefault":return Da(e,r,n,f,Ge);case"ErrorIfUnset":return Ia(e,r,n,f,Ge);case"UseAlternative":return Ca(e,n,f,Ge);case"PatternRemoval":{let d=await Ra(e,l,n,Ge,Le);return Et(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await xa(e,l,n,Ge,Le);return Et(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Oa(e,r,l);case"LengthSliceError":throw new xe(r);case"BadSubstitution":throw new xe(n.text);case"Substring":return Ta(e,r,l,n);case"CaseModification":{let d=await La(e,l,n,Ge,Ms);return Et(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Wa(e,r,l,o,n);case"Indirection":return Ma(e,r,l,o,n,Ms,s);case"ArrayKeys":return Fa(e,n);case"VarNamePrefix":return Va(e,n);default:return l}}function Zu(e,t,s){switch(s){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new te("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new te("division by 0");return e%t;case"**":if(t<0)throw new te("exponent less than 0");return e**t;case"<<":return e<>":return e>>t;case"<":return e":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function xo(e,t,s){switch(s){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function Hu(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ju(e,t){let s=e.state.env.get(t);if(s!==void 0)return s;let r=e.state.env.get(`${t}_0`);return r!==void 0?r:await Y(e,t)}function Gu(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let s=e.trim();if(!s)return 0;try{let r=new V,{expr:n,pos:i}=Oe(r,s,0);if(i100)throw new te("maximum variable indirection depth exceeded");if(s.has(t))return 0;s.add(t);let n=await ju(e,t);if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n.trim()))return i;let a=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await pr(e,a,s,r+1);let l=new V,{expr:o,pos:u}=Oe(l,a,0);if(u0&&(r===-1||d64)return 0;let i=`${n}#${t.value}`;return es(i)}case"ArithDynamicNumber":{let n=await Bs(e,t.prefix)+t.suffix;return es(n)}case"ArithArrayElement":{let r=e.state.associativeArrays?.has(t.array),n=async i=>{let a=e.state.env.get(i);return a!==void 0?await hr(e,a):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(r&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(r&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let i=await Y(e,t.index.name);return await n(`${t.array}_${i}`)}if(t.index){let i=await T(e,t.index,s);if(i<0){let o=F(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript +`,0;let f=Math.max(...o.map(([d])=>typeof d=="number"?d:0))+1+i;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript +`,0;i=f}let a=`${t.array}_${i}`,l=e.state.env.get(a);if(l!==void 0)return hr(e,l);if(i===0){let o=e.state.env.get(t.array);if(o!==void 0)return hr(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new Re(`${t.array}[${i}]`);return 0}return 0}case"ArithDoubleSubscript":throw new te("double subscript","","");case"ArithNumberSubscript":throw new te(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new te(t.message,"","",!0);case"ArithSingleQuote":{if(s)throw new te(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await T(e,t.left,s)||await T(e,t.right,s)?1:0;if(t.operator==="&&")return await T(e,t.left,s)&&await T(e,t.right,s)?1:0;let r=await T(e,t.left,s),n=await T(e,t.right,s);return Zu(r,n,t.operator)}case"ArithUnary":{let r=await T(e,t.operand,s);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,i=Number.parseInt(await Y(e,n),10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,i=e.state.associativeArrays?.has(n),a;if(t.operand.stringKey!==void 0)a=`${n}_${t.operand.stringKey}`;else if(i&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)a=`${n}_${t.operand.index.name}`;else if(i&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await Y(e,t.operand.index.name);a=`${n}_${u}`}else if(t.operand.index){let u=await T(e,t.operand.index,s);a=`${n}_${u}`}else return r;let l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let i of t.operand.parts)n+=await zt(e,i,s);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let i of t.operand.nameExpr.parts)n+=await zt(e,i,s);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await Y(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=await T(e,t.operand.subscript,s),a=`${n}_${i}`,l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}}return r}return Hu(r,t.operator)}case"ArithTernary":return await T(e,t.condition,s)?await T(e,t.consequent,s):await T(e,t.alternate,s);case"ArithAssignment":{let r=t.variable,n=r;if(t.stringKey!==void 0)n=`${r}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(r);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${r}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await Y(e,t.subscript.name);n=`${r}_${u||"\\"}`}else if(o){let u=await T(e,t.subscript,s);n=`${r}_${u}`}else{let u=await T(e,t.subscript,s);if(u<0){let c=F(e,r);c.length>0&&(u=Math.max(...c.map(([d])=>typeof d=="number"?d:0))+1+u)}n=`${r}_${u}`}}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=xo(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await T(e,t.expression,s);case"ArithConcat":{let r="";for(let n of t.parts)r+=await zt(e,n,s);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?await pr(e,r):Number.parseInt(r,10)||0}case"ArithDynamicAssignment":{let r="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)r+=await zt(e,o,s);else t.target.type==="ArithVariable"&&(r=t.target.hasDollarPrefix?await Y(e,t.target.name):t.target.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=r;if(t.subscript){let o=await T(e,t.subscript,s);n=`${r}_${o}`}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=xo(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let r="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)r+=await zt(e,l,s);else t.nameExpr.type==="ArithVariable"&&(r=t.nameExpr.hasDollarPrefix?await Y(e,t.nameExpr.name):t.nameExpr.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=await T(e,t.subscript,s),i=`${r}_${n}`,a=e.state.env.get(i);return a!==void 0?Gu(a):0}default:return 0}}async function zt(e,t,s=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await T(e,t,s));case"ArithVariable":return t.hasDollarPrefix?await Y(e,t.name):t.name;case"ArithSpecialVar":return await Y(e,t.name);case"ArithBracedExpansion":return await Bs(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let r="";for(let n of t.parts)r+=await zt(e,n,s);return r}default:return String(await T(e,t,s))}}async function Oo(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],a=!1,l="",o=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(l||o)&&(i.push(l),l="",o=!1):h&&(l+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(l))l+=Ft({type:"Word",parts:[c]});else{(l||o)&&(i.push(l),l="",o=!1);let d=await tt(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(o=!0);let f=await W(e,{type:"Word",parts:[c]});l+=f}(l||o)&&i.push(l);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${n}=(${u.join(" ")})`}async function To(e,t){let s=-1,r=-1,n=!1;for(let m=0;m0?await W(e,d):"";return`${f}${n?"+=":"="}${h}`}var Qu=["tar","yq","xan","sqlite3","python3","python"];function Lo(e){return Qu.includes(e)}var G=Object.freeze({stdout:"",stderr:"",exitCode:0});function H(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function de(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function st(e,t,s="",r=""){throw new Q(e,t,s,r)}function ve(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Q(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function mr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ft;return G}if(t.length>1)throw new U(1,"",`bash: break: too many arguments +`);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(128,"",`bash: break: ${t[0]}: numeric argument required +`);s=r}throw new Ie(s)}async function gr(e,t){let s,r=!1,n=!1,i=0;for(;ih);for(let h of d){let p=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(p)).isDirectory){s=p,r=!0;break}}catch{}}}}let o=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of o)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${s}: Not a directory `)}catch{return _(`bash: cd: ${s}: No such file or directory -`)}}let c=u||"/";if(r)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),F(n?`${c} -`:"")}function Fs(e,t){return e.fs.resolvePath(e.state.cwd,t)}var ua=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Bt(e){return ua.includes(e)}async function jt(e,t,s){let n=Fs(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(n);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var fa=["-nt","-ot","-ef"];function Ht(e){return fa.includes(e)}async function Ut(e,t,s,n){let r=Fs(e,s),i=Fs(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtimes;case"-ge":return t>=s}}function vt(e){return e==="="||e==="=="||e==="!="}function Gt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=ot(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var ha=new Set(["-z","-n"]);function Kt(e){return ha.has(e)}function Xt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Yt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,u)=>e.state.env.get(u)||""),e.state.env.has(`${n}_${o}`)}let a;try{let o=new V,l=Q(o,r);a=await j(e,l.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env.get(r);a=o?Number.parseInt(o,10):0}}if(a<0){let o=ne(e,n),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript -`,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript -`,!1}return e.state.env.has(`${n}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Me(e,t).length>0:ne(e,t).length>0}async function ze(e,t){switch(t.type){case"CondBinary":{let s=await I(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await I(e,t.right);r=Kn(i)}else r=await Yn(e,t.right);else vt(t.operator)&&!n?r=await Qn(e,t.right):r=await I(e,t.right);if(vt(t.operator)){let i=e.state.shoptOptions.nocasematch;return Gt(t.operator,s,r,!n,i,!0)}if(Zt(t.operator))return qt(t.operator,await gr(e,s),await gr(e,r));if(Ht(t.operator))return Ut(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=ga(r),l=mt(a,i?"i":"").match(s);if(Ce(e,"BASH_REMATCH"),l)for(let u=0;u":return s>r;default:return!1}}case"CondUnary":{let s=await I(e,t.operand);return Bt(t.operator)?jt(e,t.operator,s):Kt(t.operator)?Xt(t.operator,s):t.operator==="-v"?await Yt(e,s):t.operator==="-o"?Ws(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await I(e,t.operand.expression.word)})`!=="":!await ze(e,t.operand);case"CondAnd":return await ze(e,t.left)?await ze(e,t.right):!1;case"CondOr":return await ze(e,t.left)?!0:await ze(e,t.right);case"CondGroup":return await ze(e,t.expression);case"CondWord":return await I(e,t.word)!=="";default:return!1}}async function bt(e,t){if(t.length===0)return k("","",1);if(t.length===1)return X(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?_(`test: '(' without matching ')' -`,2):Bt(n)?X(await jt(e,n,r)):Kt(n)?X(Xt(n,r)):n==="!"?X(!r):n==="-v"?X(await Yt(e,r)):n==="-o"?X(Ws(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?_(`test: ${n}: unary operator expected -`,2):k("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(vt(r))return X(Gt(r,n,i));if(Zt(r)){let a=Qt(n),o=Qt(i);return!a.valid||!o.valid?k("","",2):X(qt(r,a.value,o.value))}if(Ht(r))return X(await Ut(e,r,n,i));switch(r){case"-a":return X(n!==""&&i!=="");case"-o":return X(n!==""||i!=="");case">":return X(n>i);case"<":return X(nbr(c,t)),u=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${u})`;else if(r==="*")s+=`(?:${u})*`;else if(r==="+")s+=`(?:${u})+`;else if(r==="?")s+=`(?:${u})?`;else if(r==="!")if(iSr(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let y=[];h>0&&y.push(`.{0,${h-1}}`),y.push(`.{${h+1},}`),y.push(`(?!(?:${u})).{${h}}`),s+=`(?:${y.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;n=i;continue}}if(r==="\\")if(n+10;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function Er(e){let t=[],s="",n=0,r=0;for(;rSr(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){s+=l[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Ws(e,t){let n=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return n?n():!1}async function gr(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return wr(t);try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{return wr(t)}}function ya(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function wr(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=ya(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function Qt(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ga(e){let t="",s=0;for(;s=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s=f&&e.state.env.set(`${n}__length`,String(c+1))}else a!==void 0&&e.state.env.set(n,a);return l&&ue(e,n),null}function Ve(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function lt(e,t){return e.state.localVarDepth?.get(t)}function es(e,t){e.state.localVarDepth?.delete(t)}function Cr(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function ts(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function kr(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var zs=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Pr(e){return zs.has(e)}var Vs=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),ct=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function Ge(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory -`;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file -`}catch{}return null}function Be(e){let s=Math.min(e.length,8192);for(let n=0;n127)return"utf8";return"binary"}function $a(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let u=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(u)||u<0)return null;let c=o.slice(l+1);return{path:i,position:u,content:c}}async function Nr(e,t){let s=new Map;for(let n=0;n&"||r.operator==="<&"){if(ks(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect -`};s.set(n,await I(e,r.target))}else{let a=await Mt(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function Ea(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function ss(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await I(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=Ea(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await I(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(ae(e),e.state.fileDescriptors.set(n,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),ae(e),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")ae(e),e.state.fileDescriptors.set(n,`${r} -`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);ae(e),e.state.fileDescriptors.set(n,a)}catch{return k("",`bash: ${r}: No such file or directory -`,1)}}}return null}async function Oe(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await I(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await Mt(e,s.target);if("error"in o)return k("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";if(i.includes("\0"))return k("",`bash: ${r}: No such file or directory -`,1);try{let o=await e.fs.stat(i);if(o.isDirectory)return k("",`bash: ${r}: Is a directory -`,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return k("",`bash: ${r}: cannot overwrite existing file -`,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return k("",`bash: /dev/full: No space left on device -`,1)}return null}async function q(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t,l=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=h=>l;for(let h=0;h&"||y.operator==="<&"){if(ks(e,y.target)){i+=`bash: $@: ambiguous redirect -`,a=1,r="";continue}p=await I(e,y.target)}else{let g=await Mt(e,y.target);if("error"in g){i+=g.error,a=1,r="";continue}p=g.target}if(!y.fdVariable){if(p.includes("\0")){i+=`bash: ${p.replace(/\0/g,"")}: No such file or directory -`,a=1,r="";continue}switch(y.operator){case">":case">|":{let $=y.fd??1,g=y.operator===">|";if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1,r="";break}let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1,r="";break}await e.fs.writeFile(b,r,u(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1;break}if(p==="/dev/null")i="";else{let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1;break}await e.fs.writeFile(b,i,Be(i)),i=""}}break}case">>":{let $=y.fd??1;if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1,r="";break}let g=e.fs.resolvePath(e.state.cwd,p),b=await Ge(e,g,p,{});if(b){i+=b,a=1,r="";break}await e.fs.appendFile(g,r,u(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device -`,a=1;break}let g=e.fs.resolvePath(e.state.cwd,p),b=await Ge(e,g,p,{});if(b){i+=b,a=1;break}await e.fs.appendFile(g,i,Be(i)),i=""}break}case">&":case"<&":{let $=y.fd??1;if(p==="-")break;if(p.endsWith("-")){let g=p.slice(0,-1),b=Number.parseInt(g,10);if(!Number.isNaN(b)){let m=e.state.fileDescriptors?.get(b);m!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,m),b>=3&&e.state.fileDescriptors?.delete(b)):b===1||b===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupout__:${b}`)):b===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupin__:${b}`)):b>=3&&(i+=`bash: ${b}: Bad file descriptor -`,a=1)}break}if(p==="2"||p==="&2")$===1&&(i+=r,r="");else if(p==="1"||p==="&1")r+=i,i="";else{let g=Number.parseInt(p,10);if(Number.isNaN(g)){if(y.operator===">&"){let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}if(y.fd==null){let v=r+i;await e.fs.writeFile(b,v,u(v)),r="",i=""}else $===1?(await e.fs.writeFile(b,r,u(r)),r=""):$===2&&(await e.fs.writeFile(b,i,Be(i)),i="")}}else{let b=e.state.fileDescriptors?.get(g);if(b?.startsWith("__file__:")){let m=b.slice(9);$===1?(await e.fs.appendFile(m,r,u(r)),r=""):$===2&&(await e.fs.appendFile(m,i,Be(i)),i="")}else if(b?.startsWith("__rw__:")){let m=$a(b);m&&($===1?(await e.fs.appendFile(m.path,r,u(r)),r=""):$===2&&(await e.fs.appendFile(m.path,i,Be(i)),i=""))}else if(b?.startsWith("__dupout__:")){let m=Number.parseInt(b.slice(11),10);if(m!==1)if(m===2)$===1&&(i+=r,r="");else{let v=e.state.fileDescriptors?.get(m);if(v?.startsWith("__file__:")){let E=v.slice(9);$===1?(await e.fs.appendFile(E,r,u(r)),r=""):$===2&&(await e.fs.appendFile(E,i,Be(i)),i="")}}}else b?.startsWith("__dupin__:")?(i+=`bash: ${g}: Bad file descriptor -`,a=1,r=""):g>=3&&(i+=`bash: ${g}: Bad file descriptor -`,a=1,r="")}}break}case"&>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device -`,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await Ge(e,$,p,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.writeFile($,b,u(b)),r="",i="";break}case"&>>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device -`,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await Ge(e,$,p,{});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.appendFile($,b,u(b)),r="",i="";break}}}}let c=e.state.fileDescriptors?.get(1);if(c){if(c==="__dupout__:2")i+=r,r="";else if(c.startsWith("__file__:")){let h=c.slice(9);await e.fs.appendFile(h,r,u(r)),r=""}else if(c.startsWith("__file_append__:")){let h=c.slice(16);await e.fs.appendFile(h,r,u(r)),r=""}}let f=e.state.fileDescriptors?.get(2);if(f){if(f==="__dupout__:1")r+=i,i="";else if(f.startsWith("__file__:")){let h=f.slice(9);await e.fs.appendFile(h,i,Be(i)),i=""}else if(f.startsWith("__file_append__:")){let h=f.slice(16);await e.fs.appendFile(h,i,Be(i)),i=""}}let d=k(r,i,a);return t.stdoutKind&&(d.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(d.stdoutEncoding="binary"),d}function Or(e,t){if(e.state.options.posix&&zs.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin -`;throw new B(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),M}async function Sa(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await I(e,r.content);r.stripTabs&&(i=i.split(` -`).map(o=>o.replace(/^\t+/,"")).join(` -`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await I(e,n.target)} -`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await I(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function ns(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Pe(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(kr(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:o,error:l}=await Nr(e,t.redirections);if(l)return a(),k("",l,1);try{let u=await Sa(e,t.redirections),c=n||u,f=await e.executeCommand(t.body,c);return a(),q(e,f,t.redirections,o)}catch(u){if(a(),u instanceof ce){let c=k(u.stdout,u.stderr,u.exitCode);return q(e,c,t.redirections,o)}throw u}}var Tr=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],js=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],Aa=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],_a=js;async function Hs(e,t){let s=[],n=null,r="",i="",a=null,o=!1,l=!1,u=!1,c=null,f=null,d=null,h=[],y=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let m=0;m=t.length)return _(`compgen: -A: option requires an argument -`,2);let E=t[m];if(!y.includes(E))return _(`compgen: ${E}: invalid action name -`,2);s.push(E)}else if(v==="-W"){if(m++,m>=t.length)return _(`compgen: -W: option requires an argument -`,2);n=t[m]}else if(v==="-P"){if(m++,m>=t.length)return _(`compgen: -P: option requires an argument -`,2);r=t[m]}else if(v==="-S"){if(m++,m>=t.length)return _(`compgen: -S: option requires an argument -`,2);i=t[m]}else if(v==="-o"){if(m++,m>=t.length)return _(`compgen: -o: option requires an argument -`,2);let E=t[m];if(E==="plusdirs")o=!0;else if(E==="dirnames")l=!0;else if(E==="default")u=!0;else if(!(E==="filenames"||E==="nospace"||E==="bashdefault"||E==="noquote"))return _(`compgen: ${E}: invalid option name -`,2)}else if(v==="-F"){if(m++,m>=t.length)return _(`compgen: -F: option requires an argument -`,2);f=t[m]}else if(v==="-C"){if(m++,m>=t.length)return _(`compgen: -C: option requires an argument -`,2);d=t[m]}else if(v==="-X"){if(m++,m>=t.length)return _(`compgen: -X: option requires an argument -`,2);c=t[m]}else if(v==="-G"){if(m++,m>=t.length)return _(`compgen: -G: option requires an argument -`,2)}else if(v==="--"){h.push(...t.slice(m+1));break}else v.startsWith("-")||h.push(v)}a=h[0]??null;let p=[];if(l){let m=await Bs(e,a);p.push(...m)}if(u){let m=await Dr(e,a);p.push(...m)}for(let m of s)if(m==="variable"){let v=Ca(e,a);p.push(...v)}else if(m==="export"){let v=ka(e,a);p.push(...v)}else if(m==="function"){let v=Pa(e,a);p.push(...v)}else if(m==="builtin"){let v=Na(a);p.push(...v)}else if(m==="keyword"){let v=Oa(a);p.push(...v)}else if(m==="alias"){let v=Da(e,a);p.push(...v)}else if(m==="shopt"){let v=Ta(a);p.push(...v)}else if(m==="helptopic"){let v=Ia(a);p.push(...v)}else if(m==="directory"){let v=await Bs(e,a);p.push(...v)}else if(m==="file"){let v=await Dr(e,a);p.push(...v)}else if(m==="user"){let v=xa(a);p.push(...v)}else if(m==="command"){let v=await Ra(e,a);p.push(...v)}if(n!==null)try{let m=await La(e,n),v=Fa(e,m);for(let E of v)(a===null||E.startsWith(a))&&p.push(E)}catch{return k("","",1)}if(o){let m=await Bs(e,a);for(let v of m)p.includes(v)||p.push(v)}let w="";if(f!==null){let m=e.state.functions.get(f);if(m){let v=new Map;v.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),v.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),v.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),v.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let E=new Map;for(let O of e.state.env.keys())(O==="COMPREPLY"||O.startsWith("COMPREPLY_")||O==="COMPREPLY__length")&&(E.set(O,e.state.env.get(O)),e.state.env.delete(O));let S=["compgen",h[0]??"",""];try{let O=await ns(e,m,S,"");if(O.exitCode!==0)return ut(e,v),ut(e,E),k("",O.stderr,1);w=O.stdout;let N=Ma(e);p.push(...N)}catch{return ut(e,v),ut(e,E),k("","",1)}ut(e,v),ut(e,E)}}if(d!==null)try{let m=Ee(d),v=await e.executeScript(m);if(v.exitCode!==0)return k("",v.stderr,v.exitCode);if(v.stdout){let E=v.stdout.split(` -`);for(let S of E)S.length>0&&p.push(S)}}catch(m){if(m.name==="ParseException")return _(`compgen: -C: ${m.message} -`,2);throw m}let $=p;if(c!==null){let m=c.startsWith("!"),v=m?c.slice(1):c;$=p.filter(E=>{let S=ot(E,v,!1,!0);return m?S:!S})}if($.length===0&&a!==null)return k(w,"",1);let g=$.map(m=>`${r}${m}${i}`).join(` -`),b=w+(g?`${g} -`:"");return F(b)}function Ca(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function ka(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function Pa(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function Na(e){let t=[...js];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Oa(e){let t=[...Tr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Da(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Ta(e){let t=[...Aa];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ia(e){let t=[..._a];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Bs(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Dr(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),l=t.slice(0,o+1);s.push(l+a)}else s.push(a)}catch{}return s.sort()}function xa(e){return["root","nobody"]}async function Ra(e,t){let s=new Set;for(let i of js)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Tr)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function La(e,t){let n=new V().parseWordFromString(t,!1,!1);return await I(e,n)}function Fa(e,t){let s=e.state.env.get("IFS")??` -`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function ut(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function Ma(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=Se(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else{let r=e.state.env.get("COMPREPLY");r!==void 0&&t.push(r)}return t}var Wa=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Zs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,l=[],u=[],c=[];for(let f=0;f=t.length)return _(`complete: -W: option requires an argument +`)}}let c=u||"/";if(n)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),H(r?`${c} +`:"")}function yr(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Ku=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function qs(e){return Ku.includes(e)}async function Us(e,t,s){let r=yr(e,s);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Xu=["-nt","-ot","-ef"];function Zs(e){return Xu.includes(e)}async function Hs(e,t,s,r){let n=yr(e,s),i=yr(e,r);switch(t){case"-nt":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime>l.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtimes;case"-ge":return t>=s}}function as(e){return e==="="||e==="=="||e==="!="}function Qs(e,t,s,r=!1,n=!1,i=!1){if(r){let l=Bt(t,s,n,i);return e==="!="?!l:l}if(n){let l=t.toLowerCase()===s.toLowerCase();return e==="!="?!l:l}let a=t===s;return e==="!="?!a:a}var Ju=new Set(["-z","-n"]);function Ks(e){return Ju.has(e)}function Xs(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ys(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let r=s[1],n=s[2];if(e.state.associativeArrays?.has(r)){let l=n;return(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))&&(l=l.slice(1,-1)),l=l.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(o,u)=>e.state.env.get(u)||""),e.state.env.has(`${r}_${l}`)}let a;try{let l=new V,o=X(l,n);a=await T(e,o.expression)}catch{if(/^-?\d+$/.test(n))a=Number.parseInt(n,10);else{let l=e.state.env.get(n);a=l?Number.parseInt(l,10):0}}if(a<0){let l=fe(e,r),o=e.state.currentLine;if(l.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript +`,!1;if(a=Math.max(...l)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript +`,!1}return e.state.env.has(`${r}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ze(e,t).length>0:fe(e,t).length>0}async function bt(e,t){switch(t.type){case"CondBinary":{let s=await W(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),n;if(t.operator==="=~")if(r){let i=await W(e,t.right);n=rs(i)}else n=await Po(e,t.right);else as(t.operator)&&!r?n=await Do(e,t.right):n=await W(e,t.right);if(as(t.operator)){let i=e.state.shoptOptions.nocasematch;return Qs(t.operator,s,n,!r,i,!0)}if(js(t.operator))return Gs(t.operator,await Mo(e,s),await Mo(e,n));if(Zs(t.operator))return Hs(e,t.operator,s,n);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=nf(n),o=ae(a,i?"i":"").match(s);if(Xe(e,"BASH_REMATCH"),o)for(let u=0;u":return s>n;default:return!1}}case"CondUnary":{let s=await W(e,t.operand);return qs(t.operator)?Us(e,t.operator,s):Ks(t.operator)?Xs(t.operator,s):t.operator==="-v"?await Ys(e,s):t.operator==="-o"?Er(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await W(e,t.operand.expression.word)})`!=="":!await bt(e,t.operand);case"CondAnd":return await bt(e,t.left)?await bt(e,t.right):!1;case"CondOr":return await bt(e,t.left)?!0:await bt(e,t.right);case"CondGroup":return await bt(e,t.expression);case"CondWord":return await W(e,t.word)!=="";default:return!1}}async function os(e,t){if(t.length===0)return P("","",1);if(t.length===1)return de(!!t[0]);if(t.length===2){let r=t[0],n=t[1];return r==="("?_(`test: '(' without matching ')' +`,2):qs(r)?de(await Us(e,r,n)):Ks(r)?de(Xs(r,n)):r==="!"?de(!n):r==="-v"?de(await Ys(e,n)):r==="-o"?de(Er(e,n)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?_(`test: ${r}: unary operator expected +`,2):P("","",1)}if(t.length===3){let r=t[0],n=t[1],i=t[2];if(as(n))return de(Qs(n,r,i));if(js(n)){let a=Js(r),l=Js(i);return!a.valid||!l.valid?P("","",2):de(Gs(n,a.value,l.value))}if(Zs(n))return de(await Hs(e,n,r,i));switch(n){case"-a":return de(r!==""&&i!=="");case"-o":return de(r!==""||i!=="");case">":return de(r>i);case"<":return de(rzo(c,t)),u=o.length>0?o.join("|"):"(?:)";if(n==="@")s+=`(?:${u})`;else if(n==="*")s+=`(?:${u})*`;else if(n==="+")s+=`(?:${u})+`;else if(n==="?")s+=`(?:${u})?`;else if(n==="!")if(iUo(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${u})).{${h}}`),s+=`(?:${p.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;r=i;continue}}if(n==="\\")if(r+10;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function qo(e){let t=[],s="",r=0,n=0;for(;nUo(u,t));if(o.every(u=>u!==null)&&o.every(u=>u===o[0])){s+=o[0],r=i+1;continue}return null}return null}}if(n==="*")return null;if(n==="?"){s+=1,r++;continue}if(n==="["){let i=e.indexOf("]",r+1);if(i!==-1){s+=1,r=i+1;continue}s+=1,r++;continue}if(n==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}function Er(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function Mo(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return Fo(t);try{let s=new V,r=X(s,t);return await T(e,r.expression)}catch{return Fo(t)}}function sf(e,t){let s=0;for(let r of e){let n;if(r>="0"&&r<="9")n=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")n=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")n=r.charCodeAt(0)-65+36;else if(r==="@")n=62;else if(r==="_")n=63;else return Number.NaN;if(n>=t)return Number.NaN;s=s*t+n}return s}function Fo(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let n=Number.parseInt(r[1],10);n>=2&&n<=64?s=sf(r[2],n):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function Js(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function nf(e){let t="",s=0;for(;s=e.length)break;if(e[s]!=="["){s++;continue}s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s=f&&e.state.env.set(`${r}__length`,String(c+1))}else a!==void 0&&e.state.env.set(r,a);return o&&Pe(e,r),null}function vt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function qt(e,t){return e.state.localVarDepth?.get(t)}function tn(e,t){e.state.localVarDepth?.delete(t)}function jo(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function sn(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Go(e,t){if(e.state.localVarStack)for(let[s,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(s)}}var br=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Qo(e){return br.has(e)}var vr=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Ut=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function nn(e,t,s,r){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory +`;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file +`}catch{}return null}function Zt(e){let s=Math.min(e.length,8192);for(let r=0;r127)return"utf8";return"binary"}function lf(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}async function Ko(e,t){let s=new Map;for(let r=0;r&"||n.operator==="<&"){if(Vs(e,n.target))return{targets:s,error:`bash: $@: ambiguous redirect +`};s.set(r,await W(e,n.target))}else{let a=await zs(e,n.target);if("error"in a)return{targets:s,error:a.error};s.set(r,a.target)}}return{targets:s}}function cf(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function rn(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await W(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let r=cf(e);if(e.state.env.set(s.fdVariable,String(r)),s.target.type==="Word"){let n=await W(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(n,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(ve(e),e.state.fileDescriptors.set(r,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,n);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),ve(e),e.state.fileDescriptors.set(r,`__file__:${i}`)}else if(s.operator==="<<<")ve(e),e.state.fileDescriptors.set(r,`${n} +`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,n),a=await e.fs.readFile(i);ve(e),e.state.fileDescriptors.set(r,a)}catch{return P("",`bash: ${n}: No such file or directory +`,1)}}}return null}async function rt(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let r=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!r)continue;let n;if(r){if(n=await W(e,s.target),n==="-"||!Number.isNaN(Number.parseInt(n,10))||s.fd!=null)continue}else{let l=await zs(e,s.target);if("error"in l)return P("",l.error,1);n=l.target}let i=e.fs.resolvePath(e.state.cwd,n),a=s.operator===">|";if(i.includes("\0"))return P("",`bash: ${n}: No such file or directory +`,1);try{let l=await e.fs.stat(i);if(l.isDirectory)return P("",`bash: ${n}: Is a directory +`,1);if(e.state.options.noclobber&&!a&&!l.isDirectory&&n!=="/dev/null")return P("",`bash: ${n}: cannot overwrite existing file +`,1)}catch{}if(n!=="/dev/null"&&n!=="/dev/stdout"&&n!=="/dev/stderr"&&n!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),n==="/dev/full")return P("",`bash: /dev/full: No space left on device +`,1)}return null}async function le(e,t,s,r){let{stdout:n,stderr:i,exitCode:a}=t,o=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=m=>o,c={kind:"live-stdout"},f={kind:"live-stderr"};for(let m=0;m&"||y.operator==="<&"){if(Vs(e,y.target)){i+=`bash: $@: ambiguous redirect +`,a=1,n="";continue}b=await W(e,y.target)}else{let w=await zs(e,y.target);if("error"in w){i+=w.error,a=1,n="";continue}b=w.target}if(!y.fdVariable){if(b.includes("\0")){i+=`bash: ${b.replace(/\0/g,"")}: No such file or directory +`,a=1,n="";continue}switch(y.operator){case">":case">|":case">>":{let E=y.fd??1;if(E!==1&&E!==2)break;let w=y.operator===">>",S=y.operator===">|";if(b==="/dev/stdout"){E===2&&(f=c);break}if(b==="/dev/stderr"){E===1&&(c=f);break}if(b==="/dev/full"){i+=`bash: echo: write error: No space left on device +`,a=1,E===1&&(n="");break}if(b==="/dev/null"&&E===2){f={kind:"discard"};break}let A=e.fs.resolvePath(e.state.cwd,b),$=await nn(e,A,b,{...w?{}:{checkNoclobber:!0,isClobber:S}});if($){i+=$,a=1,E===1&&(n="");break}w?await e.fs.appendFile(A,"","binary"):await e.fs.writeFile(A,"","binary"),E===1?c={kind:"file",path:A,append:w}:f={kind:"file",path:A,append:w};break}case">&":case"<&":{let E=y.fd??1;if(b==="-")break;if(b.endsWith("-")){let w=b.slice(0,-1),S=Number.parseInt(w,10);if(!Number.isNaN(S)){let A=e.state.fileDescriptors?.get(S);A!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,A),S>=3&&e.state.fileDescriptors?.delete(S)):S===1||S===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupout__:${S}`)):S===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupin__:${S}`)):S>=3&&(i+=`bash: ${S}: Bad file descriptor +`,a=1)}break}if(b==="2"||b==="&2")E===1&&(c=f);else if(b==="1"||b==="&1")E===2?f=c:(n+=i,i="");else{let w=Number.parseInt(b,10);if(Number.isNaN(w)){if(y.operator===">&"){let S=e.fs.resolvePath(e.state.cwd,b),A=await nn(e,S,b,{checkNoclobber:!0});if(A){i=A,a=1,n="";break}await e.fs.writeFile(S,"","binary"),y.fd==null?(c={kind:"file",path:S,append:!1},f=c):E===1?c={kind:"file",path:S,append:!1}:E===2&&(f={kind:"file",path:S,append:!1})}}else{let S=e.state.fileDescriptors?.get(w);if(S?.startsWith("__file__:")){let A=S.slice(9);E===1?(await e.fs.appendFile(A,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A,i,Zt(i)),i="")}else if(S?.startsWith("__rw__:")){let A=lf(S);A&&(E===1?(await e.fs.appendFile(A.path,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A.path,i,Zt(i)),i=""))}else if(S?.startsWith("__dupout__:")){let A=Number.parseInt(S.slice(11),10);if(A!==1)if(A===2)E===1&&(i+=n,n="");else{let $=e.state.fileDescriptors?.get(A);if($?.startsWith("__file__:")){let R=$.slice(9);E===1?(await e.fs.appendFile(R,n,u(n)),n=""):E===2&&(await e.fs.appendFile(R,i,Zt(i)),i="")}}}else S?.startsWith("__dupin__:")?(i+=`bash: ${w}: Bad file descriptor +`,a=1,n=""):w>=3&&(i+=`bash: ${w}: Bad file descriptor +`,a=1,n="")}}break}case"&>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device +`,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{checkNoclobber:!0});if(w){i=w,a=1,n="";break}await e.fs.writeFile(E,"","binary"),c={kind:"file",path:E,append:!1},f=c;break}case"&>>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device +`,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{});if(w){i=w,a=1,n="";break}await e.fs.appendFile(E,"","binary"),c={kind:"file",path:E,append:!0},f=c;break}}}}if(n!==""||i!==""){let m=n,y=i;n="",i="";let b=async(v,E,w)=>{v.append?await e.fs.appendFile(v.path,E,w):await e.fs.writeFile(v.path,E,w)};if(c===f&&c.kind==="file"){let v=m+y;v!==""&&await b(c,v,u(v))}else for(let[v,E,w]of[[m,c,!0],[y,f,!1]])if(v!=="")switch(E.kind){case"live-stdout":n+=v;break;case"live-stderr":i+=v;break;case"file":await b(E,v,w?u(v):Zt(v));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=n,n="";else if(d.startsWith("__file__:")){let m=d.slice(9);await e.fs.appendFile(m,n,u(n)),n=""}else if(d.startsWith("__file_append__:")){let m=d.slice(16);await e.fs.appendFile(m,n,u(n)),n=""}}let h=e.state.fileDescriptors?.get(2);if(h){if(h==="__dupout__:1")n+=i,i="";else if(h.startsWith("__file__:")){let m=h.slice(9);await e.fs.appendFile(m,i,Zt(i)),i=""}else if(h.startsWith("__file_append__:")){let m=h.slice(16);await e.fs.appendFile(m,i,Zt(i)),i=""}}let p=P(n,i,a);return t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),p}function Xo(e,t){if(e.state.options.posix&&br.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin +`;throw new U(2,"",r)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),G}async function uf(e,t){let s="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let n=r.target,i=await W(e,n.content);n.stripTabs&&(i=i.split(` +`).map(l=>l.replace(/^\t+/,"")).join(` +`)),(r.fd??0)===0&&(s=i)}else if(r.operator==="<<<"&&r.target.type==="Word")s=`${await W(e,r.target)} +`;else if(r.operator==="<"&&r.target.type==="Word"){let n=await W(e,r.target),i=e.fs.resolvePath(e.state.cwd,n);try{s=await e.fs.readFile(i)}catch{}}return s}async function an(e,t,s,r="",n){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,st(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(n??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(Go(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:l,error:o}=await Ko(e,t.redirections);if(o)return a(),P("",o,1);try{let u=await uf(e,t.redirections),c=r||u,f=await e.executeCommand(t.body,c);return a(),le(e,f,t.redirections,l)}catch(u){if(a(),u instanceof Ne){let c=P(u.stdout,u.stderr,u.exitCode);return le(e,c,t.redirections,l)}throw u}}var Jo=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Ar=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],ff=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],df=Ar;async function $r(e,t){let s=[],r=null,n="",i="",a=null,l=!1,o=!1,u=!1,c=null,f=null,d=null,h=[],p=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let w=0;w=t.length)return _(`compgen: -A: option requires an argument +`,2);let A=t[w];if(!p.includes(A))return _(`compgen: ${A}: invalid action name +`,2);s.push(A)}else if(S==="-W"){if(w++,w>=t.length)return _(`compgen: -W: option requires an argument +`,2);r=t[w]}else if(S==="-P"){if(w++,w>=t.length)return _(`compgen: -P: option requires an argument +`,2);n=t[w]}else if(S==="-S"){if(w++,w>=t.length)return _(`compgen: -S: option requires an argument +`,2);i=t[w]}else if(S==="-o"){if(w++,w>=t.length)return _(`compgen: -o: option requires an argument +`,2);let A=t[w];if(A==="plusdirs")l=!0;else if(A==="dirnames")o=!0;else if(A==="default")u=!0;else if(!(A==="filenames"||A==="nospace"||A==="bashdefault"||A==="noquote"))return _(`compgen: ${A}: invalid option name +`,2)}else if(S==="-F"){if(w++,w>=t.length)return _(`compgen: -F: option requires an argument +`,2);f=t[w]}else if(S==="-C"){if(w++,w>=t.length)return _(`compgen: -C: option requires an argument +`,2);d=t[w]}else if(S==="-X"){if(w++,w>=t.length)return _(`compgen: -X: option requires an argument +`,2);c=t[w]}else if(S==="-G"){if(w++,w>=t.length)return _(`compgen: -G: option requires an argument +`,2)}else if(S==="--"){h.push(...t.slice(w+1));break}else S.startsWith("-")||h.push(S)}a=h[0]??null;let m=[];if(o){let w=await Sr(e,a);m.push(...w)}if(u){let w=await Yo(e,a);m.push(...w)}for(let w of s)if(w==="variable"){let S=hf(e,a);m.push(...S)}else if(w==="export"){let S=pf(e,a);m.push(...S)}else if(w==="function"){let S=mf(e,a);m.push(...S)}else if(w==="builtin"){let S=gf(a);m.push(...S)}else if(w==="keyword"){let S=yf(a);m.push(...S)}else if(w==="alias"){let S=wf(e,a);m.push(...S)}else if(w==="shopt"){let S=Ef(a);m.push(...S)}else if(w==="helptopic"){let S=bf(a);m.push(...S)}else if(w==="directory"){let S=await Sr(e,a);m.push(...S)}else if(w==="file"){let S=await Yo(e,a);m.push(...S)}else if(w==="user"){let S=vf(a);m.push(...S)}else if(w==="command"){let S=await Sf(e,a);m.push(...S)}if(r!==null)try{let w=await Af(e,r),S=$f(e,w);for(let A of S)(a===null||A.startsWith(a))&&m.push(A)}catch{return P("","",1)}if(l){let w=await Sr(e,a);for(let S of w)m.includes(S)||m.push(S)}let y="";if(f!==null){let w=e.state.functions.get(f);if(w){let S=new Map;S.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),S.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),S.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),S.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let A=new Map;for(let R of e.state.env.keys())(R==="COMPREPLY"||R.startsWith("COMPREPLY_")||R==="COMPREPLY__length")&&(A.set(R,e.state.env.get(R)),e.state.env.delete(R));let $=["compgen",h[0]??"",""];try{let R=await an(e,w,$,"");if(R.exitCode!==0)return Ht(e,S),Ht(e,A),P("",R.stderr,1);y=R.stdout;let I=Nf(e);m.push(...I)}catch{return Ht(e,S),Ht(e,A),P("","",1)}Ht(e,S),Ht(e,A)}}if(d!==null)try{let w=Ue(d),S=await e.executeScript(w);if(S.exitCode!==0)return P("",S.stderr,S.exitCode);if(S.stdout){let A=S.stdout.split(` +`);for(let $ of A)$.length>0&&m.push($)}}catch(w){if(w.name==="ParseException")return _(`compgen: -C: ${w.message} +`,2);throw w}let b=m;if(c!==null){let w=c.startsWith("!"),S=w?c.slice(1):c;b=m.filter(A=>{let $=Bt(A,S,!1,!0);return w?$:!$})}if(b.length===0&&a!==null)return P(y,"",1);let v=b.map(w=>`${n}${w}${i}`).join(` +`),E=y+(v?`${v} +`:"");return H(E)}function hf(e,t){let s=new Set;for(let n of e.state.env.keys()){if(n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length"))continue;let i=n.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)?s.add(n):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function pf(e,t){let s=e.state.exportedVars??new Set,r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r=r.filter(n=>n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length")?!1:e.state.env.has(n)),r.sort()}function mf(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(r=>r.startsWith(t))),s.sort()}function gf(e){let t=[...Ar];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function yf(e){let t=[...Jo];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function wf(e,t){let s=[];for(let n of e.state.env.keys())if(n.startsWith("BASH_ALIAS_")){let i=n.slice(11);s.push(i)}let r=s;return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function Ef(e){let t=[...ff];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function bf(e){let t=[...df];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Sr(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i){let l=`${r}/${a}`;try{if((await e.fs.stat(l)).isDirectory&&(!n||a.startsWith(n)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Yo(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i)if(!n||a.startsWith(n))if(t?.includes("/")){let l=t.lastIndexOf("/"),o=t.slice(0,l+1);s.push(o+a)}else s.push(a)}catch{}return s.sort()}function vf(e){return["root","nobody"]}async function Sf(e,t){let s=new Set;for(let i of Ar)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Jo)s.add(i);let r=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of r.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let l of a)s.add(l)}catch{}let n=Array.from(s);return t!==null&&(n=n.filter(i=>i.startsWith(t))),n.sort()}async function Af(e,t){let r=new V().parseWordFromString(t,!1,!1);return await W(e,r)}function $f(e,t){let s=e.state.env.get("IFS")??` +`;if(s.length===0)return[t];let r=new Set(s.split("")),n=[],i="",a=0;for(;a0&&(n.push(i),i=""),a++):(i+=l,a++)}return i.length>0&&n.push(i),n}function Ht(e,t){for(let[s,r]of t)r===void 0?e.state.env.delete(s):e.state.env.set(s,r)}function Nf(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let n=F(e,"COMPREPLY");for(let[,i]of n)t.push(i)}else{let n=e.state.env.get("COMPREPLY");n!==void 0&&t.push(n)}return t}var kf=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function kr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=!1,i,a,l,o=[],u=[],c=[];for(let f=0;f=t.length)return _(`complete: -W: option requires an argument `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return _(`complete: -F: option requires an argument `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return _(`complete: -o: option requires an argument -`,2);let h=t[f];if(!Wa.includes(h))return _(`complete: ${h}: invalid option name -`,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument +`,2);let h=t[f];if(!kf.includes(h))return _(`complete: ${h}: invalid option name +`,2);o.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument -`,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument +`,2);l=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument `,2)}else if(d==="-P"){if(f++,f>=t.length)return _(`complete: -P: option requires an argument `,2)}else if(d==="-S"){if(f++,f>=t.length)return _(`complete: -S: option requires an argument `,2)}else if(d==="-X"){if(f++,f>=t.length)return _(`complete: -X: option requires an argument -`,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(n){if(c.length===0)return e.state.completionSpecs.clear(),F("");for(let f of c)e.state.completionSpecs.delete(f);return F("")}if(s)return c.length===0?Us(e):Us(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&l.length===0&&u.length===0&&!r)return Us(e);if(a&&c.length===0&&!r)return _(`complete: -F: option requires a command name -`,2);if(r){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),F("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return F("")}function Us(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification -`;return k("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return k(n.join(` -`)+(n.length>0?` +`,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),H("");for(let f of c)e.state.completionSpecs.delete(f);return H("")}if(s)return c.length===0?Nr(e):Nr(e,c);if(t.length===0||c.length===0&&!i&&!a&&!l&&o.length===0&&u.length===0&&!n)return Nr(e);if(a&&c.length===0&&!n)return _(`complete: -F: option requires a command name +`,2);if(n){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),l!==void 0&&(f.command=l),o.length>0&&(f.options=o),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),H("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),l!==void 0&&(d.command=l),o.length>0&&(d.options=o),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return H("")}function Nr(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification +`;return P("",i,1)}return H("")}let r=[],n=t||Array.from(s.keys());for(let i of n){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return P(r.join(` +`)+(r.length>0?` `:""),`complete: ${i}: no completion specification -`,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${l}`;if(a.actions)for(let l of a.actions)o+=` -A ${l}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?F(""):F(`${n.join(` +`,1);continue}let l="complete";if(a.options)for(let o of a.options)l+=` -o ${o}`;if(a.actions)for(let o of a.actions)l+=` -A ${o}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?l+=` -W '${a.wordlist}'`:l+=` -W ${a.wordlist}`),a.function!==void 0&&(l+=` -F ${a.function}`),a.isDefault&&(l+=" -D"),l+=` ${i}`,r.push(l)}return r.length===0?H(""):H(`${r.join(` `)} -`)}var Ir=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function qs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o=t.length)return _(`compopt: -o: option requires an argument -`,2);let u=t[o];if(!Ir.includes(u))return _(`compopt: ${u}: invalid option name -`,2);r.push(u)}else if(l==="+o"){if(o++,o>=t.length)return _(`compopt: +o: option requires an argument -`,2);let u=t[o];if(!Ir.includes(u))return _(`compopt: ${u}: invalid option name -`,2);i.push(u)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(o.options??[]);for(let u of r)l.add(u);for(let u of i)l.delete(u);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",o),F("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},l=new Set(o.options??[]);for(let u of r)l.add(u);for(let u of i)l.delete(u);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",o),F("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},u=new Set(l.options??[]);for(let c of r)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(o,l)}return F("")}return _(`compopt: not currently executing completion function -`,1)}function Gs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Re;return M}if(t.length>1)throw new B(1,"",`bash: continue: too many arguments -`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(1,"",`bash: continue: ${t[0]}: numeric argument required -`);s=n}throw new he(s)}function G(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Ks(e){for(let t=0;t{let h=e.state.env.get(`${i}_${d}`)??"",y=Qs(h);return`['${d}']=${y}`});s+=`declare -A ${i}=(${f.join(" ")}) -`}continue}let l=ne(e,i);if(l.length>0){let c=l.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${Ke(d)}`});s+=`declare -a ${i}=(${c.join(" ")}) +`)}var el=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function _r(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=[],i=[],a=[];for(let l=0;l=t.length)return _(`compopt: -o: option requires an argument +`,2);let u=t[l];if(!el.includes(u))return _(`compopt: ${u}: invalid option name +`,2);n.push(u)}else if(o==="+o"){if(l++,l>=t.length)return _(`compopt: +o: option requires an argument +`,2);let u=t[l];if(!el.includes(u))return _(`compopt: ${u}: invalid option name +`,2);i.push(u)}else if(o==="--"){a.push(...t.slice(l+1));break}else!o.startsWith("-")&&!o.startsWith("+")&&a.push(o)}if(s){let l=e.state.completionSpecs.get("__default__")??{isDefault:!0},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__default__",l),H("")}if(r){let l=e.state.completionSpecs.get("__empty__")??{},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__empty__",l),H("")}if(a.length>0){for(let l of a){let o=e.state.completionSpecs.get(l)??{},u=new Set(o.options??[]);for(let c of n)u.add(c);for(let c of i)u.delete(c);o.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(l,o)}return H("")}return _(`compopt: not currently executing completion function +`,1)}function Pr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ft;return G}if(t.length>1)throw new U(1,"",`bash: continue: too many arguments +`);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(1,"",`bash: continue: ${t[0]}: numeric argument required +`);s=r}throw new Ce(s)}function ue(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Dr(e){for(let t=0;t{let h=e.state.env.get(`${i}_${d}`)??"",p=Rr(h);return`['${d}']=${p}`});s+=`declare -A ${i}=(${f.join(" ")}) +`}continue}let o=fe(e,i);if(o.length>0){let c=o.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${_t(d)}`});s+=`declare -a ${i}=(${c.join(" ")}) `;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=() -`;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Ys(u)} +`;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Cr(u)} `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?s+=`declare ${a} ${i} -`:(n+=`bash: declare: ${i}: not found -`,r=!0)}}return k(s,n,r?1:0)}function Lr(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,l="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),y=f.slice(d+1);if(/^\d+$/.test(y)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=xr(e,f),h=e.state.associativeArrays?.has(f),y=ne(e,f),p=!h&&(y.length>0||e.state.env.has(`${f}__length`));if(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!ge(e,f)))continue;if(h){let $=Me(e,f);if($.length===0)l+=`declare -A ${f}=() -`;else{let g=$.map(b=>{let m=e.state.env.get(`${f}_${b}`)??"",v=Qs(m);return`['${b}']=${v}`});l+=`declare -A ${f}=(${g.join(" ")}) -`}continue}if(y.length>0){let $=y.map(g=>{let b=e.state.env.get(`${f}_${g}`)??"";return`[${g}]=${Ke(b)}`});l+=`declare -a ${f}=(${$.join(" ")}) -`;continue}if(e.state.env.has(`${f}__length`)){l+=`declare -a ${f}=() -`;continue}let w=e.state.env.get(f);w!==void 0&&(l+=`declare ${d} ${f}=${Ys(w)} -`)}return F(l)}function Fr(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Me(e,n);if(r.length===0)t+=`declare -A ${n}=() -`;else{let i=r.map(a=>{let o=e.state.env.get(`${n}_${a}`)??"",l=Qs(o);return`['${a}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")}) -`}}return F(t)}function Mr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=ne(e,r);if(i.length===0)t+=`declare -a ${r}=() -`;else{let a=i.map(o=>{let l=e.state.env.get(`${r}_${o}`)??"";return`[${o}]=${Ke(l)}`});t+=`declare -a ${r}=(${a.join(" ")}) -`}}return F(t)}function Wr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||ne(e,r).length>0||e.state.env.has(`${r}__length`))continue;let o=e.state.env.get(r);o!==void 0&&(t+=`${r}=${rs(o)} -`)}return F(t)}function Js(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function $t(e,t){return e.state.integerVars?.has(t)??!1}function en(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function za(e,t){return e.state.lowercaseVars?.has(t)??!1}function tn(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Va(e,t){return e.state.uppercaseVars?.has(t)??!1}function ft(e,t,s){return za(e,t)?s.toLowerCase():Va(e,t)?s.toUpperCase():s}async function zr(e,t){try{let s=new V,n=Q(s,t),r=await j(e,n.expression);return String(r)}catch{return"0"}}function Ba(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n0&&!w,m=N=>{if(!b)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(N)||x.set(N,e.state.env.get(N))},v=N=>{if(!b)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(N)||x.set(N,e.state.env.get(N));let C=`${N}_`;for(let D of e.state.env.keys())D.startsWith(C)&&!D.includes("__")&&(x.has(D)||x.set(D,e.state.env.get(D)));let P=`${N}__length`;e.state.env.has(P)&&!x.has(P)&&x.set(P,e.state.env.get(P))},E=N=>{b&&Ve(e,N)};if(p){if($.length===0){let C=Array.from(e.state.functions.keys()).sort(),P="";for(let D of C)P+=`declare -f ${D} -`;return F(P)}let N=!0,x="";for(let C of $)e.state.functions.has(C)?x+=`${C} -`:N=!1;return k(x,"",N?0:1)}if(y){if($.length===0){let x="",C=Array.from(e.state.functions.keys()).sort();for(let P of C)x+=`${P} () +`:(r+=`bash: declare: ${i}: not found +`,n=!0)}}return P(s,r,n?1:0)}function nl(e,t){let{filterExport:s,filterReadonly:r,filterNameref:n,filterIndexedArray:i,filterAssocArray:a}=t,l=s||r||n||i||a,o="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),p=f.slice(d+1);if(/^\d+$/.test(p)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=tl(e,f),h=e.state.associativeArrays?.has(f),p=fe(e,f),m=!h&&(p.length>0||e.state.env.has(`${f}__length`));if(l&&(a&&!h||i&&!m||s&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||n&&!ee(e,f)))continue;if(h){let b=Ze(e,f);if(b.length===0)o+=`declare -A ${f}=() +`;else{let v=b.map(E=>{let w=e.state.env.get(`${f}_${E}`)??"",S=Rr(w);return`['${E}']=${S}`});o+=`declare -A ${f}=(${v.join(" ")}) +`}continue}if(p.length>0){let b=p.map(v=>{let E=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${_t(E)}`});o+=`declare -a ${f}=(${b.join(" ")}) +`;continue}if(e.state.env.has(`${f}__length`)){o+=`declare -a ${f}=() +`;continue}let y=e.state.env.get(f);y!==void 0&&(o+=`declare ${d} ${f}=${Cr(y)} +`)}return H(o)}function rl(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let r of s){let n=Ze(e,r);if(n.length===0)t+=`declare -A ${r}=() +`;else{let i=n.map(a=>{let l=e.state.env.get(`${r}_${a}`)??"",o=Rr(l);return`['${a}']=${o}`});t+=`declare -A ${r}=(${i.join(" ")}) +`}}return H(t)}function il(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);/^\d+$/.test(l)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let r=Array.from(s).sort();for(let n of r){let i=fe(e,n);if(i.length===0)t+=`declare -a ${n}=() +`;else{let a=i.map(l=>{let o=e.state.env.get(`${n}_${l}`)??"";return`[${l}]=${_t(o)}`});t+=`declare -a ${n}=(${a.join(" ")}) +`}}return H(t)}function al(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);if(/^\d+$/.test(l)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(n)}let r=Array.from(s).sort();for(let n of r){if(e.state.associativeArrays?.has(n)||fe(e,n).length>0||e.state.env.has(`${n}__length`))continue;let l=e.state.env.get(n);l!==void 0&&(t+=`${n}=${on(l)} +`)}return H(t)}function xr(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ls(e,t){return e.state.integerVars?.has(t)??!1}function Or(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function _f(e,t){return e.state.lowercaseVars?.has(t)??!1}function Tr(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Pf(e,t){return e.state.uppercaseVars?.has(t)??!1}function jt(e,t,s){return _f(e,t)?s.toLowerCase():Pf(e,t)?s.toUpperCase():s}async function ol(e,t){try{let s=new V,r=X(s,t),n=await T(e,r.expression);return String(n)}catch{return"0"}}function Df(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],r=s.length;if(e[r]!=="[")return null;let n=0,i=r+1;for(;r0&&!y,w=I=>{if(!E)return;let L=e.state.localScopes[e.state.localScopes.length-1];L.has(I)||L.set(I,e.state.env.get(I))},S=I=>{if(!E)return;let L=e.state.localScopes[e.state.localScopes.length-1];L.has(I)||L.set(I,e.state.env.get(I));let k=`${I}_`;for(let C of e.state.env.keys())C.startsWith(k)&&!C.includes("__")&&(L.has(C)||L.set(C,e.state.env.get(C)));let D=`${I}__length`;e.state.env.has(D)&&!L.has(D)&&L.set(D,e.state.env.get(D))},A=I=>{E&&vt(e,I)};if(m){if(b.length===0){let k=Array.from(e.state.functions.keys()).sort(),D="";for(let C of k)D+=`declare -f ${C} +`;return H(D)}let I=!0,L="";for(let k of b)e.state.functions.has(k)?L+=`${k} +`:I=!1;return P(L,"",I?0:1)}if(p){if(b.length===0){let L="",k=Array.from(e.state.functions.keys()).sort();for(let D of k)L+=`${D} () { # function body } -`;return F(x)}let N=!0;for(let x of $)e.state.functions.has(x)||(N=!1);return k("","",N?0:1)}if(a&&$.length>0)return Rr(e,$);if(a&&$.length===0)return Lr(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!a)return Fr(e);if($.length===0&&s&&!a)return Mr(e);if($.length===0&&!a)return Wr(e);let S="",O=0;for(let N of $){let x=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(x&&!u){let A=x[1],T=x[2];if(n&&ne(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array -`,O=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(A)){S+=`bash: declare: ${A}: cannot convert associative to indexed array -`,O=1;continue}if(v(A),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)),Ce(e,A),e.state.env.delete(A),e.state.env.delete(`${A}__length`),n&&T.includes("[")){let R=Jt(T);for(let[J,z]of R){let K=G(e,z);e.state.env.set(`${A}_${J}`,K)}}else if(n){let R=Ne(T);for(let J=0;J/^\[[^\]]+\]=/.test(z))){let z=0;for(let K of R){let re=K.match(/^\[([^\]]+)\]=(.*)$/);if(re){let fe=re[1],Qe=re[2],Xi=G(e,Qe),pt;if(/^-?\d+$/.test(fe))pt=Number.parseInt(fe,10);else try{let Yi=new V,Qi=Q(Yi,fe);pt=await j(e,Qi.expression)}catch{pt=0}e.state.env.set(`${A}_${pt}`,Xi),z=pt+1}else{let fe=G(e,K);e.state.env.set(`${A}_${z}`,fe),z++}}}else{for(let z=0;z=K&&e.state.env.set(`${A}__length`,String(z+1)),E(A),r&&ue(e,A),i&&Ae(e,A);continue}let P=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(P&&!u){let A=P[1],T=P[2],R=ee(e,A);if(R)return R;v(A);let J=Ne(T);if(e.state.associativeArrays?.has(A)){let z=Jt(T);for(let[K,re]of z){let fe=G(e,re);e.state.env.set(`${A}_${K}`,fe)}}else{let z=ne(e,A),K=0,re=e.state.env.get(A);z.length===0&&re!==void 0?(e.state.env.set(`${A}_0`,re),e.state.env.delete(A),K=1):z.length>0&&(K=Math.max(...z)+1);for(let Qe=0;Qe0||e.state.associativeArrays?.has(A);if($t(e,A)){let K=e.state.env.get(A)??"0",re=parseInt(K,10)||0,fe=parseInt(await zr(e,T),10)||0;T=String(re+fe),e.state.env.set(A,T)}else if(z){T=ft(e,A,T);let K=`${A}_0`,re=e.state.env.get(K)??"";e.state.env.set(K,re+T)}else{T=ft(e,A,T);let K=e.state.env.get(A)??"";e.state.env.set(A,K+T)}E(A),r&&ue(e,A),i&&Ae(e,A),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(A));continue}if(N.includes("=")){let A=N.indexOf("="),T=N.slice(0,A),R=N.slice(A+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(T)){S+=`bash: typeset: \`${T}': not a valid identifier -`,O=1;continue}let J=ee(e,T);if(J)return J;if(m(T),o){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){S+=`bash: declare: \`${R}': invalid variable name for name reference -`,O=1;continue}e.state.env.set(T,R),Ie(e,T),R!==""&&_s(e,R)&&As(e,T),E(T),r&&ue(e,T),i&&Ae(e,T);continue}if(f&&Js(e,T),d&&en(e,T),h&&tn(e,T),$t(e,T)&&(R=await zr(e,R)),R=ft(e,T,R),ge(e,T)){let z=We(e,T);z&&z!==T?e.state.env.set(z,R):e.state.env.set(T,R)}else e.state.env.set(T,R);E(T),r&&ue(e,T),i&&Ae(e,T),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(T))}else{let A=N;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)){S+=`bash: typeset: \`${A}': not a valid identifier -`,O=1;continue}if(s||n?v(A):m(A),o){Ie(e,A);let R=e.state.env.get(A);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?Un(e,A):R&&_s(e,R)&&As(e,A),E(A),r&&ue(e,A),i&&Ae(e,A);continue}if(f&&Js(e,A),d&&en(e,A),h&&tn(e,A),n){if(ne(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array -`,O=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)}let T=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${A}_`)&&!R.startsWith(`${A}__length`));!e.state.env.has(A)&&!T&&(s||n?e.state.env.set(`${A}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(A))),E(A),r&&ue(e,A),i&&Ae(e,A)}}return k("",S,O)}async function nn(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a0&&(w=Math.max(...p)+1);for(let b=0;bn&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function an(e,t){let s=rn(e),n;for(let o=0;ol);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.get("HOME")||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=ja(r);try{if(!(await e.fs.stat(r)).isDirectory)return _(`bash: pushd: ${n}: Not a directory -`,1)}catch{return _(`bash: pushd: ${n}: No such file or directory -`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[r,...s].map(o=>Et(o,i)).join(" ")} -`;return F(a)}function on(e,t){let s=rn(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option +`;return H(L)}let I=!0;for(let L of b)e.state.functions.has(L)||(I=!1);return P("","",I?0:1)}if(a&&b.length>0)return sl(e,b);if(a&&b.length===0)return nl(e,{filterExport:i,filterReadonly:n,filterNameref:l,filterIndexedArray:s,filterAssocArray:r});if(b.length===0&&r&&!a)return rl(e);if(b.length===0&&s&&!a)return il(e);if(b.length===0&&!a)return al(e);let $="",R=0;for(let I of b){let L=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(L&&!u){let N=L[1],O=L[2];if(r&&fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array +`,R=1;continue}if((s||!r&&!s)&&e.state.associativeArrays?.has(N)){$+=`bash: declare: ${N}: cannot convert associative to indexed array +`,R=1;continue}if(S(N),r&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)),Xe(e,N),e.state.env.delete(N),e.state.env.delete(`${N}__length`),r&&O.includes("[")){let M=en(O);for(let[q,J]of M){let ce=ue(e,J);e.state.env.set(`${N}_${q}`,ce)}}else if(r){let M=nt(O);for(let q=0;q/^\[[^\]]+\]=/.test(J))){let J=0;for(let ce of M){let pe=ce.match(/^\[([^\]]+)\]=(.*)$/);if(pe){let De=pe[1],It=pe[2],yc=ue(e,It),Kt;if(/^-?\d+$/.test(De))Kt=Number.parseInt(De,10);else try{let wc=new V,Ec=X(wc,De);Kt=await T(e,Ec.expression)}catch{Kt=0}e.state.env.set(`${N}_${Kt}`,yc),J=Kt+1}else{let De=ue(e,ce);e.state.env.set(`${N}_${J}`,De),J++}}}else{for(let J=0;J=ce&&e.state.env.set(`${N}__length`,String(J+1)),A(N),n&&Pe(e,N),i&&je(e,N);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(D&&!u){let N=D[1],O=D[2],M=me(e,N);if(M)return M;S(N);let q=nt(O);if(e.state.associativeArrays?.has(N)){let J=en(O);for(let[ce,pe]of J){let De=ue(e,pe);e.state.env.set(`${N}_${ce}`,De)}}else{let J=fe(e,N),ce=0,pe=e.state.env.get(N);J.length===0&&pe!==void 0?(e.state.env.set(`${N}_0`,pe),e.state.env.delete(N),ce=1):J.length>0&&(ce=Math.max(...J)+1);for(let It=0;It0||e.state.associativeArrays?.has(N);if(ls(e,N)){let ce=e.state.env.get(N)??"0",pe=parseInt(ce,10)||0,De=parseInt(await ol(e,O),10)||0;O=String(pe+De),e.state.env.set(N,O)}else if(J){O=jt(e,N,O);let ce=`${N}_0`,pe=e.state.env.get(ce)??"";e.state.env.set(ce,pe+O)}else{O=jt(e,N,O);let ce=e.state.env.get(N)??"";e.state.env.set(N,ce+O)}A(N),n&&Pe(e,N),i&&je(e,N),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(N));continue}if(I.includes("=")){let N=I.indexOf("="),O=I.slice(0,N),M=I.slice(N+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){$+=`bash: typeset: \`${O}': not a valid identifier +`,R=1;continue}let q=me(e,O);if(q)return q;if(w(O),l){if(M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)){$+=`bash: declare: \`${M}': invalid variable name for name reference +`,R=1;continue}e.state.env.set(O,M),lt(e,O),M!==""&&Rs(e,M)&&ar(e,O),A(O),n&&Pe(e,O),i&&je(e,O);continue}if(f&&xr(e,O),d&&Or(e,O),h&&Tr(e,O),ls(e,O)&&(M=await ol(e,M)),M=jt(e,O,M),ee(e,O)){let J=Se(e,O);J&&J!==O?e.state.env.set(J,M):e.state.env.set(O,M)}else e.state.env.set(O,M);A(O),n&&Pe(e,O),i&&je(e,O),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let N=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)){$+=`bash: typeset: \`${N}': not a valid identifier +`,R=1;continue}if(s||r?S(N):w(N),l){lt(e,N);let M=e.state.env.get(N);M!==void 0&&M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)?Aa(e,N):M&&Rs(e,M)&&ar(e,N),A(N),n&&Pe(e,N),i&&je(e,N);continue}if(f&&xr(e,N),d&&Or(e,N),h&&Tr(e,N),r){if(fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array +`,R=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)}let O=Array.from(e.state.env.keys()).some(M=>M.startsWith(`${N}_`)&&!M.startsWith(`${N}__length`));!e.state.env.has(N)&&!O&&(s||r?e.state.env.set(`${N}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(N))),A(N),n&&Pe(e,N),i&&je(e,N)}}return P("",$,R)}async function Wr(e,t){let s=!1,r=!1,n=!1,i=[];for(let a=0;a0&&(y=Math.max(...m)+1);for(let E=0;Er&&r!=="."),s=[];for(let r of t)r===".."?s.pop():s.push(r);return`/${s.join("/")}`}async function Fr(e,t){let s=Mr(e),r;for(let l=0;lo);l.pop(),n=`/${l.join("/")}`}else r==="."?n=e.state.cwd:r.startsWith("~")?n=(e.state.env.get("HOME")||"/")+r.slice(1):n=`${e.state.cwd}/${r}`;n=If(n);try{if(!(await e.fs.stat(n)).isDirectory)return _(`bash: pushd: ${r}: Not a directory +`,1)}catch{return _(`bash: pushd: ${r}: No such file or directory +`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[n,...s].map(l=>cs(l,i)).join(" ")} +`;return H(a)}function Vr(e,t){let s=Mr(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option `,2):_(`bash: popd: too many arguments `,2);if(s.length===0)return _(`bash: popd: directory stack empty -`,1);let n=s.shift();if(!n)return _(`bash: popd: directory stack empty -`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let r=e.state.env.get("HOME")||"",i=`${[n,...s].map(a=>Et(a,r)).join(" ")} -`;return F(i)}function ln(e,t){let s=rn(e),n=!1,r=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")n=!0;else if(f==="l")r=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option +`,1);let r=s.shift();if(!r)return _(`bash: popd: directory stack empty +`,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let n=e.state.env.get("HOME")||"",i=`${[r,...s].map(a=>cs(a,n)).join(" ")} +`;return H(i)}function zr(e,t){let s=Mr(e),r=!1,n=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")n=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option `,2);else return _(`bash: dirs: too many arguments -`,1);if(n)return e.state.directoryStack=[],M;let o=[e.state.cwd,...s],l=e.state.env.get("HOME")||"",u;return a?(u=o.map((c,f)=>{let d=r?c:Et(c,l);return` ${f} ${d}`}).join(` +`,1);if(r)return e.state.directoryStack=[],G;let l=[e.state.cwd,...s],o=e.state.env.get("HOME")||"",u;return a?(u=l.map((c,f)=>{let d=n?c:cs(c,o);return` ${f} ${d}`}).join(` `),u+=` -`):i?u=o.map(c=>r?c:Et(c,l)).join(` +`):i?u=l.map(c=>n?c:cs(c,o)).join(` `)+` -`:u=o.map(c=>r?c:Et(c,l)).join(" ")+` -`,F(u)}async function is(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return _(`bash: eval: ${o}: invalid option +`:u=l.map(c=>n?c:cs(c,o)).join(" ")+` +`,H(u)}async function ln(e,t,s){let r=t;if(r.length>0){let l=r[0];if(l==="--")r=r.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return _(`bash: eval: ${l}: invalid option eval: usage: eval [arg ...] -`,2)}if(n.length===0)return M;let r=n.join(" ");if(r.trim()==="")return M;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=Ee(r);return await e.executeScript(o)}catch(o){if(o instanceof de||o instanceof he||o instanceof ce||o instanceof B)throw o;if(o.name==="ParseException")return _(`bash: eval: ${o.message} -`);throw o}finally{e.state.groupStdin=i}}function cn(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required -`,s=2):s=(i%256+256)%256}throw new B(s,"",n)}function un(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}" -`}}return F(a)}if(s){for(let a of n){let o,l;if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),l=G(e,a.slice(u+1)),e.state.env.set(o,l)}else o=a;Ft(e,o)}return M}let r="",i=0;for(let a of n){let o,l,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],l=G(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=G(e,a.slice(f+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier -`,i=1;continue}if(l!==void 0)if(u){let f=e.state.env.get(o)??"";e.state.env.set(o,f+l)}else e.state.env.set(o,l);else e.state.env.has(o)||e.state.env.set(o,"");Ae(e,o)}return k("",r,i)}function as(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...] -`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let w=1;w<=p;w++)o.push(e.state.env.get(String(w))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>o.length)return r||e.state.env.set(n,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:1,stdout:"",stderr:""};let c=o[l-1];if(!c||c==="-"||!c.startsWith("-"))return r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),as(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d} -`,r||e.state.env.set(n,"?"),f+1=o.length){let p="";return i?(e.state.env.set("OPTARG",d),r||e.state.env.set(n,":")):(p=`bash: option requires an argument -- ${d} -`,r||e.state.env.set(n,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",o[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1=t.length)return _(`bash: hash: -p: option requires an argument -`,1);o=t[u],u++}else if(y.startsWith("-")&&y.length>1){for(let p of y.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")a=!0;else return p==="p"?_(`bash: hash: -p: option requires an argument -`,1):_(`bash: hash: -${p}: invalid option -`,1);u++}else l.push(y),u++}if(s)return e.state.hashTable.clear(),M;if(n){if(l.length===0)return _(`bash: hash: -d: option requires an argument -`,1);let y=!1,p="";for(let w of l)e.state.hashTable.has(w)?e.state.hashTable.delete(w):(p+=`bash: hash: ${w}: not found -`,y=!0);return y?_(p,1):M}if(a){if(l.length===0)return _(`bash: hash: -t: option requires an argument -`,1);let y="",p=!1,w="";for(let $ of l){let g=e.state.hashTable.get($);g?l.length>1?y+=`${$} ${g} -`:y+=`${g} -`:(w+=`bash: hash: ${$}: not found -`,p=!0)}return p?{exitCode:1,stdout:y,stderr:w}:F(y)}if(i){if(l.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...] -`,1);let y=l[0];return e.state.hashTable.set(y,o),M}if(l.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty -`);let y="";if(r)for(let[p,w]of e.state.hashTable)y+=`builtin hash -p ${w} ${p} -`;else{y=`hits command -`;for(let[,p]of e.state.hashTable)y+=` 1 ${p} -`}return F(y)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let y of l){if(y.includes("/")){f+=`bash: hash: ${y}: cannot use / in name -`,c=!0;continue}let p=!1;for(let w of h){if(!w)continue;let $=`${w}/${y}`;if(await e.fs.exists($)){e.state.hashTable.set(y,$),p=!0;break}}p||(f+=`bash: hash: ${y}: not found -`,c=!0)}return c?_(f,1):M}var Vr=new Map([[":",[": [arguments]",`Null command. +`,2)}if(r.length===0)return G;let n=r.join(" ");if(n.trim()==="")return G;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let l=Ue(n);return await e.executeScript(l)}catch(l){if(l instanceof Ie||l instanceof Ce||l instanceof Ne||l instanceof U)throw l;if(l.name==="ParseException")return _(`bash: eval: ${l.message} +`);throw l}finally{e.state.groupStdin=i}}function Br(e,t){let s,r="";if(t.length===0)s=e.state.lastExitCode;else{let n=t[0],i=Number.parseInt(n,10);n===""||Number.isNaN(i)||!/^-?\d+$/.test(n)?(r=`bash: exit: ${n}: numeric argument required +`,s=2):s=(i%256+256)%256}throw new U(s,"",r)}function qr(e,t){let s=!1,r=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!s){let a="",l=e.state.exportedVars??new Set,o=Array.from(l).sort();for(let u of o){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}" +`}}return H(a)}if(s){for(let a of r){let l,o;if(a.includes("=")){let u=a.indexOf("=");l=a.slice(0,u),o=ue(e,a.slice(u+1)),e.state.env.set(l,o)}else l=a;Os(e,l)}return G}let n="",i=0;for(let a of r){let l,o,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)l=c[1],o=ue(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");l=a.slice(0,f),o=ue(e,a.slice(f+1))}else l=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: export: \`${a}': not a valid identifier +`,i=1;continue}if(o!==void 0)if(u){let f=e.state.env.get(l)??"";e.state.env.set(l,f+o)}else e.state.env.set(l,o);else e.state.env.has(l)||e.state.env.set(l,"");je(e,l)}return P("",n,i)}function cn(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...] +`);let s=t[0],r=t[1],n=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=s.startsWith(":"),a=i?s.slice(1):s,l;if(t.length>2)l=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);l=[];for(let y=1;y<=m;y++)l.push(e.state.env.get(String(y))||"")}let o=Number.parseInt(e.state.env.get("OPTIND")||"1",10);o<1&&(o=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),o>l.length)return n||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(l.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:1,stdout:"",stderr:""};let c=l[o-1];if(!c||c==="-"||!c.startsWith("-"))return n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),cn(e,t);let h=a.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d} +`,n||e.state.env.set(r,"?"),f+1=l.length){let m="";return i?(e.state.env.set("OPTARG",d),n||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d} +`,n||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",l[o]),e.state.env.set("OPTIND",String(o+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1=t.length)return _(`bash: hash: -p: option requires an argument +`,1);l=t[u],u++}else if(p.startsWith("-")&&p.length>1){for(let m of p.slice(1))if(m==="r")s=!0;else if(m==="d")r=!0;else if(m==="l")n=!0;else if(m==="t")a=!0;else return m==="p"?_(`bash: hash: -p: option requires an argument +`,1):_(`bash: hash: -${m}: invalid option +`,1);u++}else o.push(p),u++}if(s)return e.state.hashTable.clear(),G;if(r){if(o.length===0)return _(`bash: hash: -d: option requires an argument +`,1);let p=!1,m="";for(let y of o)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found +`,p=!0);return p?_(m,1):G}if(a){if(o.length===0)return _(`bash: hash: -t: option requires an argument +`,1);let p="",m=!1,y="";for(let b of o){let v=e.state.hashTable.get(b);v?o.length>1?p+=`${b} ${v} +`:p+=`${v} +`:(y+=`bash: hash: ${b}: not found +`,m=!0)}return m?{exitCode:1,stdout:p,stderr:y}:H(p)}if(i){if(o.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...] +`,1);let p=o[0];return e.state.hashTable.set(p,l),G}if(o.length===0){if(e.state.hashTable.size===0)return H(`hash: hash table empty +`);let p="";if(n)for(let[m,y]of e.state.hashTable)p+=`builtin hash -p ${y} ${m} +`;else{p=`hits command +`;for(let[,m]of e.state.hashTable)p+=` 1 ${m} +`}return H(p)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let p of o){if(p.includes("/")){f+=`bash: hash: ${p}: cannot use / in name +`,c=!0;continue}let m=!1;for(let y of h){if(!y)continue;let b=`${y}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found +`,c=!0)}return c?_(f,1):G}var ll=new Map([[":",[": [arguments]",`Null command. No effect; the command does nothing. Exit Status: Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell. @@ -498,32 +572,32 @@ eval: usage: eval [arg ...] job specification, and reports its termination status. Exit Status: Returns the status of the last ID; fails if ID is invalid or an invalid - option is given.`]]]),Br=[...Vr.keys()].sort();function dn(e,t){let s=!1,n=[],r=0;for(;r1){for(let u=1;u1){for(let u=1;us.test(n))}function Ua(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=Br.slice(),n=Math.ceil(s.length/2);for(let r=0;rs.test(r))}function Rf(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=cl.slice(),r=Math.ceil(s.length/2);for(let n=0;n0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await j(e,o.expression.expression))}}catch(i){return _(`bash: let: ${r}: ${i.message} -`)}return k("","",n===0?1:0)}async function pn(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function -`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,l=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")o=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(o=!0);else l.push(u);if(l.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d} -`)}return k(u,"",0)}for(let u of l){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let $=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${u}': not a valid identifier -`,r=1;continue}if(ee(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let m=`${c}_`;for(let v of e.state.env.keys())v.startsWith(m)&&!v.includes("__")&&(s.has(v)||s.set(v,e.state.env.get(v)))}let g=`${c}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&e.state.env.delete(m);let b=Ne($);for(let m=0;m0&&(m=Math.max(...b)+1);for(let S=0;S=m&&e.state.env.set(`${c}__length`,String(b+1)),Ve(e,c),i&&Ie(e,c);continue}if(u.includes("=")){let $=u.indexOf("=");c=u.slice(0,$),f=G(e,u.slice($+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${u}': not a valid identifier -`,r=1;continue}let w=s.has(c);if(f!==void 0){let $=e.state.env.get(c);if(e.state.tempEnvBindings){let g=e.state.accessedTempEnvVars?.has(c),b=e.state.mutatedTempEnvVars?.has(c);if(!g&&!b)for(let m=e.state.tempEnvBindings.length-1;m>=0;m--){let v=e.state.tempEnvBindings[m];if(v.has(c)){$=v.get(c);break}}}Cr(e,c,$)}if(!w){let $=e.state.env.get(c);if(e.state.tempEnvBindings)for(let g=e.state.tempEnvBindings.length-1;g>=0;g--){let b=e.state.tempEnvBindings[g];if(b.has(c)){$=b.get(c);break}}if(s.set(c,$),a){let g=`${c}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&(s.has(m)||s.set(m,e.state.env.get(m)));let b=`${c}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}}if(a&&f===void 0){let $=`${c}_`;for(let g of e.state.env.keys())g.startsWith($)&&!g.includes("__")&&e.state.env.delete(g);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(ee(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference -`,r=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let $=e.state.tempEnvBindings?.some(g=>g.has(c));!w&&!$&&e.state.env.delete(c)}Ve(e,c),i&&Ie(e,c)}return k("",n,r)}function mn(e,t,s){let n=` -`,r=0,i=0,a=0,o=!1,l="MAPFILE",u=0;for(;u0;){let g=d.indexOf(n);if(g===-1){if(d.length>0){if(y=p)return k("",`mapfile: array element limit exceeded (${p}) -`,1);let v=d,E=v.indexOf("\0");E!==-1&&(v=v.substring(0,E)),f.push(v),h++}}break}let b=d.substring(0,g),m=b.indexOf("\0");if(m!==-1&&(b=b.substring(0,m)),!o&&n!=="\0"&&(b+=n),d=d.substring(g+n.length),y0&&h>=r)break;if(i+h>=p)return k("",`mapfile: array element limit exceeded (${p}) -`,1);f.push(b),h++}i===0&&Ce(e,l);for(let g=0;g{let D=1;for(;D1&&C!=="--"){let P=p(C,h);if(P.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(P.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=P.nextArgIndex}else if(C==="--")for(h++;h=0?e.state.fileDescriptors?w=e.state.fileDescriptors.get(c)||"":w="":!w&&e.state.groupStdin!==void 0&&(w=e.state.groupStdin);let $=i===""?"\0":i,g="",b=0,m=!0,v=C=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,w.substring(C));else if(n>=0&&e.state.fileDescriptors){let P=e.state.fileDescriptors.get(n);if(P?.startsWith("__rw__:")){let D=qa(P);if(D){let A=D.position+C;e.state.fileDescriptors.set(n,Ga(D.path,A,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=w.substring(C))};if(l>=0){let C=Math.min(l,w.length);g=w.substring(0,C),b=C,m=C>=l,v(b);let P=d[0]||"REPLY";e.state.env.set(P,g);for(let D=1;D=0){let C=0,P=0,D=!1;for(;P=o||D,v(b)}else{b=0;let C=0;for(;C=w.length&&(m=!1,b=C,g.length===0&&w.length===0)){for(let P of d)e.state.env.set(P,"");return u&&Ce(e,u),k("","",1)}v(b)}$===` -`&&g.endsWith(` -`)&&(g=g.slice(0,-1));let E=C=>r?C:C.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",E(g)),k("","",m?0:1);let S=Bn(e.state.env);if(u){let{words:C}=Ss(g,S,void 0,r),P=e.limits?.maxArrayElements??1e5;if(C.length>P)return k("",`read: array element limit exceeded (${P}) -`,1);Ce(e,u);for(let D=0;D0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return _(`bash: return: ${n}: numeric argument required -`,2);s=(r%256+256)%256}throw new ce(s)}var St=`set: usage: set [-eux] [+eux] [-o option] [+o option] +`)}function xf(e){let t=[],s="",r=0;for(let n of e){for(let i of n)i==="("?r++:i===")"&&r--;s?s+=` ${n}`:s=n,r===0&&(t.push(s),s="")}return s&&t.push(s),t}async function Hr(e,t){if(t.length===0)return _(`bash: let: expression expected +`);let s=xf(t),r=0;for(let n of s)try{let a=Ue(`(( ${n} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let l=a.pipelines[0].commands[0];l.type==="ArithmeticCommand"&&(r=await T(e,l.expression.expression))}}catch(i){return _(`bash: let: ${n}: ${i.message} +`)}return P("","",r===0?1:0)}async function jr(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function +`);let s=e.state.localScopes[e.state.localScopes.length-1],r="",n=0,i=!1,a=!1,l=!1,o=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")l=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(l=!0);else o.push(u);if(o.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d} +`)}return P(u,"",0)}for(let u of o){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier +`,n=1;continue}if(me(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let w=`${c}_`;for(let S of e.state.env.keys())S.startsWith(w)&&!S.includes("__")&&(s.has(S)||s.set(S,e.state.env.get(S)))}let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&e.state.env.delete(w);let E=nt(b);for(let w=0;w0&&(w=Math.max(...E)+1);for(let $=0;$=w&&e.state.env.set(`${c}__length`,String(E+1)),vt(e,c),i&<(e,c);continue}if(u.includes("=")){let b=u.indexOf("=");c=u.slice(0,b),f=ue(e,u.slice(b+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier +`,n=1;continue}let y=s.has(c);if(f!==void 0){let b=e.state.env.get(c);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(c),E=e.state.mutatedTempEnvVars?.has(c);if(!v&&!E)for(let w=e.state.tempEnvBindings.length-1;w>=0;w--){let S=e.state.tempEnvBindings[w];if(S.has(c)){b=S.get(c);break}}}jo(e,c,b)}if(!y){let b=e.state.env.get(c);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let E=e.state.tempEnvBindings[v];if(E.has(c)){b=E.get(c);break}}if(s.set(c,b),a){let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)));let E=`${c}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}}if(a&&f===void 0){let b=`${c}_`;for(let v of e.state.env.keys())v.startsWith(b)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(me(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){r+=`bash: local: \`${f}': invalid variable name for name reference +`,n=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(c));!y&&!b&&e.state.env.delete(c)}vt(e,c),i&<(e,c)}return P("",r,n)}function Gr(e,t,s){let r=` +`,n=0,i=0,a=0,l=!1,o="MAPFILE",u=0;for(;u0;){let v=d.indexOf(r);if(v===-1){if(d.length>0){if(p=m)return P("",`mapfile: array element limit exceeded (${m}) +`,1);let S=d,A=S.indexOf("\0");A!==-1&&(S=S.substring(0,A)),f.push(S),h++}}break}let E=d.substring(0,v),w=E.indexOf("\0");if(w!==-1&&(E=E.substring(0,w)),!l&&r!=="\0"&&(E+=r),d=d.substring(v+r.length),p0&&h>=n)break;if(i+h>=m)return P("",`mapfile: array element limit exceeded (${m}) +`,1);f.push(E),h++}i===0&&Xe(e,o);for(let v=0;v{let C=1;for(;C1&&k!=="--"){let D=m(k,h);if(D.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(D.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=D.nextArgIndex}else if(k==="--")for(h++;h=0?e.state.fileDescriptors?y=e.state.fileDescriptors.get(c)||"":y="":!y&&e.state.groupStdin!==void 0&&(y=e.state.groupStdin);let b=i===""?"\0":i,v="",E=0,w=!0,S=k=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,y.substring(k));else if(r>=0&&e.state.fileDescriptors){let D=e.state.fileDescriptors.get(r);if(D?.startsWith("__rw__:")){let C=Of(D);if(C){let N=C.position+k;e.state.fileDescriptors.set(r,Tf(C.path,N,C.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=y.substring(k))};if(o>=0){let k=Math.min(o,y.length);v=y.substring(0,k),E=k,w=k>=o,S(E);let D=d[0]||"REPLY";e.state.env.set(D,v);for(let C=1;C=0){let k=0,D=0,C=!1;for(;D=l||C,S(E)}else{E=0;let k=0;for(;k=y.length&&(w=!1,E=k,v.length===0&&y.length===0)){for(let D of d)e.state.env.set(D,"");return u&&Xe(e,u),P("","",1)}S(E)}b===` +`&&v.endsWith(` +`)&&(v=v.slice(0,-1));let A=k=>n?k:k.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",A(v)),P("","",w?0:1);let $=he(e.state.env);if(u){let{words:k}=ir(v,$,void 0,n),D=e.limits?.maxArrayElements??1e5;if(k.length>D)return P("",`read: array element limit exceeded (${D}) +`,1);Xe(e,u);for(let C=0;C0){let r=t[0],n=Number.parseInt(r,10);if(r===""||Number.isNaN(n)||!/^-?\d+$/.test(r))return _(`bash: return: ${r}: numeric argument required +`,2);s=(n%256+256)%256}throw new Ne(s)}var us=`set: usage: set [-eux] [+eux] [-o option] [+o option] Options: -e Exit immediately if a command exits with non-zero status +e Disable -e @@ -539,185 +613,185 @@ Options: +o pipefail Disable pipefail -o xtrace Same as -x +o xtrace Disable xtrace -`,jr=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),os=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),Zr=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],qr=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function wn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,at(e))}function Ka(e,t){return t+1{let i=e.state.env.get(`${t}_${r}`)??"";return`[${r}]=${Ke(i)}`});return`${t}=(${n.join(" ")})`}function Ya(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Qa(e,t){let s=Me(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${Ya(r)}]=${Ke(i)}`});return`${t}=(${n.join(" ")} )`}function Ja(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function eo(e){return e.state.associativeArrays??new Set}function Hr(e){let t=Zr.map(n=>`${n.padEnd(16)}${e.state.options[n]?"on":"off"}`),s=qr.map(n=>`${n.padEnd(16)}off`);return`${[...t,...s].sort().join(` +`,ul=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),un=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),hl=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],pl=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Xr(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,Mt(e))}function Lf(e,t){return t+1{let i=e.state.env.get(`${t}_${n}`)??"";return`[${n}]=${_t(i)}`});return`${t}=(${r.join(" ")})`}function Mf(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ff(e,t){let s=Ze(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${Mf(n)}]=${_t(i)}`});return`${t}=(${r.join(" ")} )`}function Vf(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let r of e.state.env.keys()){let n=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(n){let i=n[1];s.has(i)||t.add(i)}}return t}function zf(e){return e.state.associativeArrays??new Set}function fl(e){let t=hl.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),s=pl.map(r=>`${r.padEnd(16)}off`);return`${[...t,...s].sort().join(` `)} -`}function Ur(e){let t=Zr.map(n=>`set ${e.state.options[n]?"-o":"+o"} ${n}`),s=qr.map(n=>`set +o ${n}`);return`${[...t,...s].sort().join(` +`}function dl(e){let t=hl.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),s=pl.map(r=>`set +o ${r}`);return`${[...t,...s].sort().join(` `)} -`}function bn(e,t){if(t.includes("--help"))return F(St);if(t.length===0){let i=Ja(e),a=eo(e),o=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},l=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||o(c)||h&&a.has(h[1])||l.push([c,f])}let u=[];for(let[c,f]of l.sort(([d],[h])=>dh?1:0))u.push(`${c}=${rs(f)}`);for(let c of[...i].sort((f,d)=>fd?1:0))u.push(Xa(e,c));for(let c of[...a].sort((f,d)=>fd?1:0))u.push(Qa(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return dh?1:0}),F(u.length>0?`${u.join(` +`}function Jr(e,t){if(t.includes("--help"))return H(us);if(t.length===0){let i=Vf(e),a=zf(e),l=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||l(c)||h&&a.has(h[1])||o.push([c,f])}let u=[];for(let[c,f]of o.sort(([d],[h])=>dh?1:0))u.push(`${c}=${on(f)}`);for(let c of[...i].sort((f,d)=>fd?1:0))u.push(Wf(e,c));for(let c of[...a].sort((f,d)=>fd?1:0))u.push(Ff(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return dh?1:0}),H(u.length>0?`${u.join(` `)} -`:"")}let s=[],n=()=>s.length>0?F(s.join("")):M,r=0;for(;r1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",o=0;for(let l=1;l0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required -`;if(e.state.options.posix)throw new me(1,"",o);return _(o)}s=a}let n=Number.parseInt(e.state.env.get("#")||"0",10);if(s>n){let a=`bash: shift: shift count out of range -`;if(e.state.options.posix)throw new me(1,"",a);return _(a)}if(s===0)return M;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env.get(String(a))||"");let i=r.slice(s);for(let a=1;a<=n;a++)e.state.env.delete(String(a));for(let a=0;a0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return k("",`bash: source: filename argument required -`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(f),r=f}catch{}}}if(i===null)return _(`bash: ${n}: No such file or directory -`);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Y(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=n;try{let u=Ee(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof B)throw u;if(u instanceof ce)return k(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${n}: ${u.message} -`);throw u}}function Gr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function to(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Kr(e,t){if(to(t))return null;try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Xr(e,t){if(e.state.localVarStack?.has(t)){let n=ts(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Sn(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||es(e,t),!0}}return!1}function Sn(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function Yr(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new V().parseWordFromString(s,!0,!1);return I(e,r)}if(t.includes("$")){let n=new V().parseWordFromString(t,!1,!1);return I(e,n)}return t}async function An(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let b=Se(e,d);for(let[m]of b)e.state.env.delete(`${d}_${m}`);e.state.env.delete(d);continue}let y=e.state.associativeArrays?.has(d);if(y){let b=await Yr(e,h);e.state.env.delete(`${d}_${b}`);continue}let p=Cs(e,d),w=e.state.declaredVars?.has(d);if((e.state.env.has(d)||w)&&!p&&!y){n+=`bash: unset: ${d}: not an array variable -`,r=1;continue}let g=await Kr(e,h);if(g===null&&p){n+=`bash: unset: ${h}: not a valid identifier -`,r=1;continue}if(g===null)continue;if(g<0){let b=Se(e,d),m=b.length,v=e.state.currentLine;if(m===0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript -`,r=1;continue}let E=m+g;if(E<0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript -`,r=1;continue}let S=b[E][0];e.state.env.delete(`${d}_${S}`);continue}e.state.env.delete(`${d}_${g}`);continue}if(!Gr(i)){n+=`bash: unset: \`${i}': not a valid identifier -`,r=1;continue}let c=i;if(ge(e,i)){let d=We(e,i);d&&d!==i&&(c=d)}if(Ze(e,c)){n+=`bash: unset: ${c}: cannot unset: readonly variable -`,r=1;continue}let f=lt(e,c);if(f!==void 0&&f!==e.state.callDepth)Xr(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let y=ts(e,c);y?y.value===void 0?e.state.env.delete(c):e.state.env.set(c,y.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Sn(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let p=Se(e,u);for(let[w]of p)e.state.env.delete(`${u}_${w}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let p=await Yr(e,c);e.state.env.delete(`${u}_${p}`);continue}let d=Cs(e,u);if(e.state.env.has(u)&&!d&&!f){n+=`bash: unset: ${u}: not an array variable -`,r=1;continue}let y=await Kr(e,c);if(y===null&&d){n+=`bash: unset: ${c}: not a valid identifier -`,r=1;continue}if(y===null)continue;if(y<0){let p=Se(e,u),w=p.length,$=e.state.currentLine;if(w===0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript -`,r=1;continue}let g=w+y;if(g<0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript -`,r=1;continue}let b=p[g][0];e.state.env.delete(`${u}_${b}`);continue}e.state.env.delete(`${u}_${y}`);continue}if(!Gr(i)){n+=`bash: unset: \`${i}': not a valid identifier -`,r=1;continue}let o=i;if(ge(e,i)){let u=We(e,i);u&&u!==i&&(o=u)}if(Ze(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable -`,r=1;continue}let l=lt(e,o);if(l!==void 0&&l!==e.state.callDepth)Xr(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((u||c)&&e.state.localVarStack?.has(o)){let f=ts(e,o);f?f.value===void 0?e.state.env.delete(o):e.state.env.set(o,f.value):e.state.env.delete(o)}else e.state.env.delete(o)}else Sn(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return k("",n,r)}var _n=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],so=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function ls(e){return _n.includes(e)}function no(e){return so.includes(e)}function Qr(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],l=0;for(;l1){for(let h=1;h0?`${h.join(` +`:"")}let s=[],r=()=>s.length>0?H(s.join("")):G,n=0;for(;n1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",l=0;for(let o=1;o0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let l=`bash: shift: ${t[0]}: numeric argument required +`;if(e.state.options.posix)throw new Me(1,"",l);return _(l)}s=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(s>r){let a=`bash: shift: shift count out of range +`;if(e.state.options.posix)throw new Me(1,"",a);return _(a)}if(s===0)return G;let n=[];for(let a=1;a<=r;a++)n.push(e.state.env.get(String(a))||"");let i=n.slice(s);for(let a=1;a<=r;a++)e.state.env.delete(String(a));for(let a=0;a0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required +`,2);let r=s[0],n=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),n=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),n=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),n=f}catch{}}}if(i===null)return _(`bash: ${r}: No such file or directory +`);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c{if(e.state.sourceDepth--,e.state.currentSource=l,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Q(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=Ue(i),c=await e.executeScript(u);return o(),c}catch(u){if(o(),u instanceof U)throw u;if(u instanceof Ne)return P(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${r}: ${u.message} +`);throw u}}function ml(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Bf(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function gl(e,t){if(Bf(t))return null;try{let s=new V,r=X(s,t);return await T(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function yl(e,t){if(e.state.localVarStack?.has(t)){let r=sn(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let n=e.state.localVarStack?.get(t);if(!n||n.length===0)tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),si(e,t);else{let i=n[n.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let n=e.state.localScopes[r];if(n.has(t)){let i=n.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),n.delete(t);let a=!1;for(let l=r-1;l>=0;l--)if(e.state.localScopes[l].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,l+1),a=!0;break}return a||tn(e,t),!0}}return!1}function si(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let r=e.state.tempEnvBindings[s];if(r.has(t)){let n=r.get(t);return n===void 0?e.state.env.delete(t):e.state.env.set(t,n),r.delete(t),!0}}return!1}async function wl(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),n=new V().parseWordFromString(s,!0,!1);return W(e,n)}if(t.includes("$")){let r=new V().parseWordFromString(t,!1,!1);return W(e,r)}return t}async function ni(e,t){let s="both",r="",n=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let E=F(e,d);for(let[w]of E)e.state.env.delete(`${d}_${w}`);e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let E=await wl(e,h);e.state.env.delete(`${d}_${E}`);continue}let m=He(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable +`,n=1;continue}let v=await gl(e,h);if(v===null&&m){r+=`bash: unset: ${h}: not a valid identifier +`,n=1;continue}if(v===null)continue;if(v<0){let E=F(e,d),w=E.length,S=e.state.currentLine;if(w===0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript +`,n=1;continue}let A=w+v;if(A<0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript +`,n=1;continue}let $=E[A][0];e.state.env.delete(`${d}_${$}`);continue}e.state.env.delete(`${d}_${v}`);continue}if(!ml(i)){r+=`bash: unset: \`${i}': not a valid identifier +`,n=1;continue}let c=i;if(ee(e,i)){let d=Se(e,i);d&&d!==i&&(c=d)}if(et(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable +`,n=1;continue}let f=qt(e,c);if(f!==void 0&&f!==e.state.callDepth)yl(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let p=sn(e,c);p?p.value===void 0?e.state.env.delete(c):e.state.env.set(c,p.value):e.state.env.delete(c)}else e.state.env.delete(c)}else si(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let m=F(e,u);for(let[y]of m)e.state.env.delete(`${u}_${y}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await wl(e,c);e.state.env.delete(`${u}_${m}`);continue}let d=He(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable +`,n=1;continue}let p=await gl(e,c);if(p===null&&d){r+=`bash: unset: ${c}: not a valid identifier +`,n=1;continue}if(p===null)continue;if(p<0){let m=F(e,u),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript +`,n=1;continue}let v=y+p;if(v<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript +`,n=1;continue}let E=m[v][0];e.state.env.delete(`${u}_${E}`);continue}e.state.env.delete(`${u}_${p}`);continue}if(!ml(i)){r+=`bash: unset: \`${i}': not a valid identifier +`,n=1;continue}let l=i;if(ee(e,i)){let u=Se(e,i);u&&u!==i&&(l=u)}if(et(e,l)){r+=`bash: unset: ${l}: cannot unset: readonly variable +`,n=1;continue}let o=qt(e,l);if(o!==void 0&&o!==e.state.callDepth)yl(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(o!==void 0){let u=e.state.accessedTempEnvVars?.has(l),c=e.state.mutatedTempEnvVars?.has(l);if((u||c)&&e.state.localVarStack?.has(l)){let f=sn(e,l);f?f.value===void 0?e.state.env.delete(l):e.state.env.set(l,f.value):e.state.env.delete(l)}else e.state.env.delete(l)}else si(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l),e.state.functions.delete(i)}return P("",r,n)}var ri=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],qf=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function fn(e){return ri.includes(e)}function Uf(e){return qf.includes(e)}function El(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=[],o=0;for(;o1){for(let h=1;h0?`${h.join(` `)} -`:"",stderr:""}}let d=[];for(let h of _n){let y=e.state.shoptOptions[h];d.push(r?`shopt ${y?"-s":"-u"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(` +`:"",stderr:""}}let d=[];for(let h of ri){let p=e.state.shoptOptions[h];d.push(n?`shopt ${p?"-s":"-u"} ${h}`:`${h} ${p?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(` `)} -`,stderr:""}}let u=!1,c="",f=[];for(let d of o){if(!ls(d)&&!no(d)){c+=`shopt: ${d}: invalid shell option name -`,u=!0;continue}if(s)ls(d)&&(e.state.shoptOptions[d]=!0,Is(e));else if(n)ls(d)&&(e.state.shoptOptions[d]=!1,Is(e));else if(ls(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):r?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:r?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` +`,stderr:""}}let u=!1,c="",f=[];for(let d of l){if(!fn(d)&&!Uf(d)){c+=`shopt: ${d}: invalid shell option name +`,u=!0;continue}if(s)fn(d)&&(e.state.shoptOptions[d]=!0,In(e));else if(r)fn(d)&&(e.state.shoptOptions[d]=!1,In(e));else if(fn(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):n?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:n?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` `)} -`:"",stderr:c}}function ro(e,t,s,n,r,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],l=[...a.keys(),...o].sort();if(t.length===0){let d=[];for(let h of l){let y=o.includes(h),p=a.get(h),w=y||!p?!1:e.state.options[p];s&&!w||n&&w||d.push(r?`set ${w?"-o":"+o"} ${h}`:`${h} ${w?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(` +`:"",stderr:c}}function Zf(e,t,s,r,n,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],o=[...a.keys(),...l].sort();if(t.length===0){let d=[];for(let h of o){let p=l.includes(h),m=a.get(h),y=p||!m?!1:e.state.options[m];s&&!y||r&&y||d.push(n?`set ${y?"-o":"+o"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(` `)} -`:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),y=o.includes(d);if(!h&&!y){c+=`shopt: ${d}: invalid option name -`,u=!0;continue}if(y){s||n||(i?u=!0:r?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,at(e);else if(n)e.state.options[p]=!1,at(e);else{let w=e.state.options[p];i?w||(u=!0):r?(f.push(`set ${w?"-o":"+o"} ${d}`),w||(u=!0)):(f.push(`${d} ${w?"on":"off"}`),w||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` +`:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),p=l.includes(d);if(!h&&!p){c+=`shopt: ${d}: invalid option name +`,u=!0;continue}if(p){s||r||(i?u=!0:n?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let m=a.get(d);if(m)if(s)m==="vi"?e.state.options.emacs=!1:m==="emacs"&&(e.state.options.vi=!1),e.state.options[m]=!0,Mt(e);else if(r)e.state.options[m]=!1,Mt(e);else{let y=e.state.options[m];i?y||(u=!0):n?(f.push(`set ${y?"-o":"+o"} ${d}`),y||(u=!0)):(f.push(`${d} ${y?"on":"off"}`),y||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(` `)} -`:"",stderr:c}}async function Jr(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,l=e.commands.get(o);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:l?{cmd:l,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let l=await e.fs.stat(a);if(!l.isDirectory&&(l.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function cs(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}function io(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function Z(e,t,s,n){return((...r)=>{yt(t,s,`${n} call`);let i=e(...r);return io(i)?i.then(a=>(yt(t,s,`${n} post-await`),a),a=>{throw yt(t,s,`${n} post-await`),a}):(yt(t,s,`${n} return`),i)})}function ao(e,t,s){let n={readFile:Z(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:Z(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:Z(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:Z(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:Z(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:Z(e.exists.bind(e),t,s,"fs.exists"),stat:Z(e.stat.bind(e),t,s,"fs.stat"),mkdir:Z(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:Z(e.readdir.bind(e),t,s,"fs.readdir"),rm:Z(e.rm.bind(e),t,s,"fs.rm"),cp:Z(e.cp.bind(e),t,s,"fs.cp"),mv:Z(e.mv.bind(e),t,s,"fs.mv"),resolvePath:Z(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:Z(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:Z(e.chmod.bind(e),t,s,"fs.chmod"),symlink:Z(e.symlink.bind(e),t,s,"fs.symlink"),link:Z(e.link.bind(e),t,s,"fs.link"),readlink:Z(e.readlink.bind(e),t,s,"fs.readlink"),lstat:Z(e.lstat.bind(e),t,s,"fs.lstat"),realpath:Z(e.realpath.bind(e),t,s,"fs.realpath"),utimes:Z(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(n.readdirWithFileTypes=Z(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),n}function ei(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,n={...e,fs:ao(e.fs,e.requireDefenseContext,s)};return e.exec&&(n.exec=Z(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(n.fetch=Z(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(n.sleep=Z(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(n.getRegisteredCommands=Z(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),n}async function ri(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,l=!1,u=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let w of p.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?a=!0:w==="a"?o=!0:w==="f"&&(l=!0);else u.push(p);let c="",f="",d=0,h=!1,y=!1;for(let p of u){let w=!1;if(a){if(o){let E=await n(p);if(E.length>0){for(let S of E)c+=`${S} -`;h=!0,w=!0}}else{let E=await s(p);E&&(c+=`${E} -`,h=!0,w=!0)}w||(y=!0);continue}let $=!l&&e.state.functions.has(p);if(o&&$){if(!i)if(r)c+=`function -`;else{let E=e.state.functions.get(p),S=E?ti(p,E):`${p} is a function -`;c+=S}w=!0}let g=e.state.env.get(`BASH_ALIAS_${p}`);if(g!==void 0&&(o||!w)&&(i||(r?c+=`alias -`:c+=`${p} is aliased to \`${g}' -`),w=!0,!o)||Vs.has(p)&&(o||!w)&&(i||(r?c+=`keyword -`:c+=`${p} is a shell keyword -`),w=!0,!o))continue;if(!o&&$&&!w){if(!i)if(r)c+=`function -`;else{let E=e.state.functions.get(p),S=E?ti(p,E):`${p} is a function -`;c+=S}w=!0;continue}if(!(ct.has(p)&&(o||!w)&&(i||(r?c+=`builtin -`:c+=`${p} is a shell builtin -`),w=!0,!o))){if(o){let E=await n(p);for(let S of E)i?c+=`${S} -`:r?c+=`file -`:c+=`${p} is ${S} -`,h=!0,w=!0}else if(!w){let E=await s(p);E&&(i?c+=`${E} -`:r?c+=`file -`:c+=`${p} is ${E} -`,h=!0,w=!0)}if(!w&&(y=!0,!r&&!i)){let E=!0;if(p.includes("/")){let S=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(S)&&(E=!1)}E&&(f+=`bash: type: ${p}: not found -`)}}}return i?d=y&&!h?1:0:d=y?1:0,k(c,f,d)}function ti(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>At(r)).join("; "):s=At(t.body),`${e} is a function +`:"",stderr:c}}async function bl(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let l=a.split("/").pop()||t,o=e.commands.get(l);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:o?{cmd:o,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let l=e.commands.get(t);if(l)return{cmd:l,path:a};try{let o=await e.fs.stat(a);if(!o.isDirectory&&(o.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let n=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of n){if(!a)continue;let o=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(o))try{let u=await e.fs.stat(o);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:o};if(c){if(f&&!d)return{script:!0,path:o};if(!f)return{script:!0,path:o}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function dn(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let n=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of n){if(!i)continue;let l=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(l)){try{if((await e.fs.stat(l)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?l:`${i}/${t}`)}}return s}function Hf(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function ie(e,t,s,r){return((...n)=>{Xt(t,s,`${r} call`);let i=e(...n);return Hf(i)?i.then(a=>(Xt(t,s,`${r} post-await`),a),a=>{throw Xt(t,s,`${r} post-await`),a}):(Xt(t,s,`${r} return`),i)})}function jf(e,t,s){let r={readFile:ie(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:ie(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:ie(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:ie(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:ie(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:ie(e.exists.bind(e),t,s,"fs.exists"),stat:ie(e.stat.bind(e),t,s,"fs.stat"),mkdir:ie(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:ie(e.readdir.bind(e),t,s,"fs.readdir"),rm:ie(e.rm.bind(e),t,s,"fs.rm"),cp:ie(e.cp.bind(e),t,s,"fs.cp"),mv:ie(e.mv.bind(e),t,s,"fs.mv"),resolvePath:ie(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:ie(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:ie(e.chmod.bind(e),t,s,"fs.chmod"),symlink:ie(e.symlink.bind(e),t,s,"fs.symlink"),link:ie(e.link.bind(e),t,s,"fs.link"),readlink:ie(e.readlink.bind(e),t,s,"fs.readlink"),lstat:ie(e.lstat.bind(e),t,s,"fs.lstat"),realpath:ie(e.realpath.bind(e),t,s,"fs.realpath"),utimes:ie(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=ie(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),r}function vl(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,r={...e,fs:jf(e.fs,e.requireDefenseContext,s)};return e.exec&&(r.exec=ie(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(r.fetch=ie(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(r.sleep=ie(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=ie(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),r}async function Nl(e,t,s,r){let n=!1,i=!1,a=!1,l=!1,o=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let y of m.slice(1))y==="t"?n=!0:y==="p"?i=!0:y==="P"?a=!0:y==="a"?l=!0:y==="f"&&(o=!0);else u.push(m);let c="",f="",d=0,h=!1,p=!1;for(let m of u){let y=!1;if(a){if(l){let A=await r(m);if(A.length>0){for(let $ of A)c+=`${$} +`;h=!0,y=!0}}else{let A=await s(m);A&&(c+=`${A} +`,h=!0,y=!0)}y||(p=!0);continue}let b=!o&&e.state.functions.has(m);if(l&&b){if(!i)if(n)c+=`function +`;else{let A=e.state.functions.get(m),$=A?Sl(m,A):`${m} is a function +`;c+=$}y=!0}let v=e.state.env.get(`BASH_ALIAS_${m}`);if(v!==void 0&&(l||!y)&&(i||(n?c+=`alias +`:c+=`${m} is aliased to \`${v}' +`),y=!0,!l)||vr.has(m)&&(l||!y)&&(i||(n?c+=`keyword +`:c+=`${m} is a shell keyword +`),y=!0,!l))continue;if(!l&&b&&!y){if(!i)if(n)c+=`function +`;else{let A=e.state.functions.get(m),$=A?Sl(m,A):`${m} is a function +`;c+=$}y=!0;continue}if(!(Ut.has(m)&&(l||!y)&&(i||(n?c+=`builtin +`:c+=`${m} is a shell builtin +`),y=!0,!l))){if(l){let A=await r(m);for(let $ of A)i?c+=`${$} +`:n?c+=`file +`:c+=`${m} is ${$} +`,h=!0,y=!0}else if(!y){let A=await s(m);A&&(i?c+=`${A} +`:n?c+=`file +`:c+=`${m} is ${A} +`,h=!0,y=!0)}if(!y&&(p=!0,!n&&!i)){let A=!0;if(m.includes("/")){let $=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists($)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found +`)}}}return i?d=p&&!h?1:0:d=p?1:0,P(c,f,d)}function Sl(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(n=>fs(n)).join("; "):s=fs(t.body),`${e} is a function ${e} () { ${s} } -`}function At(e){if(Array.isArray(e))return e.map(t=>At(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;sAt(n)).join("; ")}; }`:"..."}function oo(e){let t=e.commands.map(s=>At(s));return(e.negated?"! ":"")+t.join(" | ")}function si(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>ni(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=ni(s);return t}function ni(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function ii(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let l=e.state.env.get(`BASH_ALIAS_${o}`);if(l!==void 0)n?r+=`${o} is an alias for "${l}" -`:r+=`alias ${o}='${l}' -`;else if(Vs.has(o))n?r+=`${o} is a shell keyword -`:r+=`${o} -`;else if(ct.has(o))n?r+=`${o} is a shell builtin -`:r+=`${o} -`;else if(e.state.functions.has(o))n?r+=`${o} is a function -`:r+=`${o} -`;else if(o.includes("/")){let u=e.fs.resolvePath(e.state.cwd,o),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(n?r+=`${o} is ${o} -`:r+=`${o} -`,c=!0)}catch{}c||(n&&(i+=`${o}: not found -`),a=1)}else if(e.commands.has(o)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${o}`;try{let y=await e.fs.stat(h);if(!y.isDirectory&&(y.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${o}`),n?r+=`${o} is ${f} -`:r+=`${f} -`}else n&&(i+=`${o}: not found -`),a=1}return k(r,i,a)}async function ai(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function oi(e,t,s,n,r,i,a,o){let{ctx:l,runCommand:u}=e;if(l.coverage&&ct.has(t)&&l.coverage.hit(`bash:builtin:${t}`),t==="export")return un(l,s);if(t==="unset")return An(l,s);if(t==="exit")return cn(l,s);if(t==="local")return pn(l,s);if(t==="set")return bn(l,s);if(t==="break")return Rs(l,s);if(t==="continue")return Gs(l,s);if(t==="return")return gn(l,s);if(t==="eval"&&l.state.options.posix)return is(l,s,r);if(t==="shift")return $n(l,s);if(t==="getopts")return as(l,s);if(t==="compgen")return Hs(l,s);if(t==="complete")return Zs(l,s);if(t==="compopt")return qs(l,s);if(t==="pushd")return await an(l,s);if(t==="popd")return on(l,s);if(t==="dirs")return ln(l,s);if(t==="source"||t===".")return En(l,s);if(t==="read")return yn(l,s,r,o);if(t==="mapfile"||t==="readarray")return mn(l,s,r);if(t==="declare"||t==="typeset")return sn(l,s);if(t==="readonly")return nn(l,s);if(!i){let c=l.state.functions.get(t);if(c)return ns(l,c,s,r)}if(t==="eval")return is(l,s,r);if(t==="cd")return await Ls(l,s);if(t===":"||t==="true")return M;if(t==="false")return X(!1);if(t==="let")return hn(l,s);if(t==="command")return lo(e,s,r);if(t==="builtin")return co(e,s,r);if(t==="shopt")return Qr(l,s);if(t==="exec"){if(s.length===0)return M;let[c,...f]=s;return u(c,f,[],r,!1,!1,-1)}if(t==="wait")return M;if(t==="type")return await ri(l,s,c=>ai(l,c),c=>cs(l,c));if(t==="hash")return fn(l,s);if(t==="help")return dn(l,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);c=s.slice(0,-1)}return bt(l,c)}return null}async function lo(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return M;let i=!1,a=!1,o=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let f=l[0];if(f==="--"){l=l.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return M;if(o||a)return await ii(n,l,o,a);let[u,...c]=l;return r(u,c,[],s,!0,i,-1)}async function co(e,t,s){let{runCommand:n}=e;if(t.length===0)return M;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return M;let i=r[0];if(!ct.has(i))return _(`bash: builtin: ${i}: not a shell builtin -`);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function li(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,u=await Jr(i,t,r?"/usr/bin:/bin":void 0);if(!u)return mr(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle. +`}function fs(e){if(Array.isArray(e))return e.map(t=>fs(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;sfs(r)).join("; ")}; }`:"..."}function Gf(e){let t=e.commands.map(s=>fs(s));return(e.negated?"! ":"")+t.join(" | ")}function Al(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(r=>$l(r)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=$l(s);return t}function $l(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function kl(e,t,s,r){let n="",i="",a=0;for(let l of t){if(!l){a=1;continue}let o=e.state.env.get(`BASH_ALIAS_${l}`);if(o!==void 0)r?n+=`${l} is an alias for "${o}" +`:n+=`alias ${l}='${o}' +`;else if(vr.has(l))r?n+=`${l} is a shell keyword +`:n+=`${l} +`;else if(Ut.has(l))r?n+=`${l} is a shell builtin +`:n+=`${l} +`;else if(e.state.functions.has(l))r?n+=`${l} is a function +`:n+=`${l} +`;else if(l.includes("/")){let u=e.fs.resolvePath(e.state.cwd,l),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(r?n+=`${l} is ${l} +`:n+=`${l} +`,c=!0)}catch{}c||(r&&(i+=`${l}: not found +`),a=1)}else if(e.commands.has(l)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${l}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${l}`),r?n+=`${l} is ${f} +`:n+=`${f} +`}else r&&(i+=`${l}: not found +`),a=1}return P(n,i,a)}async function _l(e,t){if(t.includes("/")){let n=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(n)){try{let i=await e.fs.stat(n);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let n of r){if(!n)continue;let a=`${n.startsWith("/")?n:e.fs.resolvePath(e.state.cwd,n)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${n}/${t}`}}if(e.commands.has(t)){for(let n of r)if(n==="/usr/bin"||n==="/bin")return`${n}/${t}`;return`/usr/bin/${t}`}return null}async function Pl(e,t,s,r,n,i,a,l){let{ctx:o,runCommand:u}=e;if(o.coverage&&Ut.has(t)&&o.coverage.hit(`bash:builtin:${t}`),t==="export")return qr(o,s);if(t==="unset")return ni(o,s);if(t==="exit")return Br(o,s);if(t==="local")return jr(o,s);if(t==="set")return Jr(o,s);if(t==="break")return mr(o,s);if(t==="continue")return Pr(o,s);if(t==="return")return Kr(o,s);if(t==="eval"&&o.state.options.posix)return ln(o,s,n);if(t==="shift")return ei(o,s);if(t==="getopts")return cn(o,s);if(t==="compgen")return $r(o,s);if(t==="complete")return kr(o,s);if(t==="compopt")return _r(o,s);if(t==="pushd")return await Fr(o,s);if(t==="popd")return Vr(o,s);if(t==="dirs")return zr(o,s);if(t==="source"||t===".")return ti(o,s);if(t==="read")return Qr(o,s,n,l);if(t==="mapfile"||t==="readarray")return Gr(o,s,n);if(t==="declare"||t==="typeset")return Lr(o,s);if(t==="readonly")return Wr(o,s);if(!i){let c=o.state.functions.get(t);if(c)return an(o,c,s,n)}if(t==="eval")return ln(o,s,n);if(t==="cd")return await gr(o,s);if(t===":"||t==="true")return G;if(t==="false")return de(!1);if(t==="let")return Hr(o,s);if(t==="command")return Qf(e,s,n);if(t==="builtin")return Kf(e,s,n);if(t==="shopt")return El(o,s);if(t==="exec"){if(s.length===0)return G;let[c,...f]=s;return u(c,f,[],n,!1,!1,-1)}if(t==="wait")return G;if(t==="type")return await Nl(o,s,c=>_l(o,c),c=>dn(o,c));if(t==="hash")return Ur(o,s);if(t==="help")return Zr(o,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);c=s.slice(0,-1)}return os(o,c)}return null}async function Qf(e,t,s){let{ctx:r,runCommand:n}=e;if(t.length===0)return G;let i=!1,a=!1,l=!1,o=t;for(;o.length>0&&o[0].startsWith("-");){let f=o[0];if(f==="--"){o=o.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(l=!0);o=o.slice(1)}if(o.length===0)return G;if(l||a)return await kl(r,o,l,a);let[u,...c]=o;return n(u,c,[],s,!0,i,-1)}async function Kf(e,t,s){let{runCommand:r}=e;if(t.length===0)return G;let n=t;if(n[0]==="--"&&(n=n.slice(1),n.length===0))return G;let i=n[0];if(!Ut.has(i))return _(`bash: builtin: ${i}: not a shell builtin +`);let[,...a]=n;return r(i,a,[],s,!0,!1,-1)}async function Dl(e,t,s,r,n){let{ctx:i,buildExportedEnv:a,executeUserScript:l}=e,u=await bl(i,t,n?"/usr/bin:/bin":void 0);if(!u)return Lo(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle. `,127):_(`bash: ${t}: command not found `,127);if("error"in u)return u.error==="permission_denied"?_(`bash: ${t}: Permission denied `,126):_(`bash: ${t}: No such file or directory -`,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await o(u.path,s,n);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=n||i.state.groupStdin||"",h=a(),y={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},p=ei(y,t);try{let w=()=>Wn(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,p));return c.trusted?await be.runTrustedAsync(()=>w()):await w()}catch(w){if(w instanceof Y||w instanceof Je)throw w;return _(`${t}: ${Te($e(w))} -`)}}async function Cn(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function _t(e,t,s,n){if(e instanceof de)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof he)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof ce||e instanceof pe||e instanceof B||e instanceof Y)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=$e(e);return{action:"error",stdout:t,stderr:`${s}${r} -`,exitCode:1}}async function us(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let l=await e.executeStatement(o);r+=l.stdout,i+=l.stderr,a=l.exitCode}}catch(o){if(xt(o)||o instanceof pe||o instanceof B||o instanceof Y||o instanceof Re)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${$e(o)} -`,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function ci(e,t){let s="",n="";for(let r of t.clauses){let i=await Cn(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return us(e,r.body,s,n)}return t.elseBody?us(e,t.elseBody,s,n):k(s,n,0)}async function ui(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier -`);let o=[];if(t.words===null)o=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let u of t.words){let c=await ke(e,u);o.push(...c.values)}}catch(u){if(u instanceof Tt)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of o){a++,a>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);n+=f.stdout,r+=f.stderr,i=f.exitCode}}catch(c){let f=_t(c,n,r,e.state.loopDepth);if(n=f.stdout,r=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=k(n,r,f.exitCode??1);return q(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let l=k(n,r,i);return q(e,l,t.redirections)}async function fi(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",a=0,o=0;t.init&&await j(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await j(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);r+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=_t(u,r,i,e.state.loopDepth);if(r=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await j(e,t.update.expression);continue}if(c.action==="error"){let f=k(r,i,c.exitCode??1);return q(e,f,t.redirections)}throw c.error}t.update&&await j(e,t.update.expression)}}finally{e.state.loopDepth--}let l=k(r,i,a);return q(e,l,t.redirections)}async function di(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await I(e,c.content);c.stripTabs&&(f=f.split(` +`,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await l(u.path,s,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",h=a(),p={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},m=vl(p,t);try{let y=()=>gi(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,m));return c.trusted?await Be.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof Q||y instanceof Ct)throw y;return _(`${t}: ${at(qe(y))} +`)}}async function ii(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let r="",n="",i=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,n+=l.stderr,i=l.exitCode}}finally{e.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function ds(e,t,s,r){if(e instanceof Ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof Ce)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof Ne||e instanceof We||e instanceof U||e instanceof Q)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let n=qe(e);return{action:"error",stdout:t,stderr:`${s}${n} +`,exitCode:1}}async function hn(e,t,s="",r=""){let n=s,i=r,a=0;try{for(let l of t){let o=await e.executeStatement(l);n+=o.stdout,i+=o.stderr,a=o.exitCode}}catch(l){if(bs(l)||l instanceof We||l instanceof U||l instanceof Q||l instanceof ft)throw l.prependOutput(n,i),l;return{stdout:n,stderr:`${i}${qe(l)} +`,exitCode:1}}return{stdout:n,stderr:i,exitCode:a}}async function Il(e,t){let s="",r="";for(let n of t.clauses){let i=await ii(e,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return hn(e,n.body,s,r)}return t.elseBody?hn(e,t.elseBody,s,r):P(s,r,0)}async function Cl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier +`);let l=[];if(t.words===null)l=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)l=[];else try{for(let u of t.words){let c=await tt(e,u);l.push(...c.values)}}catch(u){if(u instanceof ut)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of l){a++,a>e.limits.maxLoopIterations&&st(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,n+=f.stderr,i=f.exitCode}}catch(c){let f=ds(c,r,n,e.state.loopDepth);if(r=f.stdout,n=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=P(r,n,f.exitCode??1);return le(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let o=P(r,n,i);return le(e,o,t.redirections)}async function Rl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r=t.line;r!==void 0&&(e.state.currentLine=r);let n="",i="",a=0,l=0;t.init&&await T(e,t.init.expression),e.state.loopDepth++;try{for(;l++,l>e.limits.maxLoopIterations&&st(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,i),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await T(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);n+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=ds(u,n,i,e.state.loopDepth);if(n=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await T(e,t.update.expression);continue}if(c.action==="error"){let f=P(n,i,c.exitCode??1);return le(e,f,t.redirections)}throw c.error}t.update&&await T(e,t.update.expression)}}finally{e.state.loopDepth--}let o=P(n,i,a);return le(e,o,t.redirections)}async function xl(e,t,s=""){let r="",n="",i=0,a=0,l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await W(e,c.content);c.stripTabs&&(f=f.split(` `).map(d=>d.replace(/^\t+/,"")).join(` -`)),o=f}else if(u.operator==="<<<"&&u.target.type==="Word")o=`${await I(e,u.target)} -`;else if(u.operator==="<"&&u.target.type==="Word")try{let c=await I(e,u.target),f=e.fs.resolvePath(e.state.cwd,c);o=await e.fs.readFile(f)}catch{let c=await I(e,u.target);return _(`bash: ${c}: No such file or directory -`)}let l=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Pe(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,u=y.exitCode}}catch(h){if(h instanceof de){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;c=!0}else if(h instanceof he){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,i=y.exitCode}}catch(h){let y=_t(h,n,r,e.state.loopDepth);if(n=y.stdout,r=y.stderr,y.action==="break")break;if(y.action==="continue")continue;if(y.action==="error")return k(n,r,y.exitCode??1);throw y.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return k(n,r,i)}async function hi(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Pe(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await Cn(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let l=await e.executeStatement(o);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(o){let l=_t(o,s,n,e.state.loopDepth);if(s=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return k(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return k(s,n,r)}async function pi(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await I(e,t.word),o=!1;for(let u=0;ufo(t)).join(" ")}function fo(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(` -`),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let l="";for(let u of e){let c=u.charCodeAt(0);u===` -`?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function wi(e,t,s){if(!e.state.options.xtrace)return"";let n=await gi(e),r=[t,...s],i=uo(r);return`${n}${i} -`}async function vi(e,t,s){return e.state.options.xtrace?`${await gi(e)}${t}=${s} -`:""}async function $i(e,t,s){let n=t.timed?bs():0,r="",i=M,a=0,o=[],l="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else if(b instanceof pe&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else throw $&&(e.state.env=$),b}$&&(e.state.env=$),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),y?i=g:(t.pipeStderr?.[d]??!1?r=He(g.stderr)+gs(g):(r=gs(g),l+=g.stderr),i={stdout:"",stderr:"",exitCode:g.exitCode})}if(l&&(i={...i,stderr:l+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;de.limits.maxLoopIterations&&st(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,u=p.exitCode}}catch(h){if(h instanceof Ie){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;c=!0}else if(h instanceof Ce){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,i=p.exitCode}}catch(h){let p=ds(h,r,n,e.state.loopDepth);if(r=p.stdout,n=p.stderr,p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return P(r,n,p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return P(r,n,i)}async function Ol(e,t){let s="",r="",n=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&st(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r);let a=await ii(e,t.condition);if(s+=a.stdout,r+=a.stderr,a.exitCode===0)break;try{for(let l of t.body){let o=await e.executeStatement(l);s+=o.stdout,r+=o.stderr,n=o.exitCode}}catch(l){let o=ds(l,s,r,e.state.loopDepth);if(s=o.stdout,r=o.stderr,o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return P(s,r,o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return P(s,r,n)}async function Tl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=await W(e,t.word),l=!1;for(let u=0;uYf(t)).join(" ")}function Yf(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),r=e.includes(` +`),n=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||r||n||i){let o="";for(let u of e){let c=u.charCodeAt(0);u===` +`?o+="\\n":u===" "?o+="\\t":u==="\\"?o+="\\\\":u==="'"?o+="'":u==='"'?o+='"':c<32||c===127?c<256?o+=`\\x${c.toString(16).padStart(2,"0")}`:o+=`\\u${c.toString(16).padStart(4,"0")}`:o+=u}return`$'${o}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Fl(e,t,s){if(!e.state.options.xtrace)return"";let r=await Ml(e),n=[t,...s],i=Xf(n);return`${r}${i} +`}async function Vl(e,t,s){return e.state.options.xtrace?`${await Ml(e)}${t}=${s} +`:""}async function Bl(e,t,s){let r=t.timed?An():0,n="",i=G,a=0,l=[],o="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else if(E instanceof We&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else throw b&&(e.state.env=b),E}b&&(e.state.env=b),l.push(v.exitCode),v.exitCode!==0&&(a=v.exitCode),p?i=v:(t.pipeStderr?.[d]??!1?n=At(v.stderr)+bn(v):(n=bn(v),o+=v.stderr),i={stdout:"",stderr:"",exitCode:v.exitCode})}if(o&&(i={...i,stderr:o+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;d{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(o&&l?await mo(e,t,s,n,r,u,c=>{a+=c}):l?await yo(e,s,n,r,u):await go(e,s,n,r,u),t.name){i.set(s,e.state.env.get(s));let f=`(${n.map(d=>Lt(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function po(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function mo(e,t,s,n,r,i,a){let o=[];for(let l of n){let u=Es(l);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await I(e,{type:"Word",parts:f}):h="",h=G(e,h),o.push({type:"keyed",key:c,value:h,append:d})}else{let c=await I(e,l);o.push({type:"invalid",expandedValue:c})}}r||i();for(let l of o)if(l.type==="keyed")if(l.append){let u=e.state.env.get(`${s}_${l.key}`)??"";e.state.env.set(`${s}_${l.key}`,u+l.value)}else e.state.env.set(`${s}_${l.key}`,l.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array -`)}}async function yo(e,t,s,n,r){let i=[];for(let o of s){let l=Es(o);if(l){let{key:u,valueParts:c,append:f}=l,d;c.length>0?d=await I(e,{type:"Word",parts:c}):d="",d=G(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await ke(e,o);i.push({type:"non-keyed",values:u.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let l;try{let u=new V,c=Q(u,o.indexExpr);l=await j(e,c.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))l=Number.parseInt(o.indexExpr,10);else{let u=e.state.env.get(o.indexExpr);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}}if(o.append){let u=e.state.env.get(`${t}_${l}`)??"";e.state.env.set(`${t}_${l}`,u+o.value)}else e.state.env.set(`${t}_${l}`,o.value);a=l+1}else for(let l of o.values)e.state.env.set(`${t}_${a++}`,l)}async function go(e,t,s,n,r){let i=[];for(let o of s){let l=await ke(e,o);i.push(...l.values)}let a=0;if(n){let o=Se(e,t);if(o.length>0)a=Math.max(...o.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(e.state.env.set(`${t}_0`,l),e.state.env.delete(t),a=1)}}else r();for(let o=0;o0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function Si(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),a=new V().parseWordFromString(r,!0,!1);n=await I(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);n=await I(e,i)}else n=s;return`${t}_${n}`}async function vo(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new V,a=Q(i,n);r=await j(e,a.expression,!1)}catch(i){if(i instanceof Ue){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message} -`;if(i.fatal)throw new B(1,"",l);return{index:0,error:k("",l,1)}}let a=e.state.env.get(s);r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=Se(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:k("",`bash: line ${o}: ${t}[${s}]: bad array subscript -`,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:k("",`bash: line ${o}: ${t}[${s}]: bad array subscript -`,1)}}}return{index:r}}async function bo(e,t,s,n,r,i){let a="",o=s,l=null;if(ge(e,s)){let f=qn(e,s,n);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:k("",`bash: ${s}: circular name reference -`,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};o=f;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Ze(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable -`,{continueToNext:!0,xtraceOutput:a};let f=ee(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if($t(e,o))try{let f=new V;if(r){let h=`(${e.state.env.get(o)||"0"}) + (${n})`,y=Q(f,h);u=String(await j(e,y.expression))}else{let d=Q(f,n);u=String(await j(e,d.expression))}}catch{u="0"}else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js"),d=f(e,o)?`${o}_0`:o;u=r?(e.state.env.get(d)||"")+n:n}u=ft(e,o,u),a+=await vi(e,o,u);let c=o;if(l)c=await $o(e,l);else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js");f(e,o)&&(c=`${o}_0`)}return t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(f=>f.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function $o(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Si(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new V,o=Q(a,n);i=await j(e,o.expression,!1)}catch{let a=e.state.env.get(n);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=Se(e,s);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Ai(e,t,s,n){let r=await Oe(e,t.redirections);if(r)return r;let i=new Map(e.state.env),a=e.state.cwd,o={...e.state.options},l=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map(S=>new Map(S)),c){e.state.localVarStack=new Map;for(let[S,O]of c.entries())e.state.localVarStack.set(S,O.map(N=>({...N})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,y=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,w=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;s&&(e.state.groupStdin=s);let g="",b="",m=0,v=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.functions=l,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=y,e.state.groupStdin=$,e.state.bashPid=w,e.state.lastArg=p};try{for(let S of t.body){let O=await n(S);g+=O.stdout,b+=O.stderr,m=O.exitCode}}catch(S){if(v(),S instanceof Y)throw S;if(S instanceof Re){g+=S.stdout,b+=S.stderr;let N=k(g,b,0);return q(e,N,t.redirections)}if(S instanceof de||S instanceof he){g+=S.stdout,b+=S.stderr;let N=k(g,b,0);return q(e,N,t.redirections)}if(S instanceof B){g+=S.stdout,b+=S.stderr;let N=k(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof ce){g+=S.stdout,b+=S.stderr;let N=k(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof pe){let N=k(g+S.stdout,b+S.stderr,S.exitCode);return q(e,N,t.redirections)}let O=k(g,`${b}${$e(S)} -`,1);return q(e,O,t.redirections)}v();let E=k(g,b,m);return q(e,E,t.redirections)}async function _i(e,t,s,n){let r="",i="",a=0,o=await ss(e,t.redirections);if(o)return o;let l=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await I(e,d.content);d.stripTabs&&(h=h.split(` -`).map(p=>p.replace(/^\t+/,"")).join(` -`));let y=f.fd??0;y!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),ae(e),e.state.fileDescriptors.set(y,h)):l=h}else if(f.operator==="<<<"&&f.target.type==="Word")l=`${await I(e,f.target)} -`;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await I(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=await I(e,f.target);return k("",`bash: ${d}: No such file or directory -`,1)}let u=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let f of t.body){let d=await n(f);r+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof Y)throw f;if(xt(f)||f instanceof pe||f instanceof B)throw f.prependOutput(r,i),f;return k(r,`${i}${$e(f)} -`,1)}e.state.groupStdin=u;let c=k(r,i,a);return q(e,c,t.redirections)}async function Ci(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory -`,127)}if(i.startsWith("#!")){let w=i.indexOf(` -`);w!==-1&&(i=i.slice(w+1))}let a=new Map(e.state.env),o=e.state.cwd,l={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,y=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let w=0;w{e.state.env=a,e.state.cwd=o,e.state.options=l,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=y};try{let $=new V().parse(i),g=await r($);return p(),g}catch(w){if(p(),w instanceof B||w instanceof Y)throw w;if(w.name==="ParseException")return _(`bash: ${t}: ${w.message} -`);throw w}}var Ct=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Je(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let a=this.ctx.state.env.get(i);a!==void 0&&(r[i]=a)}return r}async executeScript(t){this.assertDefenseContext("execution");let s="",n="",r=0,i=this.ctx.limits.maxOutputSize,a=(o,l)=>{s.length+n.length+o.length+l.length>i&&Pe(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=o,n+=l};for(let o of t.statements)try{let l=await this.executeStatement(o);a(ws(l),l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(l){if(l instanceof B)throw l.prependOutput(s,n),l;if(l instanceof me)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Y)throw l;if(l instanceof pe)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Fn)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Dt)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Ue){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof Mn){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof de||l instanceof he){if(this.ctx.state.loopDepth>0)throw l.prependOutput(s,n),l;a(l.stdout,l.stderr);continue}throw l instanceof ce&&l.prependOutput(s,n),l}return{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Ci(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new It;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Pe(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Rt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return M;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText} -`);let r=0,i=-1,a=!1;for(let u=0;u0?t.operators[u-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(c);s+=ws(d),n+=d.stderr,r=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let o=ithis.executeCommand(s,n))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return ci(this.ctx,t);case"For":return ui(this.ctx,t);case"CStyleFor":return fi(this.ctx,t);case"While":return di(this.ctx,t,s);case"Until":return hi(this.ctx,t);case"Case":return pi(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Or(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return M}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof Tt)return _(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let m=t,v=100;for(;v>0;){let E=this.expandAlias(m);if(E===m)break;m=E,v--}this.aliasExpansionStack.clear(),m!==t&&(t=m)}this.ctx.state.expansionStderr="";let n=await Ei(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let v=await Oe(this.ctx,t.redirections);if(v)return v;let E=k("",i,0);return q(this.ctx,E,t.redirections)}this.ctx.state.lastArg="";let m=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",k("",m,this.ctx.state.lastExitCode)}let a=t.name&&kn(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(r.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let m of o)this.ctx.state.tempExportedVars.add(m)}let l=await ss(this.ctx,t.redirections);if(l){for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);return l}let u=-1;for(let m of t.redirections){if((m.operator==="<<"||m.operator==="<<-")&&m.target.type==="HereDoc"){let v=m.target,E=await I(this.ctx,v.content);v.stripTabs&&(E=E.split(` -`).map(O=>O.replace(/^\t+/,"")).join(` -`)),E=He(E);let S=m.fd??0;S!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),ae(this.ctx),this.ctx.state.fileDescriptors.set(S,E)):s=E;continue}if(m.operator==="<<<"&&m.target.type==="Word"){s=He(`${await I(this.ctx,m.target)} -`);continue}if(m.operator==="<"&&m.target.type==="Word")try{let v=await I(this.ctx,m.target),E=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);s=await Ln(this.ctx.fs,E)}catch{let v=await I(this.ctx,m.target);for(let[E,S]of r)S===void 0?this.ctx.state.env.delete(E):this.ctx.state.env.set(E,S);return _(`bash: ${v}: No such file or directory -`)}if(m.operator==="<&"&&m.target.type==="Word"){let v=await I(this.ctx,m.target),E=Number.parseInt(v,10);if(!Number.isNaN(E)&&this.ctx.state.fileDescriptors){let S=this.ctx.state.fileDescriptors.get(E);if(S!==void 0)if(S.startsWith("__rw__:")){let O=mi(S);O&&(s=O.content.slice(O.position),u=E)}else S.startsWith("__file__:")||S.startsWith("__file_append__:")||(s=S)}}}let c=await I(this.ctx,t.name),f=[],d=[];if(kn(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let m of t.args){let v=await hr(this.ctx,m);if(v)f.push(v),d.push(!0);else{let E=await pr(this.ctx,m);if(E!==null)f.push(E),d.push(!0);else{let S=await ke(this.ctx,m);for(let O of S.values)f.push(O),d.push(S.quoted)}}}else for(let m of t.args){let v=await ke(this.ctx,m);for(let E of v.values)f.push(E),d.push(v.quoted)}if(!c){if(t.name.parts.every(v=>v.type==="CommandSubstitution"||v.type==="ParameterExpansion"||v.type==="ArithmeticExpansion")){if(f.length>0){let v=f.shift();return d.shift(),await this.runCommand(v,f,d,s,!1,!1,u)}return k("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found -`,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let m of t.redirections){if(m.target.type==="HereDoc"||m.fdVariable)continue;let v=await I(this.ctx,m.target),E=m.fd??(m.operator==="<"||m.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),m.operator){case">":case">|":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);await this.ctx.fs.writeFile(S,"","utf8"),ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file__:${S}`);break}case">>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file_append__:${S}`);break}case"<":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,O)}catch{return _(`bash: ${v}: No such file or directory -`)}break}case"<>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:${O}`)}catch{await this.ctx.fs.writeFile(S,"","utf8"),ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:`)}break}case">&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupout__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupout__:${S}`))}break}case"<&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupin__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupin__:${S}`))}break}}}for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return M}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let m=0;m0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let p,w=null;try{p=await this.runCommand(c,f,d,s,!1,!1,u)}catch(m){if(m instanceof de||m instanceof he)w=m,p=M;else throw m}let $=i+y;if($&&(p={...p,stderr:$+p.stderr}),p=await q(this.ctx,p,t.redirections),w)throw w;if(f.length>0){let m=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(m)){let v=m.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);v&&(m=v[1])}this.ctx.state.lastArg=m}else this.ctx.state.lastArg=c;let g=Pr(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!g)for(let[m,v]of r)this.ctx.state.fullyUnsetLocals?.has(m)||(v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v));if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(c,f,d,h,y,p,w)=>this.runCommand(c,f,d,h,y,p,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await oi(l,t,s,n,r,i,a,o);return u!==null?u:li(l,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return xs(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return cs(this.ctx,t)}async executeSubshell(t,s=""){return Ai(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return _i(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Oe(this.ctx,t.redirections);if(s)return s;try{let n=await j(this.ctx,t.expression.expression),r=X(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=_(`bash: arithmetic expression: ${n.message} -`);return q(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Oe(this.ctx,t.redirections);if(s)return s;try{let n=await ze(this.ctx,t.expression),r=X(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=n instanceof Ue?1:2,i=_(`bash: conditional expression: ${n.message} -`,r);return q(this.ctx,i,t.redirections)}}};var te={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function ki(e){return e?{maxCallDepth:e.maxCallDepth??te.maxCallDepth,maxCommandCount:e.maxCommandCount??te.maxCommandCount,maxLoopIterations:e.maxLoopIterations??te.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??te.maxAwkIterations,maxSedIterations:e.maxSedIterations??te.maxSedIterations,maxJqIterations:e.maxJqIterations??te.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??te.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??te.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??te.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??te.maxGlobOperations,maxStringLength:e.maxStringLength??te.maxStringLength,maxArrayElements:e.maxArrayElements??te.maxArrayElements,maxHeredocSize:e.maxHeredocSize??te.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??te.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??te.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??te.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??te.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??te.maxSourceDepth}:{...te}}import{lookup as Do}from"node:dns";function Pn(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Eo(e){let t=Pn(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Pi(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function So(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Nn(e,t){let s=Pn(e);if(!s)return!1;let n=Eo(t);return!n||s.origin!==n.origin||n.pathPrefix!=="/"&&n.pathPrefix!==""&&Pi(s.pathname)?!1:So(s.pathname,n.pathPrefix)}function Ni(e){return typeof e=="string"?e:e.url}function Oi(e,t){return!t||t.length===0?!1:t.some(s=>Nn(e,Ni(s)))}function On(e){let t=Ao(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Di(t);if(s)return fs(s);let n=Co(t);return n?ko(n):!1}function Ao(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function _o(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let n=Number.parseInt(s,t);return!Number.isFinite(n)||n<0?null:n}function Di(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(l=>_o(l));if(s.some(l=>l===null))return null;let n=s;if(t.length===1){let l=n[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=n;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=n;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[r,i,a,o]=n;return r>255||i>255||a>255||o>255?null:[r,i,a,o]}function Co(e){let t=e,s=null;if(t.includes(".")){let p=t.lastIndexOf(":");if(p<0)return null;let w=t.slice(p+1),$=Di(w);if(!$)return null;s=$,t=t.slice(0,p)}let n=t.includes("::")?t.split("::").length-1:0;if(n>1)return null;let[r,i]=t.split("::"),a=r?r.split(":").filter(Boolean):[],o=i?i.split(":").filter(Boolean):[],l=p=>/^[0-9a-f]{1,4}$/i.test(p)?Number.parseInt(p,16):null,u=a.map(l),c=o.map(l);if(u.some(p=>p===null)||c.some(p=>p===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(n===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let y=[...u,...new Array(h).fill(0),...c];return s&&(y.push(s[0]<<8|s[1]),y.push(s[2]<<8|s[3])),y.length===8?y:null}function fs(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function ko(e){if(e.every(r=>r===0)||e.slice(0,7).every(r=>r===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let r=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return fs(r)}return!1}function Ti(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let n=Ni(s);if(!Pn(n)){t.push(`Invalid URL in allow-list: "${n}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(n);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${n}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${n}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Pi(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${n}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${n}"`)}return t}var Po=typeof __BROWSER__<"u"&&__BROWSER__,dt=null,ds=null,Ii=!1;function No(){if(dt===null&&!Po)try{let e=In("node:async_hooks");ds=In("node:dns"),dt=new e.AsyncLocalStorage}catch{}}function Oo(){if(Ii||(No(),!dt||!ds))return;Ii=!0;let e=dt,t=ds.lookup;function s(...n){let r=n[0],i=e.getStore();if(typeof r!="string"||!i||i.hostname.toLowerCase()!==r.toLowerCase())return t.apply(this,n);let a={},o;if(n.length===2)o=n[1];else if(n.length>=3){let f=n[1];typeof f=="number"?a={family:f}:f&&typeof f=="object"&&(a=f),o=n[2]}if(typeof o!="function")return t.apply(this,n);let l=o,u=a.family===4||a.family===6?a.family:0,c=u===0?i.addresses:i.addresses.filter(f=>f.family===u);if(c.length===0){let f=new Error(`ENOTFOUND ${r}`);f.code="ENOTFOUND",f.errno=-3008,f.syscall="getaddrinfo",f.hostname=r,process.nextTick(()=>l(f));return}process.nextTick(()=>{a.all?l(null,c.map(f=>({address:f.address,family:f.family}))):l(null,c[0].address,c[0].family)})}Object.defineProperty(ds,"lookup",{value:s,writable:!0,configurable:!0})}function xi(e,t){return Oo(),dt?dt.run(e,t):t()}var De=class extends Error{constructor(t,s){let n=s??"URL not in allow-list";super(`Network access denied: ${n}: ${t}`),this.name="NetworkAccessDeniedError"}},kt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Pt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},hs=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},ht=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function To(e){return new Promise((t,s)=>{Do(e,{all:!0},(n,r)=>{n?s(n):t(r)})})}var Io=20,xo=3e4,Ro=10485760,Lo=["GET","HEAD"],Fo=new Set(["GET","HEAD","OPTIONS"]),Mo=new Set([301,302,303,307,308]);function Dn(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Ti(t);if(h.length>0)throw new Error(`Invalid network allow-list: +`,i={...i,stderr:i.stderr+y}}return u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function ql(e,t){let s=new Map,r="";for(let n of t.assignments){let i=n.name;if(n.array){let c=await Jf(e,t,i,n.array,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=n.value?await W(e,n.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript +`,1)};let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=await rd(e,t,o[1],o[2],a,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let u=await ad(e,t,i,a,n.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:s}}async function Jf(e,t,s,r,n,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member +`,1)};if(ee(e,s)){let c=kt(e,s);if(c===void 0||c==="")throw new U(1,"","");let f=Se(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member +`,1)}}if(et(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable +`,{continueToNext:!0,xtraceOutput:a};let c=me(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let l=e.state.associativeArrays?.has(s),o=ed(r),u=()=>{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(l&&o?await td(e,t,s,r,n,u,c=>{a+=c}):o?await sd(e,s,r,n,u):await nd(e,s,r,n,u),t.name){i.set(s,e.state.env.get(s));let f=`(${r.map(d=>Ft(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function ed(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],r=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let n=t.parts[2];return n.type!=="Literal"?!1:n.value.startsWith("]=")||n.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):s.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function td(e,t,s,r,n,i,a){let l=[];for(let o of r){let u=nr(o);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await W(e,{type:"Word",parts:f}):h="",h=ue(e,h),l.push({type:"keyed",key:c,value:h,append:d})}else{let c=await W(e,o);l.push({type:"invalid",expandedValue:c})}}n||i();for(let o of l)if(o.type==="keyed")if(o.append){let u=e.state.env.get(`${s}_${o.key}`)??"";e.state.env.set(`${s}_${o.key}`,u+o.value)}else e.state.env.set(`${s}_${o.key}`,o.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${o.expandedValue}: must use subscript when assigning associative array +`)}}async function sd(e,t,s,r,n){let i=[];for(let l of s){let o=nr(l);if(o){let{key:u,valueParts:c,append:f}=o,d;c.length>0?d=await W(e,{type:"Word",parts:c}):d="",d=ue(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await tt(e,l);i.push({type:"non-keyed",values:u.values})}}r||n();let a=0;for(let l of i)if(l.type==="keyed"){let o;try{let u=new V,c=X(u,l.indexExpr);o=await T(e,c.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))o=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);o=u?Number.parseInt(u,10):0,Number.isNaN(o)&&(o=0)}}if(l.append){let u=e.state.env.get(`${t}_${o}`)??"";e.state.env.set(`${t}_${o}`,u+l.value)}else e.state.env.set(`${t}_${o}`,l.value);a=o+1}else for(let o of l.values)e.state.env.set(`${t}_${a++}`,o)}async function nd(e,t,s,r,n){let i=[];for(let l of s){let o=await tt(e,l);i.push(...o.values)}let a=0;if(r){let l=F(e,t);if(l.length>0)a=Math.max(...l.map(([u])=>typeof u=="number"?u:0))+1;else{let o=e.state.env.get(t);o!==void 0&&(e.state.env.set(`${t}_0`,o),e.state.env.delete(t),a=1)}}else n();for(let l=0;l0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function Ul(e,t,s){let r;if(s.startsWith("'")&&s.endsWith("'"))r=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let n=s.slice(1,-1),a=new V().parseWordFromString(n,!0,!1);r=await W(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);r=await W(e,i)}else r=s;return`${t}_${r}`}async function id(e,t,s){let r=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(r=s.slice(1,-1));let n;if(/^-?\d+$/.test(r))n=Number.parseInt(r,10);else{try{let i=new V,a=X(i,r);n=await T(e,a.expression,!1)}catch(i){if(i instanceof te){let o=`bash: line ${e.state.currentLine}: ${s}: ${i.message} +`;if(i.fatal)throw new U(1,"",o);return{index:0,error:P("",o,1)}}let a=e.state.env.get(s);n=a?Number.parseInt(a,10):0}Number.isNaN(n)&&(n=0)}if(n<0){let i=F(e,t);if(i.length===0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript +`,1)}}if(n=Math.max(...i.map(([l])=>typeof l=="number"?l:0))+1+n,n<0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript +`,1)}}}return{index:n}}async function ad(e,t,s,r,n,i){let a="",l=s,o=null;if(ee(e,s)){let f=Na(e,s,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference +`,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};l=f;let d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(o={arrayName:d[1],subscriptExpr:d[2]},l=d[1])}if(et(e,l)){if(t.name)return a+=`bash: ${l}: readonly variable +`,{continueToNext:!0,xtraceOutput:a};let f=me(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ls(e,l))try{let f=new V;if(n){let h=`(${e.state.env.get(l)||"0"}) + (${r})`,p=X(f,h);u=String(await T(e,p.expression))}else{let d=X(f,r);u=String(await T(e,d.expression))}}catch{u="0"}else{let f=He(e,l)?`${l}_0`:l;u=n?(e.state.env.get(f)||"")+r:r}u=jt(e,l,u),a+=await Vl(e,l,u);let c=l;return o?c=await od(e,o):He(e,l)&&(c=`${l}_0`),t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(l)),e.state.tempEnvBindings?.some(f=>f.has(l))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(l))),{continueToNext:!1,xtraceOutput:a}}async function od(e,t){let{arrayName:s,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(s))return Ul(e,s,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new V,l=X(a,r);i=await T(e,l.expression,!1)}catch{let a=e.state.env.get(r);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=F(e,s);a.length>0&&(i=Math.max(...a.map(o=>o[0]))+1+i)}return`${s}_${i}`}async function Zl(e,t,s,r){let n=await rt(e,t.redirections);if(n)return n;let i=new Map(e.state.env),a=e.state.cwd,l={...e.state.options},o=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map($=>new Map($)),c){e.state.localVarStack=new Map;for(let[$,R]of c.entries())e.state.localVarStack.set($,R.map(I=>({...I})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,p=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let m=e.state.lastArg,y=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let b=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",E="",w=0,S=()=>{e.state.env=i,e.state.cwd=a,e.state.options=l,e.state.functions=o,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=p,e.state.groupStdin=b,e.state.bashPid=y,e.state.lastArg=m};try{for(let $ of t.body){let R=await r($);v+=R.stdout,E+=R.stderr,w=R.exitCode}}catch($){if(S(),$ instanceof Q)throw $;if($ instanceof ft){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof Ie||$ instanceof Ce){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof U){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof Ne){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof We){let I=P(v+$.stdout,E+$.stderr,$.exitCode);return le(e,I,t.redirections)}let R=P(v,`${E}${qe($)} +`,1);return le(e,R,t.redirections)}S();let A=P(v,E,w);return le(e,A,t.redirections)}async function Hl(e,t,s,r){let n="",i="",a=0,l=await rn(e,t.redirections);if(l)return l;let o=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await W(e,d.content);d.stripTabs&&(h=h.split(` +`).map(m=>m.replace(/^\t+/,"")).join(` +`));let p=f.fd??0;p!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),ve(e),e.state.fileDescriptors.set(p,h)):o=h}else if(f.operator==="<<<"&&f.target.type==="Word")o=`${await W(e,f.target)} +`;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await W(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);o=await e.fs.readFile(h)}catch{let d=await W(e,f.target);return P("",`bash: ${d}: No such file or directory +`,1)}let u=e.state.groupStdin;o&&(e.state.groupStdin=o);try{for(let f of t.body){let d=await r(f);n+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof Q)throw f;if(bs(f)||f instanceof We||f instanceof U)throw f.prependOutput(n,i),f;return P(n,`${i}${qe(f)} +`,1)}e.state.groupStdin=u;let c=P(n,i,a);return le(e,c,t.redirections)}async function jl(e,t,s,r,n){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory +`,127)}if(i.startsWith("#!")){let y=i.indexOf(` +`);y!==-1&&(i=i.slice(y+1))}let a=new Map(e.state.env),l=e.state.cwd,o={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,p=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let y=0;y{e.state.env=a,e.state.cwd=l,e.state.options=o,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=p};try{let b=new V().parse(i),v=await n(b);return m(),v}catch(y){if(m(),y instanceof U||y instanceof Q)throw y;if(y.name==="ParseException")return _(`bash: ${t}: ${y.message} +`);throw y}}var hs=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Ct(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let a=this.ctx.state.env.get(i);a!==void 0&&(n[i]=a)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,a=(l,o)=>{s.length+r.length+l.length+o.length>i&&st(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=l,r+=o};for(let l of t.statements)try{let o=await this.executeStatement(l);a(vn(o),o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(o){if(o instanceof U)throw o.prependOutput(s,r),o;if(o instanceof Me)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof Q)throw o;if(o instanceof We)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof Re)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof xe)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof te){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof ws){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof Ie||o instanceof Ce){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,r),o;a(o.stdout,o.stderr);continue}throw o instanceof Ne&&o.prependOutput(s,r),o}return{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return jl(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Es;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&st(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new we(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return G;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText} +`);let n=0,i=-1,a=!1;for(let u=0;u0?t.operators[u-1]:null;if(f==="&&"&&n!==0||f==="||"&&n===0)continue;let d=await this.executePipeline(c);s+=vn(d),r+=d.stderr,n=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}let l=ithis.executeCommand(s,r))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Il(this.ctx,t);case"For":return Cl(this.ctx,t);case"CStyleFor":return Rl(this.ctx,t);case"While":return xl(this.ctx,t,s);case"Until":return Ol(this.ctx,t);case"Case":return Tl(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Xo(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return G}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(r){if(r instanceof ut)return _(r.stderr);throw r}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let w=t,S=100;for(;S>0;){let A=this.expandAlias(w);if(A===w)break;w=A,S--}this.aliasExpansionStack.clear(),w!==t&&(t=w)}this.ctx.state.expansionStderr="";let r=await ql(this.ctx,t);if(r.error)return r.error;let n=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let S=await rt(this.ctx,t.redirections);if(S)return S;let A=P("",i,0);return le(this.ctx,A,t.redirections)}this.ctx.state.lastArg="";let w=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",w,this.ctx.state.lastExitCode)}let a=t.name&&ai(t.name,["local","declare","typeset","export","readonly"]),l=Array.from(n.keys());if(l.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let w of l)this.ctx.state.tempExportedVars.add(w)}let o=await rn(this.ctx,t.redirections);if(o){for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);return o}let u=-1;for(let w of t.redirections){if((w.operator==="<<"||w.operator==="<<-")&&w.target.type==="HereDoc"){let S=w.target,A=await W(this.ctx,S.content);S.stripTabs&&(A=A.split(` +`).map(R=>R.replace(/^\t+/,"")).join(` +`)),A=At(A);let $=w.fd??0;$!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),ve(this.ctx),this.ctx.state.fileDescriptors.set($,A)):s=A;continue}if(w.operator==="<<<"&&w.target.type==="Word"){s=At(`${await W(this.ctx,w.target)} +`);continue}if(w.operator==="<"&&w.target.type==="Word")try{let S=await W(this.ctx,w.target),A=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);s=await mi(this.ctx.fs,A)}catch{let S=await W(this.ctx,w.target);for(let[A,$]of n)$===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,$);return _(`bash: ${S}: No such file or directory +`)}if(w.operator==="<&"&&w.target.type==="Word"){let S=await W(this.ctx,w.target),A=Number.parseInt(S,10);if(!Number.isNaN(A)&&this.ctx.state.fileDescriptors){let $=this.ctx.state.fileDescriptors.get(A);if($!==void 0)if($.startsWith("__rw__:")){let R=Ll($);R&&(s=R.content.slice(R.position),u=A)}else $.startsWith("__file__:")||$.startsWith("__file_append__:")||(s=$)}}}let c=await W(this.ctx,t.name),f=[],d=[];if(ai(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let w of t.args){let S=await Oo(this.ctx,w);if(S)f.push(S),d.push(!0);else{let A=await To(this.ctx,w);if(A!==null)f.push(A),d.push(!0);else{let $=await tt(this.ctx,w);for(let R of $.values)f.push(R),d.push($.quoted)}}}else for(let w of t.args){let S=await tt(this.ctx,w);for(let A of S.values)f.push(A),d.push(S.quoted)}if(!c){if(t.name.parts.every(S=>S.type==="CommandSubstitution"||S.type==="ParameterExpansion"||S.type==="ArithmeticExpansion")){if(f.length>0){let S=f.shift();return d.shift(),await this.runCommand(S,f,d,s,!1,!1,u)}return P("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found +`,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let w of t.redirections){if(w.target.type==="HereDoc"||w.fdVariable)continue;let S=await W(this.ctx,w.target),A=w.fd??(w.operator==="<"||w.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),w.operator){case">":case">|":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);await this.ctx.fs.writeFile($,"","utf8"),ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file__:${$}`);break}case">>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file_append__:${$}`);break}case"<":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,R)}catch{return _(`bash: ${S}: No such file or directory +`)}break}case"<>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:${R}`)}catch{await this.ctx.fs.writeFile($,"","utf8"),ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:`)}break}case">&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let I=this.ctx.state.fileDescriptors.get(R);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupout__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupout__:${$}`))}break}case"<&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let I=this.ctx.state.fileDescriptors.get(R);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupin__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupin__:${$}`))}break}}}for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return G}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let w=0;w0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(n)));let m,y=null;try{m=await this.runCommand(c,f,d,s,!1,!1,u)}catch(w){if(w instanceof Ie||w instanceof Ce)y=w,m=G;else throw w}let b=i+p;if(b&&(m={...m,stderr:b+m.stderr}),m=await le(this.ctx,m,t.redirections),y)throw y;if(f.length>0){let w=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(w)){let S=w.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);S&&(w=S[1])}this.ctx.state.lastArg=w}else this.ctx.state.lastArg=c;let v=Qo(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!v)for(let[w,S]of n)this.ctx.state.fullyUnsetLocals?.has(w)||(S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S));if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return n.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(m={...m,stderr:this.ctx.state.expansionStderr+m.stderr},this.ctx.state.expansionStderr=""),m}async runCommand(t,s,r,n,i=!1,a=!1,l=-1){let o={ctx:this.ctx,runCommand:(c,f,d,h,p,m,y)=>this.runCommand(c,f,d,h,p,m,y),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await Pl(o,t,s,r,n,i,a,l);return u!==null?u:Dl(o,t,s,n,a)}aliasExpansionStack=new Set;expandAlias(t){return Yn(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return dn(this.ctx,t)}async executeSubshell(t,s=""){return Zl(this.ctx,t,s,r=>this.executeStatement(r))}async executeGroup(t,s=""){return Hl(this.ctx,t,s,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await rt(this.ctx,t.redirections);if(s)return s;try{let r=await T(this.ctx,t.expression.expression),n=de(r!==0);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=_(`bash: arithmetic expression: ${r.message} +`);return le(this.ctx,n,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await rt(this.ctx,t.redirections);if(s)return s;try{let r=await bt(this.ctx,t.expression),n=de(r);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=r instanceof te?1:2,i=_(`bash: conditional expression: ${r.message} +`,n);return le(this.ctx,i,t.redirections)}}};var ge={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function Gl(e){return e?{maxCallDepth:e.maxCallDepth??ge.maxCallDepth,maxCommandCount:e.maxCommandCount??ge.maxCommandCount,maxLoopIterations:e.maxLoopIterations??ge.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??ge.maxAwkIterations,maxSedIterations:e.maxSedIterations??ge.maxSedIterations,maxJqIterations:e.maxJqIterations??ge.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??ge.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??ge.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??ge.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??ge.maxGlobOperations,maxStringLength:e.maxStringLength??ge.maxStringLength,maxArrayElements:e.maxArrayElements??ge.maxArrayElements,maxHeredocSize:e.maxHeredocSize??ge.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??ge.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??ge.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??ge.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??ge.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??ge.maxSourceDepth}:{...ge}}import{lookup as yd}from"node:dns";function oi(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function ld(e){let t=oi(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Ql(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function cd(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function li(e,t){let s=oi(e);if(!s)return!1;let r=ld(t);return!r||s.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Ql(s.pathname)?!1:cd(s.pathname,r.pathPrefix)}function Kl(e){return typeof e=="string"?e:e.url}function Xl(e,t){return!t||t.length===0?!1:t.some(s=>li(e,Kl(s)))}function ci(e){let t=ud(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Yl(t);if(s)return pn(s);let r=dd(t);return r?hd(r):!1}function ud(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function fd(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let r=Number.parseInt(s,t);return!Number.isFinite(r)||r<0?null:r}function Yl(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(o=>fd(o));if(s.some(o=>o===null))return null;let r=s;if(t.length===1){let o=r[0];return o>4294967295?null:[o>>>24&255,o>>>16&255,o>>>8&255,o&255]}if(t.length===2){let[o,u]=r;return o>255||u>16777215?null:[o,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[o,u,c]=r;return o>255||u>255||c>65535?null:[o,u,c>>>8&255,c&255]}let[n,i,a,l]=r;return n>255||i>255||a>255||l>255?null:[n,i,a,l]}function dd(e){let t=e,s=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Yl(y);if(!b)return null;s=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[n,i]=t.split("::"),a=n?n.split(":").filter(Boolean):[],l=i?i.split(":").filter(Boolean):[],o=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=a.map(o),c=l.map(o);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...u,...new Array(h).fill(0),...c];return s&&(p.push(s[0]<<8|s[1]),p.push(s[2]<<8|s[3])),p.length===8?p:null}function pn(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function hd(e){if(e.every(n=>n===0)||e.slice(0,7).every(n=>n===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let n=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return pn(n)}return!1}function Jl(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Kl(s);if(!oi(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Ql(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var pd=typeof __BROWSER__<"u"&&__BROWSER__,Gt=null,mn=null,ec=!1;function md(){if(Gt===null&&!pd)try{let e=di("node:async_hooks");mn=di("node:dns"),Gt=new e.AsyncLocalStorage}catch{}}function gd(){if(ec||(md(),!Gt||!mn))return;ec=!0;let e=Gt,t=mn.lookup;function s(...r){let n=r[0],i=e.getStore();if(typeof n!="string"||!i||i.hostname.toLowerCase()!==n.toLowerCase())return t.apply(this,r);let a={},l;if(r.length===2)l=r[1];else if(r.length>=3){let f=r[1];typeof f=="number"?a={family:f}:f&&typeof f=="object"&&(a=f),l=r[2]}if(typeof l!="function")return t.apply(this,r);let o=l,u=a.family===4||a.family===6?a.family:0,c=u===0?i.addresses:i.addresses.filter(f=>f.family===u);if(c.length===0){let f=new Error(`ENOTFOUND ${n}`);f.code="ENOTFOUND",f.errno=-3008,f.syscall="getaddrinfo",f.hostname=n,process.nextTick(()=>o(f));return}process.nextTick(()=>{a.all?o(null,c.map(f=>({address:f.address,family:f.family}))):o(null,c[0].address,c[0].family)})}Object.defineProperty(mn,"lookup",{value:s,writable:!0,configurable:!0})}function tc(e,t){return gd(),Gt?Gt.run(e,t):t()}var it=class extends Error{constructor(t,s){let r=s??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},ps=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ms=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},gn=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},Qt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function wd(e){return new Promise((t,s)=>{yd(e,{all:!0},(r,n)=>{r?s(r):t(n)})})}var Ed=20,bd=3e4,vd=10485760,Sd=["GET","HEAD"],Ad=new Set(["GET","HEAD","OPTIONS"]),$d=new Set([301,302,303,307,308]);function ui(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Jl(t);if(h.length>0)throw new Error(`Invalid network allow-list: ${h.join(` -`)}`)}let s=[];for(let h of t)typeof h=="object"&&h.transform&&h.transform.length>0&&s.push(h);function n(h){if(s.length===0)return null;let y=null;for(let p of s)if(Nn(h,p.url)&&p.transform){y||(y=new Headers);for(let w of p.transform)for(let[$,g]of Object.entries(w.headers))y.set($,g)}return y}let r=e.maxRedirects??Io,i=e.timeoutMs??xo,a=e.maxResponseSize??Ro,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Lo,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??To;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!Oi(h,t))throw new De(h);if(l)try{let y=new URL(h);if(On(y.hostname))throw new De(h,"private/loopback IP address blocked");let p=y.hostname;if(/[a-zA-Z]/.test(p))try{let $=await u(p);for(let{address:b}of $)if(On(b))throw new De(h,"hostname resolves to private/loopback IP address");let g=[];for(let b of $)g.push({address:b.address,family:b.family===6?6:4});if(g.length>0)return{hostname:p,addresses:g}}catch($){if($ instanceof De)throw $;let g=$?.code;if(!(g==="ENOTFOUND"||g==="ENODATA"))throw new De(h,"DNS resolution failed for private IP check")}}catch(y){if(y instanceof De)throw y}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let y=h.toUpperCase();if(!o.includes(y))throw new hs(y,o)}async function d(h,y={}){let p=y.method?.toUpperCase()??"GET",w=await c(h);f(p);let $=h,g=0,b=y.followRedirects??!0,m=y.timeoutMs!==void 0?Math.min(y.timeoutMs,i):i;for(;;){let v=new AbortController,E=xn(()=>v.abort(),m);try{let S=await be.runTrustedAsync(()=>{let O=n($),N=Wo(y.headers,O),x={method:p,headers:N,signal:v.signal,redirect:"manual"};return y.body&&!Fo.has(p)&&(x.body=y.body),w?xi(w,()=>fetch($,x)):fetch($,x)});if(Mo.has(S.status)&&b){let O=S.headers.get("location");if(!O)return await Ri(S,$,a);let N=new URL(O,$).href;try{w=await c(N)}catch{throw new Pt(N)}if(g++,g>r)throw new kt(r);$=N;continue}return await Ri(S,$,a)}finally{Rn(E)}}}return d}function Wo(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[n,r]of t)s.set(n,r);return s}async function Ri(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,a)=>{n[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new ht(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),a=[],o=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(o+=c.byteLength,o>s)throw i.cancel(),new ht(s);a.push(c)}}r=new Uint8Array(o);let l=0;for(let u of a)r.set(u,l),l+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new ht(s);r=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Li(e){return Ye(e)}function Ye(e){return e.statements.map(Fi).join(` -`)}function Fi(e){let t=[];for(let n=0;n0?`${t.join(" ")} `:"")+s.join(" ")}function Mi(e){switch(e.type){case"SimpleCommand":return Vo(e);case"If":return Xo(e);case"For":return Yo(e);case"CStyleFor":return Qo(e);case"While":return Jo(e);case"Until":return el(e);case"Case":return tl(e);case"Subshell":return nl(e);case"Group":return rl(e);case"ArithmeticCommand":return il(e);case"ConditionalCommand":return al(e);case"FunctionDef":return ol(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Vo(e){let t=[];for(let s of e.assignments)t.push(Bo(s));e.name&&t.push(oe(e.name));for(let s of e.args)t.push(oe(s));for(let s of e.redirections)t.push(Vi(s));return t.join(" ")}function Bo(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(oe).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${oe(e.value)}`:`${e.name}${t}`}function oe(e){return e.parts.map(t=>ps(t,!1)).join("")}function je(e){return e.parts.map(t=>ps(t,!0)).join("")}function ps(e,t){switch(e.type){case"Literal":return t?Ho(e.value):jo(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>ps(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Wi(e);case"CommandSubstitution":return e.legacy?`\`${Ye(e.body)}\``:`$(${Ye(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Ye(e.body)})`:`>(${Ye(e.body)})`;case"BraceExpansion":return Go(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function jo(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Ho(e){return e.replace(/[$`"\\]/g,"\\$&")}function Uo(e,t){return e.parts.map(s=>Zo(s,t)).join("")}function Zo(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Wi(e);case"CommandSubstitution":return e.legacy?`\`${Ye(e.body)}\``:`$(${Ye(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;default:return ps(e,!1)}}function Wi(e){return e.operation?`\${${zi(e.parameter,e.operation)}}`:qo(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function qo(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function zi(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${je(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${je(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?je(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${je(t.word)}`;case"Substring":{let s=H(t.offset.expression);return t.length?`${e}:${s}:${H(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",n=t.greedy?`${s}${s}`:s;return`${e}${n}${je(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let n=t.replacement?`/${je(t.replacement)}`:"";return`${e}${s}${je(t.pattern)}${n}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",n=t.all?`${s}${s}`:s,r=t.pattern?je(t.pattern):"";return`${e}${n}${r}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${zi(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Go(e){return`{${e.items.map(Ko).join(",")}}`}function Ko(e){if(e.type==="Word")return oe(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function Vi(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,n=s.quoted?`'${s.delimiter}'`:s.delimiter,r=Uo(s.content,s.quoted);return`${t}${e.operator}${n} -${r}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${oe(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${oe(e.target)}`:`${t}${e.operator} ${oe(e.target)}`}function _e(e){return e.length===0?"":` ${e.map(Vi).join(" ")}`}function we(e){return e.map(Fi).join(` -`)}function Xo(e){let t=[];for(let s=0;s0&&s.push(h);function r(h){if(s.length===0)return null;let p=null;for(let m of s)if(li(h,m.url)&&m.transform){p||(p=new Headers);for(let y of m.transform)for(let[b,v]of Object.entries(y.headers))p.set(b,v)}return p}let n=e.maxRedirects??Ed,i=e.timeoutMs??bd,a=e.maxResponseSize??vd,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Sd,o=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??wd;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!Xl(h,t))throw new it(h);if(o)try{let p=new URL(h);if(ci(p.hostname))throw new it(h,"private/loopback IP address blocked");let m=p.hostname;if(/[a-zA-Z]/.test(m))try{let b=await u(m);for(let{address:E}of b)if(ci(E))throw new it(h,"hostname resolves to private/loopback IP address");let v=[];for(let E of b)v.push({address:E.address,family:E.family===6?6:4});if(v.length>0)return{hostname:m,addresses:v}}catch(b){if(b instanceof it)throw b;let v=b?.code;if(!(v==="ENOTFOUND"||v==="ENODATA"))throw new it(h,"DNS resolution failed for private IP check")}}catch(p){if(p instanceof it)throw p}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let p=h.toUpperCase();if(!l.includes(p))throw new gn(p,l)}async function d(h,p={}){let m=p.method?.toUpperCase()??"GET",y=await c(h);f(m);let b=h,v=0,E=p.followRedirects??!0,w=p.timeoutMs!==void 0?Math.min(p.timeoutMs,i):i;for(;;){let S=new AbortController,A=hi(()=>S.abort(),w);try{let $=await Be.runTrustedAsync(()=>{let R=r(b),I=Nd(p.headers,R),L={method:m,headers:I,signal:S.signal,redirect:"manual"};return p.body&&!Ad.has(m)&&(L.body=p.body),y?tc(y,()=>fetch(b,L)):fetch(b,L)});if($d.has($.status)&&E){let R=$.headers.get("location");if(!R)return await sc($,b,a);let I=new URL(R,b).href;try{y=await c(I)}catch{throw new ms(I)}if(v++,v>n)throw new ps(n);b=I;continue}return await sc($,b,a)}finally{pi(A)}}}return d}function Nd(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,n]of t)s.set(r,n);return s}async function sc(e,t,s){let r=Object.create(null);if(e.headers.forEach((i,a)=>{r[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new Qt(s)}}let n;if(s>0&&e.body){let i=e.body.getReader(),a=[],l=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(l+=c.byteLength,l>s)throw i.cancel(),new Qt(s);a.push(c)}}n=new Uint8Array(l);let o=0;for(let u of a)n.set(u,o),o+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new Qt(s);n=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:r,body:n,url:t}}function nc(e){return Dt(e)}function Dt(e){return e.statements.map(rc).join(` +`)}function rc(e){let t=[];for(let r=0;r0?`${t.join(" ")} `:"")+s.join(" ")}function ic(e){switch(e.type){case"SimpleCommand":return _d(e);case"If":return Ld(e);case"For":return Wd(e);case"CStyleFor":return Md(e);case"While":return Fd(e);case"Until":return Vd(e);case"Case":return zd(e);case"Subshell":return qd(e);case"Group":return Ud(e);case"ArithmeticCommand":return Zd(e);case"ConditionalCommand":return Hd(e);case"FunctionDef":return jd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function _d(e){let t=[];for(let s of e.assignments)t.push(Pd(s));e.name&&t.push(Ae(e.name));for(let s of e.args)t.push(Ae(s));for(let s of e.redirections)t.push(lc(s));return t.join(" ")}function Pd(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(Ae).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${Ae(e.value)}`:`${e.name}${t}`}function Ae(e){return e.parts.map(t=>yn(t,!1)).join("")}function St(e){return e.parts.map(t=>yn(t,!0)).join("")}function yn(e,t){switch(e.type){case"Literal":return t?Id(e.value):Dd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>yn(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return ac(e);case"CommandSubstitution":return e.legacy?`\`${Dt(e.body)}\``:`$(${Dt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Dt(e.body)})`:`>(${Dt(e.body)})`;case"BraceExpansion":return Od(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function Dd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Id(e){return e.replace(/[$`"\\]/g,"\\$&")}function Cd(e,t){return e.parts.map(s=>Rd(s,t)).join("")}function Rd(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return ac(e);case"CommandSubstitution":return e.legacy?`\`${Dt(e.body)}\``:`$(${Dt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;default:return yn(e,!1)}}function ac(e){return e.operation?`\${${oc(e.parameter,e.operation)}}`:xd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function xd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function oc(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${St(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${St(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?St(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${St(t.word)}`;case"Substring":{let s=ne(t.offset.expression);return t.length?`${e}:${s}:${ne(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",r=t.greedy?`${s}${s}`:s;return`${e}${r}${St(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let r=t.replacement?`/${St(t.replacement)}`:"";return`${e}${s}${St(t.pattern)}${r}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",r=t.all?`${s}${s}`:s,n=t.pattern?St(t.pattern):"";return`${e}${r}${n}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${oc(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Od(e){return`{${e.items.map(Td).join(",")}}`}function Td(e){if(e.type==="Word")return Ae(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function lc(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,r=s.quoted?`'${s.delimiter}'`:s.delimiter,n=Cd(s.content,s.quoted);return`${t}${e.operator}${r} +${n}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Ae(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Ae(e.target)}`:`${t}${e.operator} ${Ae(e.target)}`}function Qe(e){return e.length===0?"":` ${e.map(lc).join(" ")}`}function Ve(e){return e.map(rc).join(` +`)}function Ld(e){let t=[];for(let s=0;sthis.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option. -`,exitCode:1,env:ye(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:ye(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);r!==void 0&&a.set("PWD",r);let o={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:cl(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},l=t;s?.rawScript||(l=Bi(t));let u=this.defenseInDepthConfig?be.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=Ee(l,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let g=Object.create(null);for(let b of this.transformPlugins){let m=b.transform({ast:d,metadata:g});d=m.ast,m.metadata&&(g=vs(g,m.metadata))}h=g}let y={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},$=await new Ct(y,o).executeScript(d);return h&&($.metadata=h),this.logResult($)};return c?await c.run(f):await f()}catch(f){if(f instanceof B)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof Ue)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:ye(this.state.env,s?.env)});if(f instanceof It)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:ye(this.state.env,s?.env)});if(f instanceof Y)return this.logResult({stdout:f.stdout,stderr:Te(f.stderr),exitCode:Y.EXIT_CODE,env:ye(this.state.env,s?.env)});if(f instanceof Je)return this.logResult({stdout:"",stderr:`bash: security violation: ${Te(f.message)} -`,exitCode:1,env:ye(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${Te(f.message)} -`,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof Vn)return this.logResult({stdout:"",stderr:`bash: ${Te(f.message)} -`,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${Te(f.message)} -`,exitCode:1,env:ye(this.state.env,s?.env)});throw f}finally{c?.deactivate()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return Le(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=Bi(t),n=Ee(s,{maxHeredocSize:this.limits.maxHeredocSize}),r=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:n,metadata:r});n=a.ast,a.metadata&&(r=vs(r,a.metadata))}return{script:Li(n),ast:n,metadata:r}}};function Bi(e){let t=e.split(` -`),s=[],n=[];for(let r=0;r0){let l=n[n.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of a.matchAll(o)){let u=l[1]==="-",c=l[3];n.push({delimiter:c,stripTabs:u})}}return s.join(` -`)}var ll=new TextDecoder("utf-8",{fatal:!0});function ji(e){if(!e)return e;let t=!1;for(let n=0;n255)return e;r>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let n=0;n0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?U.constants.O_RDONLY:U.constants.O_RDONLY|U.constants.O_NOFOLLOW,l=await U.promises.open(i,o);try{let u=await l.readFile();return new Uint8Array(u)}finally{await l.close()}}catch(a){let o=a.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,n){W(t,"write"),this.assertWritable(`write '${t}'`);let r=L(t);this.ensureParentDirs(r);let i=Fe(n),a=et(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){W(t,"append"),this.assertWritable(`append '${t}'`);let r=L(t),i=Fe(n),a=et(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let l=new Uint8Array(o.length+a.length);l.set(o),l.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){W(t,"stat");let n=L(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.resolveRealPath_(this.toRealPath(n));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await U.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await U.promises.readlink(i),l=this.realTargetToVirtual(n,o),u=this.resolveSymlink(n,l);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){W(t,"lstat");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await U.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return nt(t,s)}realTargetToVirtual(t,s){let n=Zi(s,this.canonicalRoot);if(n.withinRoot){if(!ie.isAbsolute(s))return s;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,s){W(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let n=L(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=qe(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&r.add(u)}for(let[o,l]of this.memory)if(o!==s&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!r.has(c)&&!u.includes("/",1)&&n.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await U.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return n}let o=await U.promises.readdir(a,{withFileTypes:!0});for(let l of o)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else o.code!=="ENOTDIR"&&this.sanitizeError(o,t,"scandir")}return n}async resolveForReaddir(t,s=!1){let n=L(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(n));if(!l)return{normalized:n,outsideOverlay:!0};try{if((await U.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:n,outsideOverlay:!0};let c=await U.promises.readlink(l),f=this.realTargetToVirtual(n,c),d=this.resolveSymlink(n,f);return this.resolveForReaddir(d,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){W(t,"scandir");let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,a)=>ia?1:0)}async readdirWithFileTypes(t){W(t,"scandir");let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,a)=>i.namea.name?1:0)}async rm(t,s){W(t,"rm"),this.assertWritable(`rm '${t}'`);let n=L(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(l,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(n),this.existsOnRealFs(n)&&this.deleted.add(n)}existsOnRealFs(t){let s=this.toRealPath(t),n=this.resolveRealPathParent_(s);if(!n)return!1;try{return U.lstatSync(n),!0}catch{return!1}}async cp(t,s,n){W(t,"cp"),W(s,"cp"),this.assertWritable(`cp '${s}'`);let r=L(t),i=L(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let u of l){let c=r==="/"?`/${u}`:`${r}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return zt(t,s)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.resolveRealPath_(this.toRealPath(t));if(n)try{let r=U.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=ie.join(n,i);U.lstatSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){W(t,"chmod"),this.assertWritable(`chmod '${t}'`);let n=L(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);W(s,"symlink"),this.assertWritable(`symlink '${s}'`);let n=L(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){W(t,"link"),W(s,"link"),this.assertWritable(`link '${s}'`);let n=L(t),r=L(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){W(t,"readlink");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await U.promises.readlink(r);if(!ie.isAbsolute(i)){let a=ie.resolve(ie.dirname(r),i),o;try{o=U.realpathSync(a)}catch{o=a}if(!Ot(o,this.canonicalRoot))return ie.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){W(t,"realpath");let s=L(t),n=new Set,r=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let y=this.toRealPath(u),p=this.resolveRealPath_(y);if(p)try{if((await U.promises.lstat(p)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let $=await U.promises.readlink(p),g=this.realTargetToVirtual(u,$);return n.add(u),u=this.resolveSymlink(u,g),r(u)}}catch(w){if(w.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(w,t,"realpath")}else if(!this.allowSymlinks){let w=this.resolveRealPathParent_(y);if(w)try{if((await U.promises.lstat(w)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch($){if($.message?.includes("ENOENT")||$.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError($,t,"realpath")}}}}return u||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){W(t,"utimes"),this.assertWritable(`utimes '${t}'`);let r=L(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};var se={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},Tn=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new ys({root:s,mountPoint:"/"});this.env=new ms({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Ki.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C +`;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=uc(t.stdout),t.stderr=uc(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option. +`,exitCode:1,env:Fe(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Fe(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);n!==void 0&&a.set("PWD",n);let l={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:Kd(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},o=t;s?.rawScript||(o=cc(t));let u=this.defenseInDepthConfig?Be.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=Ue(o,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let v=Object.create(null);for(let E of this.transformPlugins){let w=E.transform({ast:d,metadata:v});d=w.ast,w.metadata&&(v=Sn(v,w.metadata))}h=v}let p={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},b=await new hs(p,l).executeScript(d);return h&&(b.metadata=h),this.logResult(b)};return c?await c.run(f):await f()}catch(f){if(f instanceof U)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof Me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof te)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:Fe(this.state.env,s?.env)});if(f instanceof Es)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Fe(this.state.env,s?.env)});if(f instanceof Q)return this.logResult({stdout:f.stdout,stderr:at(f.stderr),exitCode:Q.EXIT_CODE,env:Fe(this.state.env,s?.env)});if(f instanceof Ct)return this.logResult({stdout:"",stderr:`bash: security violation: ${at(f.message)} +`,exitCode:1,env:Fe(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${at(f.message)} +`,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof pt)return this.logResult({stdout:"",stderr:`bash: ${at(f.message)} +`,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${at(f.message)} +`,exitCode:1,env:Fe(this.state.env,s?.env)});throw f}finally{c?.deactivate()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return dt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=cc(t),r=Ue(s,{maxHeredocSize:this.limits.maxHeredocSize}),n=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:r,metadata:n});r=a.ast,a.metadata&&(n=Sn(n,a.metadata))}return{script:nc(r),ast:r,metadata:n}}};function Gd(e,t){let s=t;for(let r=0;r0){let c=r[r.length-1];if((c.stripTabs?a.replace(/^\t+/,""):a)===c.delimiter){s.push(a.trimStart()),r.pop();continue}s.push(a);continue}let l=n,o=l==="none"?a.trimStart():a;if(s.push(o),n=Gd(a,l),l!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return s.join(` +`)}var Qd=new TextDecoder("utf-8",{fatal:!0});function uc(e){if(!e)return e;let t=!1;for(let r=0;r255)return e;n>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let r=0;r0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let l=this.allowSymlinks?re.constants.O_RDONLY:re.constants.O_RDONLY|re.constants.O_NOFOLLOW,o=await re.promises.open(i,l);try{let u=await o.readFile();return new Uint8Array(u)}finally{await o.close()}}catch(a){let l=a.code;if(l==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(l==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,r){K(t,"write"),this.assertWritable(`write '${t}'`);let n=B(t);this.ensureParentDirs(n);let i=ht(r),a=Rt(s,i);this.memory.set(n,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(n)}async appendFile(t,s,r){K(t,"append"),this.assertWritable(`append '${t}'`);let n=B(t),i=ht(r),a=Rt(s,i),l;try{l=await this.readFileBuffer(n)}catch{l=new Uint8Array(0)}let o=new Uint8Array(l.length+a.length);o.set(l),o.set(a,l.length),this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(n)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){K(t,"stat");let r=B(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let l=this.resolveSymlink(r,n.target);return this.stat(l,s)}let a=0;return n.type==="file"&&(a=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:a,mtime:n.mtime}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await re.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let l=await re.promises.readlink(i),o=this.realTargetToVirtual(r,l),u=this.resolveSymlink(r,o);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){K(t,"lstat");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(s);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime}}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await re.promises.lstat(n);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return Tt(t,s)}realTargetToVirtual(t,s){let r=hc(s,this.canonicalRoot);if(r.withinRoot){if(!be.isAbsolute(s))return s;let n=r.relativePath;return this.mountPoint==="/"?n:`${this.mountPoint}${n}`}return r.safeName}async mkdir(t,s){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=B(t);if(await this.existsInOverlay(r)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=$t(r);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,n=new Set,i=s==="/"?"/":`${s}/`;for(let l of this.deleted)if(l.startsWith(i)){let o=l.slice(i.length),u=o.split("/")[0];u&&!o.includes("/",u.length)&&n.add(u)}for(let[l,o]of this.memory)if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!n.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await re.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let l=await re.promises.readdir(a,{withFileTypes:!0});for(let o of l)!n.has(o.name)&&!r.has(o.name)&&r.set(o.name,{name:o.name,isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,s=!1){let r=B(t),n=new Set,i=s,a=this.memory.get(r);for(;a&&a.type==="symlink";){if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(r),i=!0,r=this.resolveSymlink(r,a.target),a=this.memory.get(r)}if(a)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let o=this.resolveRealPath_(this.toRealPath(r));if(!o)return{normalized:r,outsideOverlay:!0};try{if((await re.promises.lstat(o)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await re.promises.readlink(o),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.keys()).sort((i,a)=>ia?1:0)}async readdirWithFileTypes(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.values()).sort((i,a)=>i.namea.name?1:0)}async rm(t,s){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=B(t);if(!await this.existsInOverlay(r)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let a=await this.readdir(r);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let l of a){let o=r==="/"?`/${l}`:`${r}/${l}`;await this.rm(o,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let s=this.toRealPath(t),r=this.resolveRealPathParent_(s);if(!r)return!1;try{return re.lstatSync(r),!0}catch{return!1}}async cp(t,s,r){K(t,"cp"),K(s,"cp"),this.assertWritable(`cp '${s}'`);let n=B(t),i=B(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);await this.writeFile(i,o)}else if(l.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(n);for(let u of o){let c=n==="/"?`/${u}`:`${n}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return Ss(t,s)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let n=re.readdirSync(r);for(let i of n){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let l=be.join(r,i);re.lstatSync(l).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=B(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=s;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);K(s,"symlink"),this.assertWritable(`symlink '${s}'`);let r=B(s);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,s){K(t,"link"),K(s,"link"),this.assertWritable(`link '${s}'`);let r=B(t),n=B(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(r);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=await this.readFileBuffer(r);this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:a.mode,mtime:new Date}),this.deleted.delete(n)}async readlink(t){K(t,"readlink");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(s);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await re.promises.readlink(n);if(!be.isAbsolute(i)){let a=be.resolve(be.dirname(n),i),l;try{l=re.realpathSync(a)}catch{l=a}if(!ys(l,this.canonicalRoot))return be.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let s=B(t),r=new Set,n=async l=>{let o=l==="/"?[]:l.slice(1).split("/"),u="";for(let c of o){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(u),m=this.resolveRealPath_(p);if(m)try{if((await re.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await re.promises.readlink(m),v=this.realTargetToVirtual(u,b);return r.add(u),u=this.resolveSymlink(u,v),n(u)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(p);if(y)try{if((await re.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return u||"/"},i=await n(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let n=B(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(n);if(a){a.mtime=r;return}let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:l.mode,mtime:r})}else l.isDirectory&&this.memory.set(n,{type:"directory",mode:l.mode,mtime:r})}};var ye={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},fi=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),r=new En({root:s,mountPoint:"/"});this.env=new wn({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=gc.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C `),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(` -Goodbye!`),process.exit(0)})}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),s=this.env.getEnv().HOME||"/home/user",n=t;return t===s?n="~":t.startsWith(`${s}/`)&&(n=`~${t.slice(s.length)}`),`${se.green}${se.bold}user@virtual${se.reset}:${se.blue}${se.bold}${n}${se.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let n=s.split(/\s+/),r=n[1]?parseInt(n[1],10):0;console.log("exit"),process.exit(r)}this.syncHistory();try{let n=await this.env.exec(s);n.stdout&&process.stdout.write(n.stdout),n.stderr&&process.stderr.write(`${se.red}${n.stderr}${se.reset}`)}catch(n){console.error(`${se.red}Error: ${$e(n)}${se.reset}`)}}}printWelcome(){console.log(` -${se.cyan}${se.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557 +Goodbye!`),process.exit(0)})}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),s=this.env.getEnv().HOME||"/home/user",r=t;return t===s?r="~":t.startsWith(`${s}/`)&&(r=`~${t.slice(s.length)}`),`${ye.green}${ye.bold}user@virtual${ye.reset}:${ye.blue}${ye.bold}${r}${ye.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let r=s.split(/\s+/),n=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(n)}this.syncHistory();try{let r=await this.env.exec(s);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${ye.red}${r.stderr}${ye.reset}`)}catch(r){console.error(`${ye.red}Error: ${qe(r)}${ye.reset}`)}}}printWelcome(){console.log(` +${ye.cyan}${ye.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557 \u2551 Virtual Shell v1.0 \u2551 \u2551 A simulated bash environment in TypeScript \u2551 -\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${se.reset} +\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${ye.reset} -${se.dim}Exploring: ${process.cwd()}${se.reset} +${ye.dim}Exploring: ${process.cwd()}${ye.reset} -Type ${se.green}help${se.reset} for available commands, ${se.green}exit${se.reset} to quit. +Type ${ye.green}help${ye.reset} for available commands, ${ye.green}exit${ye.reset} to quit. Reads from real filesystem, writes stay in memory (OverlayFs). -`)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function dl(){let e=process.argv.slice(2),t={};for(let s=0;s{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function Jd(){let e=process.argv.slice(2),t={};for(let s=0;stypeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var v=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ui=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ee=(e,t)=>{for(var n in t)Va(e,n,{get:t[n],enumerable:!0})},Y7=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K7(t))!X7.call(e,s)&&s!==n&&Va(e,s,{get:()=>t[s],enumerable:!(r=Z7(t,s))||r.enumerable});return e};var Uf=(e,t,n)=>(n=e!=null?q7(Q7(e)):{},Y7(t||!e||!e.__esModule?Va(n,"default",{value:e,enumerable:!0}):n,e));function Bf(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables",allowedKeys:new Set(["NODE_V8_COVERAGE","NODE_DEBUG","NODE_DEBUG_NATIVE","NODE_COMPILE_CACHE","WATCH_REPORT_DEPENDENCIES","FORCE_COLOR","DEBUG","UNDICI_NO_FG","JEST_WORKER_ID","__MINIMATCH_TESTING_PLATFORM__","LOG_TOKENS","LOG_STREAM"])},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"getBuiltinModule",target:process,violationType:"process_get_builtin_module",strategy:"throw",reason:"process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"},{prop:"exit",target:process,violationType:"process_exit",strategy:"throw",reason:"process.exit could terminate the interpreter"},{prop:"abort",target:process,violationType:"process_exit",strategy:"throw",reason:"process.abort could crash the interpreter"},{prop:"kill",target:process,violationType:"process_kill",strategy:"throw",reason:"process.kill could signal other processes"},{prop:"setuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setuid could escalate privileges"},{prop:"setgid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgid could escalate privileges"},{prop:"seteuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.seteuid could escalate effective user privileges"},{prop:"setegid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setegid could escalate effective group privileges"},{prop:"initgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.initgroups could modify supplementary group IDs"},{prop:"setgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgroups could modify supplementary group IDs"},{prop:"umask",target:process,violationType:"process_umask",strategy:"throw",reason:"process.umask could modify file creation permissions"},{prop:"argv",target:process,violationType:"process_argv",strategy:"throw",reason:"process.argv may contain secrets in CLI arguments"},{prop:"cwd",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.cwd could disclose real host working directory path"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"report",target:process,violationType:"process_report",strategy:"throw",reason:"process.report could disclose full environment, host paths, and system info"},{prop:"loadEnvFile",target:process,violationType:"process_env",strategy:"throw",reason:"process.loadEnvFile could load env files bypassing env proxy"},{prop:"setUncaughtExceptionCaptureCallback",target:process,violationType:"process_exception_handler",strategy:"throw",reason:"setUncaughtExceptionCaptureCallback could intercept security errors"},{prop:"send",target:process,violationType:"process_send",strategy:"throw",reason:"process.send could communicate with parent process in IPC contexts"},{prop:"channel",target:process,violationType:"process_channel",strategy:"throw",reason:"process.channel could access IPC channel to parent process"},{prop:"cpuUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.cpuUsage could enable timing side-channel attacks"},{prop:"memoryUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.memoryUsage could enable timing side-channel attacks"},{prop:"hrtime",target:process,violationType:"process_timing",strategy:"throw",reason:"process.hrtime could enable timing side-channel attacks"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"},{prop:"performance",target:globalThis,violationType:"performance_timing",strategy:"throw",reason:"performance.now() provides sub-millisecond timing for side-channel attacks"},{prop:"stdout",target:process,violationType:"process_stdout",strategy:"throw",reason:"process.stdout could bypass interpreter output to write to host stdout"},{prop:"stderr",target:process,violationType:"process_stderr",strategy:"throw",reason:"process.stderr could bypass interpreter output to write to host stderr"},{prop:"__defineGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineGetter__ allows prototype pollution via getter injection"},{prop:"__defineSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineSetter__ allows prototype pollution via setter injection"},{prop:"__lookupGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupGetter__ enables introspection for prototype pollution attacks"},{prop:"__lookupSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupSetter__ enables introspection for prototype pollution attacks"},{prop:"JSON",target:globalThis,violationType:"json_mutation",strategy:"freeze",reason:"Freeze JSON to prevent mutation of parsing/serialization"},{prop:"Math",target:globalThis,violationType:"math_mutation",strategy:"freeze",reason:"Freeze Math to prevent mutation of math utilities"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var Wf=v(()=>{"use strict"});function zf(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function t4(e,t,...n){return Ue.run(e,()=>t(...n))}function n4(e){return e===void 0?{...qa,enabled:!1}:typeof e=="boolean"?{...qa,enabled:e}:{...qa,...e}}var or,Za,J7,me,Ue,e4,qa,Et,cn=v(()=>{"use strict";Wf();or=!0;Za=null;if(!or)try{let{AsyncLocalStorage:e}=Xn("node:async_hooks");Za=e}catch{}J7=` +var e7=Object.create;var Ia=Object.defineProperty;var t7=Object.getOwnPropertyDescriptor;var n7=Object.getOwnPropertyNames;var r7=Object.getPrototypeOf,s7=Object.prototype.hasOwnProperty;var jn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var O=(e,t)=>()=>(e&&(t=e(e=0)),t);var xi=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),te=(e,t)=>{for(var n in t)Ia(e,n,{get:t[n],enumerable:!0})},i7=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of n7(t))!s7.call(e,s)&&s!==n&&Ia(e,s,{get:()=>t[s],enumerable:!(r=t7(t,s))||r.enumerable});return e};var ff=(e,t,n)=>(n=e!=null?e7(r7(e)):{},i7(t||!e||!e.__esModule?Ia(n,"default",{value:e,enumerable:!0}):n,e));function pf(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables",allowedKeys:new Set(["NODE_V8_COVERAGE","NODE_DEBUG","NODE_DEBUG_NATIVE","NODE_COMPILE_CACHE","WATCH_REPORT_DEPENDENCIES","FORCE_COLOR","DEBUG","UNDICI_NO_FG","JEST_WORKER_ID","__MINIMATCH_TESTING_PLATFORM__","LOG_TOKENS","LOG_STREAM"])},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"getBuiltinModule",target:process,violationType:"process_get_builtin_module",strategy:"throw",reason:"process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"},{prop:"exit",target:process,violationType:"process_exit",strategy:"throw",reason:"process.exit could terminate the interpreter"},{prop:"abort",target:process,violationType:"process_exit",strategy:"throw",reason:"process.abort could crash the interpreter"},{prop:"kill",target:process,violationType:"process_kill",strategy:"throw",reason:"process.kill could signal other processes"},{prop:"setuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setuid could escalate privileges"},{prop:"setgid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgid could escalate privileges"},{prop:"seteuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.seteuid could escalate effective user privileges"},{prop:"setegid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setegid could escalate effective group privileges"},{prop:"initgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.initgroups could modify supplementary group IDs"},{prop:"setgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgroups could modify supplementary group IDs"},{prop:"umask",target:process,violationType:"process_umask",strategy:"throw",reason:"process.umask could modify file creation permissions"},{prop:"argv",target:process,violationType:"process_argv",strategy:"throw",reason:"process.argv may contain secrets in CLI arguments"},{prop:"cwd",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.cwd could disclose real host working directory path"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"report",target:process,violationType:"process_report",strategy:"throw",reason:"process.report could disclose full environment, host paths, and system info"},{prop:"loadEnvFile",target:process,violationType:"process_env",strategy:"throw",reason:"process.loadEnvFile could load env files bypassing env proxy"},{prop:"setUncaughtExceptionCaptureCallback",target:process,violationType:"process_exception_handler",strategy:"throw",reason:"setUncaughtExceptionCaptureCallback could intercept security errors"},{prop:"send",target:process,violationType:"process_send",strategy:"throw",reason:"process.send could communicate with parent process in IPC contexts"},{prop:"channel",target:process,violationType:"process_channel",strategy:"throw",reason:"process.channel could access IPC channel to parent process"},{prop:"cpuUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.cpuUsage could enable timing side-channel attacks"},{prop:"memoryUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.memoryUsage could enable timing side-channel attacks"},{prop:"hrtime",target:process,violationType:"process_timing",strategy:"throw",reason:"process.hrtime could enable timing side-channel attacks"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"},{prop:"performance",target:globalThis,violationType:"performance_timing",strategy:"throw",reason:"performance.now() provides sub-millisecond timing for side-channel attacks"},{prop:"stdout",target:process,violationType:"process_stdout",strategy:"throw",reason:"process.stdout could bypass interpreter output to write to host stdout"},{prop:"stderr",target:process,violationType:"process_stderr",strategy:"throw",reason:"process.stderr could bypass interpreter output to write to host stderr"},{prop:"__defineGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineGetter__ allows prototype pollution via getter injection"},{prop:"__defineSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineSetter__ allows prototype pollution via setter injection"},{prop:"__lookupGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupGetter__ enables introspection for prototype pollution attacks"},{prop:"__lookupSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupSetter__ enables introspection for prototype pollution attacks"},{prop:"JSON",target:globalThis,violationType:"json_mutation",strategy:"freeze",reason:"Freeze JSON to prevent mutation of parsing/serialization"},{prop:"Math",target:globalThis,violationType:"math_mutation",strategy:"freeze",reason:"Freeze Math to prevent mutation of math utilities"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var hf=O(()=>{"use strict"});function df(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function l7(e,t,...n){return Ue.run(e,()=>t(...n))}function c7(e){return e===void 0?{...$a,enabled:!1}:typeof e=="boolean"?{...$a,enabled:e}:{...$a,...e}}var Yn,Ta,o7,me,Ue,a7,$a,xt,nn=O(()=>{"use strict";hf();Yn=!0;Ta=null;if(!Yn)try{let{AsyncLocalStorage:e}=jn("node:async_hooks");Ta=e}catch{}o7=` -This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,me=class extends Error{violation;constructor(t,n){super(t+J7),this.violation=n,this.name="SecurityViolationError"}},Ue=!or&&Za?new Za:null,e4=1e3;qa={enabled:!0,auditMode:!1};Et=class e{static instance=null;static importHooksRegistered=!1;static trustedExecutionDepth=new Map;config;refCount=0;patchFailures=[];activeExecutionIds=new Set;contextCache=new Map;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(t){this.config=t}static getInstance(t){let n=n4(t);if(!e.instance)e.instance=new e(n);else{let r=e.instance.config;if(n.enabled!==r.enabled||n.auditMode!==r.auditMode)throw new Error(`DefenseInDepthBox config conflict: requested {enabled: ${n.enabled}, auditMode: ${n.auditMode}} but singleton already has {enabled: ${r.enabled}, auditMode: ${r.auditMode}}. All Bash instances must use the same defense-in-depth security settings, or call DefenseInDepthBox.resetInstance() between incompatible configurations.`)}return e.instance}static resetInstance(){e.instance&&(e.instance.forceDeactivate(),e.instance=null),e.trustedExecutionDepth.clear()}static isInSandboxedContext(){return Ue?Ue?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(Ue)return Ue?.getStore()?.executionId}static enterTrustedScope(t){let n=e.trustedExecutionDepth.get(t)??0;e.trustedExecutionDepth.set(t,n+1)}static leaveTrustedScope(t){let n=e.trustedExecutionDepth.get(t);if(n){if(n===1){e.trustedExecutionDepth.delete(t);return}e.trustedExecutionDepth.set(t,n-1)}}static isTrustedScopeActive(t){return t?(e.trustedExecutionDepth.get(t)??0)>0:!1}isExecutionIdActive(t){return this.activeExecutionIds.has(t)}getCachedContext(t){let n=this.contextCache.get(t);return n||(n={sandboxActive:!0,executionId:t},this.contextCache.set(t,n)),n}getPreferredActiveExecutionId(){if(this.activeExecutionIds.size!==0)for(let t of this.activeExecutionIds)return t}static bindCurrentContext(t){if(!Ue)return t;let n=e.instance,r=Ue.getStore(),s=r?.sandboxActive===!0?r.executionId:n?.getPreferredActiveExecutionId();if(!s)return t;let i=n?.getCachedContext(s)??{sandboxActive:!0,executionId:s};return((...o)=>{let a=e.instance;if(!(a&&!a.isExecutionIdActive(s)&&(a.recordViolation("bound_callback_after_deactivate","bound callback","Bound callback blocked after originating execution was deactivated"),!a.config.auditMode)))return t4(i,t,...o)})}isEnabled(){return this.config.enabled===!0&&Ue!==null&&!or}updateConfig(t){this.config={...this.config,...t}}activate(){if(or||!this.config.enabled||!Ue){let r=zf(),s=!1;return{run:i=>s?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):i(),deactivate:()=>{s=!0},executionId:r}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let t=zf(),n=!1;return{run:r=>n?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):(this.activeExecutionIds.add(t),Ue.run({sandboxActive:!0,executionId:t},r)),deactivate:()=>{n||(n=!0,this.activeExecutionIds.delete(t),this.contextCache.delete(t),this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0))},executionId:t}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.activeExecutionIds.clear(),this.contextCache.clear(),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}getPatchFailures(){return[...this.patchFailures]}clearViolations(){this.violations=[]}getPathForTarget(t,n){return t===globalThis?`globalThis.${n}`:t===process?`process.${n}`:t===Error?`Error.${n}`:t===Function.prototype?`Function.prototype.${n}`:t===Object.prototype?`Object.prototype.${n}`:`.${n}`}static runTrusted(t){if(!Ue)return t();let n=Ue.getStore();if(!n)return t();let{executionId:r}=n;return Ue.run({...n,trusted:!0},()=>{e.enterTrustedScope(r);try{let s=t();return typeof s=="object"&&s!==null&&"finally"in s&&typeof s.finally=="function"?s.finally(()=>{e.leaveTrustedScope(r)}):(e.leaveTrustedScope(r),s)}catch(s){throw e.leaveTrustedScope(r),s}})}static async runTrustedAsync(t){if(!Ue)return t();let n=Ue.getStore();if(!n)return t();let{executionId:r}=n;return Ue.run({...n,trusted:!0},async()=>{e.enterTrustedScope(r);try{return await t()}finally{e.leaveTrustedScope(r)}})}shouldBlock(){if(or||this.config.auditMode||!Ue)return!1;let t=Ue?.getStore();return!(t?.sandboxActive!==!0||t.trusted||e.isTrustedScopeActive(t.executionId))}recordViolation(t,n,r){let s={timestamp:Date.now(),type:t,message:r,path:n,stack:new Error().stack,executionId:Ue?.getStore()?.executionId};if(this.violations.lengthr.includes(i));if(s.length>0)throw this.restorePatches(),new Error(`DefenseInDepthBox: critical patches failed: ${s.join(", ")}`)}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(t){this.patchFailures.push("AsyncFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(t){this.patchFailures.push("GeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(async function*(){}).constructor,n=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&t!==n&&this.patchPrototypeConstructor(t.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(t){this.patchFailures.push("AsyncGeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}}protectErrorPrepareStackTrace(){let t=this;try{let n=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:n});let r=n?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return r},set(s){if(t.shouldBlock()){let i="Error.prepareStackTrace modification is blocked during script execution",o=t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",i);throw new me(i,o)}t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),r=s},configurable:!0})}catch(n){this.patchFailures.push("Error.prepareStackTrace"),console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",n instanceof Error?n.message:n)}}protectPromiseThen(){let t=this;try{let i=function(...o){return Ue.run(this.captured,()=>{if(!this.box.isExecutionIdActive(this.executionId)){if(this.box.recordViolation("promise_then_after_deactivate","Promise.then","Promise.then callback is blocked after defense deactivation"),this.box.config.auditMode)return Reflect.apply(this.cb,void 0,o);if(this.kind==="fulfilled")return o[0];throw o[0]}return Reflect.apply(this.cb,void 0,o)})};var n=i;let r=Object.getOwnPropertyDescriptor(Promise.prototype,"then");this.originalDescriptors.push({target:Promise.prototype,prop:"then",descriptor:r});let s=r?.value;if(typeof s!="function")return;Object.defineProperty(Promise.prototype,"then",{value:function(a,l){if(!Ue)return Reflect.apply(s,this,[a,l]);let c=Ue.getStore(),u=c?.sandboxActive===!0&&c.trusted!==!0?c.executionId:void 0;if(!u)return Reflect.apply(s,this,[a,l]);let f=t.getCachedContext(u),p=(h,d)=>typeof h!="function"?h:i.bind({box:t,executionId:u,captured:f,cb:h,kind:d});return Reflect.apply(s,this,[p(a,"fulfilled"),p(l,"rejected")])},writable:!0,configurable:!0})}catch(r){this.patchFailures.push("Promise.prototype.then"),console.debug("[DefenseInDepthBox] Could not protect Promise.prototype.then:",r instanceof Error?r.message:r)}}patchPrototypeConstructor(t,n,r){let s=this;try{let i=Object.getOwnPropertyDescriptor(t,"constructor");this.originalDescriptors.push({target:t,prop:"constructor",descriptor:i});let o=i?.value;Object.defineProperty(t,"constructor",{get(){if(s.shouldBlock()){let a=`${n} access is blocked during script execution`,l=s.recordViolation(r,n,a);throw new me(a,l)}return s.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&s.recordViolation(r,n,`${n} accessed (audit mode)`),o},set(a){if(s.shouldBlock()){let l=`${n} modification is blocked during script execution`,c=s.recordViolation(r,n,l);throw new me(l,c)}Object.defineProperty(this,"constructor",{value:a,writable:!0,configurable:!0})},configurable:!0})}catch(i){this.patchFailures.push(n),console.debug(`[DefenseInDepthBox] Could not patch ${n}:`,i instanceof Error?i.message:i)}}protectProcessMainModule(){if(typeof process>"u")return;let t=this;try{let n=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:n});let r=n?.value;r!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(t.shouldBlock()){let s="process.mainModule access is blocked during script execution",i=t.recordViolation("process_main_module","process.mainModule",s);throw new me(s,i)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),r},set(s){if(t.shouldBlock()){let i="process.mainModule modification is blocked during script execution",o=t.recordViolation("process_main_module","process.mainModule",i);throw new me(i,o)}Object.defineProperty(process,"mainModule",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(n){this.patchFailures.push("process.mainModule"),console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",n instanceof Error?n.message:n)}}protectProcessExecPath(){if(typeof process>"u")return;let t=this;try{let n=Object.getOwnPropertyDescriptor(process,"execPath");this.originalDescriptors.push({target:process,prop:"execPath",descriptor:n});let r=n?.value??process.execPath;Object.defineProperty(process,"execPath",{get(){if(t.shouldBlock()){let s="process.execPath access is blocked during script execution",i=t.recordViolation("process_exec_path","process.execPath",s);throw new me(s,i)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("process_exec_path","process.execPath","process.execPath accessed (audit mode)"),r},set(s){if(t.shouldBlock()){let i="process.execPath modification is blocked during script execution",o=t.recordViolation("process_exec_path","process.execPath",i);throw new me(i,o)}Object.defineProperty(process,"execPath",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(n){this.patchFailures.push("process.execPath"),console.debug("[DefenseInDepthBox] Could not protect process.execPath:",n instanceof Error?n.message:n)}}lockWellKnownSymbols(){let t=(n,r)=>{try{let s=Object.getOwnPropertyDescriptor(n,r);if(s?.configurable){if("value"in s){Object.defineProperty(n,r,{...s,configurable:!1,writable:!1});return}Object.defineProperty(n,r,{...s,configurable:!1})}}catch{}};for(let n of[Array,Map,Set,RegExp,Promise])t(n,Symbol.species);for(let n of[Array.prototype,String.prototype,Map.prototype,Set.prototype])t(n,Symbol.iterator);t(Symbol.prototype,Symbol.toPrimitive),t(Date.prototype,Symbol.toPrimitive);for(let n of[Symbol.match,Symbol.matchAll,Symbol.replace,Symbol.search,Symbol.split])t(RegExp.prototype,n);t(Function.prototype,Symbol.hasInstance),t(Array.prototype,Symbol.unscopables);for(let n of[Map.prototype,Set.prototype,Promise.prototype,ArrayBuffer.prototype])t(n,Symbol.toStringTag);try{let n=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");this.originalDescriptors.push({target:Error,prop:"stackTraceLimit",descriptor:n}),Object.defineProperty(Error,"stackTraceLimit",{value:Error.stackTraceLimit,writable:!1,configurable:!0})}catch{}}protectProxyRevocable(){let t=this;try{let n=Proxy.revocable;if(typeof n!="function")return;let r=Object.getOwnPropertyDescriptor(Proxy,"revocable");this.originalDescriptors.push({target:Proxy,prop:"revocable",descriptor:r}),Object.defineProperty(Proxy,"revocable",{value:function(i,o){if(t.shouldBlock()){let a="Proxy.revocable is blocked during script execution",l=t.recordViolation("proxy","Proxy.revocable",a);throw new me(a,l)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("proxy","Proxy.revocable","Proxy.revocable called (audit mode)"),n(i,o)},writable:!1,configurable:!0})}catch(n){this.patchFailures.push("Proxy.revocable"),console.debug("[DefenseInDepthBox] Could not protect Proxy.revocable:",n instanceof Error?n.message:n)}}protectDynamicImport(){if(!(or||e.importHooksRegistered))try{let t=this,n=Xn("node:module"),r=new Set;for(let o of n.builtinModules??[]){let a=o.startsWith("node:")?o.slice(5):o;r.add(a);let l=a.indexOf("/");l>0&&r.add(a.slice(0,l))}let s=o=>{if(o.startsWith("./")||o.startsWith("../")||o.startsWith("/")||o.startsWith("file:")||o.startsWith("data:")||o.startsWith("blob:")||o.startsWith("http:")||o.startsWith("https:"))return!1;let a=o.startsWith("node:")?o.slice(5):o;if(!a)return!1;if(typeof n.isBuiltin=="function"&&n.isBuiltin(a)||r.has(a))return!0;let l=a.indexOf("/");return l>0&&r.has(a.slice(0,l))},i=()=>{let o=Ue?.getStore();return t.config.auditMode===!0&&o?.sandboxActive===!0&&o.trusted!==!0&&!e.isTrustedScopeActive(o.executionId)};if(typeof n.registerHooks=="function"){n.registerHooks({resolve(o,a,l){if(o.startsWith("data:")||o.startsWith("blob:"))throw new Error(`dynamic import of ${o.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);if(s(o)){let c=`import(${o})`,u=`dynamic import of Node.js builtin '${o}' is blocked during script execution`;if(t.shouldBlock()){let f=t.recordViolation("dynamic_import_builtin",c,u);throw new me(u,f)}i()&&t.recordViolation("dynamic_import_builtin",c,`dynamic import of Node.js builtin '${o}' called (audit mode)`)}return l(o,a)}}),e.importHooksRegistered=!0;return}if(typeof n.register=="function"){let o=["export async function resolve(specifier, context, nextResolve) {",' if (specifier.startsWith("data:") || specifier.startsWith("blob:")) {',' throw new Error("dynamic import of " + (specifier.startsWith("data:") ? "data:" : "blob:") + " URLs is blocked by defense-in-depth");'," }"," return nextResolve(specifier, context);","}"].join(` -`);n.register(`data:text/javascript,${encodeURIComponent(o)}`),e.importHooksRegistered=!0}}catch(t){console.debug("[DefenseInDepthBox] Could not register import() hooks:",t instanceof Error?t.message:t)}}protectModuleLoad(){if(!or)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof Xn<"u"&&typeof Xn.main<"u"&&(t=Xn.main.constructor),!t||typeof t._load!="function")return;let n=t._load,r=Object.getOwnPropertyDescriptor(t,"_load");this.originalDescriptors.push({target:t,prop:"_load",descriptor:r});let i=this.createBlockingProxy(n,"Module._load","module_load");Object.defineProperty(t,"_load",{value:i,writable:!0,configurable:!0})}catch(t){this.patchFailures.push("Module._load"),console.debug("[DefenseInDepthBox] Could not protect Module._load:",t instanceof Error?t.message:t)}}protectModuleResolveFilename(){if(!or)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof Xn<"u"&&typeof Xn.main<"u"&&(t=Xn.main.constructor),!t||typeof t._resolveFilename!="function")return;let n=t._resolveFilename,r=Object.getOwnPropertyDescriptor(t,"_resolveFilename");this.originalDescriptors.push({target:t,prop:"_resolveFilename",descriptor:r});let i=this.createBlockingProxy(n,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(t,"_resolveFilename",{value:i,writable:!0,configurable:!0})}catch(t){this.patchFailures.push("Module._resolveFilename"),console.debug("[DefenseInDepthBox] Could not protect Module._resolveFilename:",t instanceof Error?t.message:t)}}applyPatch(t){let{target:n,prop:r,violationType:s,strategy:i}=t;try{let o=n[r];if(o===void 0)return;let a=Object.getOwnPropertyDescriptor(n,r);if(this.originalDescriptors.push({target:n,prop:r,descriptor:a}),i==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let l=this.getPathForTarget(n,r),c=typeof o=="function"?this.createBlockingProxy(o,l,s):this.createBlockingObjectProxy(o,l,s,t.allowedKeys);Object.defineProperty(n,r,{value:c,writable:!0,configurable:!0})}}catch(o){let a=this.getPathForTarget(n,r);this.patchFailures.push(a),console.debug(`[DefenseInDepthBox] Could not patch ${a}:`,o instanceof Error?o.message:o)}}restorePatches(){for(let t=this.originalDescriptors.length-1;t>=0;t--){let{target:n,prop:r,descriptor:s}=this.originalDescriptors[t];try{s?Object.defineProperty(n,r,s):delete n[r]}catch(i){let o=this.getPathForTarget(n,r);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,i instanceof Error?i.message:i)}}this.originalDescriptors=[]}}});function i4(e){return typeof e!="function"?e:Et.bindCurrentContext(e)}var r4,s4,ck,uk,Nr,ns,Zs=v(()=>{"use strict";cn();r4=globalThis.setTimeout.bind(globalThis),s4=globalThis.clearTimeout.bind(globalThis),ck=globalThis.setInterval.bind(globalThis),uk=globalThis.clearInterval.bind(globalThis);Nr=((e,t,...n)=>r4(i4(e),t,...n)),ns=s4});var Hf={};ee(Hf,{echoCommand:()=>a4,flagsForFuzzing:()=>l4});function o4(e){let t="",n=0;for(;n=e.length){t+="\\";break}let r=e[n+1];switch(r){case"\\":t+="\\",n+=2;break;case"n":t+=` -`,n+=2;break;case"t":t+=" ",n+=2;break;case"r":t+="\r",n+=2;break;case"a":t+="\x07",n+=2;break;case"b":t+="\b",n+=2;break;case"f":t+="\f",n+=2;break;case"v":t+="\v",n+=2;break;case"e":case"E":t+="\x1B",n+=2;break;case"c":return{output:t,stop:!0};case"0":{let s="",i=n+2;for(;i{"use strict";a4={name:"echo",async execute(e,t){let n=!1,r=t.xpgEcho??!1,s=0;for(;s255)return t;i>127&&(n=!0)}if(!n)return t;let r=new Uint8Array(t.length);for(let s=0;s{"use strict";c4=new TextDecoder("utf-8",{fatal:!0}),u4=new TextEncoder;Gf=""});function U(e){let t=`${e.name} - ${e.summary} +This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,me=class extends Error{violation;constructor(t,n){super(t+o7),this.violation=n,this.name="SecurityViolationError"}},Ue=!Yn&&Ta?new Ta:null,a7=1e3;$a={enabled:!0,auditMode:!1};xt=class e{static instance=null;static importHooksRegistered=!1;static trustedExecutionDepth=new Map;config;refCount=0;patchFailures=[];activeExecutionIds=new Set;contextCache=new Map;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(t){this.config=t}static getInstance(t){let n=c7(t);if(!e.instance)e.instance=new e(n);else{let r=e.instance.config;if(n.enabled!==r.enabled||n.auditMode!==r.auditMode)throw new Error(`DefenseInDepthBox config conflict: requested {enabled: ${n.enabled}, auditMode: ${n.auditMode}} but singleton already has {enabled: ${r.enabled}, auditMode: ${r.auditMode}}. All Bash instances must use the same defense-in-depth security settings, or call DefenseInDepthBox.resetInstance() between incompatible configurations.`)}return e.instance}static resetInstance(){e.instance&&(e.instance.forceDeactivate(),e.instance=null),e.trustedExecutionDepth.clear()}static isInSandboxedContext(){return Ue?Ue?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(Ue)return Ue?.getStore()?.executionId}static enterTrustedScope(t){let n=e.trustedExecutionDepth.get(t)??0;e.trustedExecutionDepth.set(t,n+1)}static leaveTrustedScope(t){let n=e.trustedExecutionDepth.get(t);if(n){if(n===1){e.trustedExecutionDepth.delete(t);return}e.trustedExecutionDepth.set(t,n-1)}}static isTrustedScopeActive(t){return t?(e.trustedExecutionDepth.get(t)??0)>0:!1}isExecutionIdActive(t){return this.activeExecutionIds.has(t)}getCachedContext(t){let n=this.contextCache.get(t);return n||(n={sandboxActive:!0,executionId:t},this.contextCache.set(t,n)),n}getPreferredActiveExecutionId(){if(this.activeExecutionIds.size!==0)for(let t of this.activeExecutionIds)return t}static bindCurrentContext(t){if(!Ue)return t;let n=e.instance,r=Ue.getStore(),s=r?.sandboxActive===!0?r.executionId:n?.getPreferredActiveExecutionId();if(!s)return t;let i=n?.getCachedContext(s)??{sandboxActive:!0,executionId:s};return((...o)=>{let a=e.instance;if(!(a&&!a.isExecutionIdActive(s)&&(a.recordViolation("bound_callback_after_deactivate","bound callback","Bound callback blocked after originating execution was deactivated"),!a.config.auditMode)))return l7(i,t,...o)})}isEnabled(){return this.config.enabled===!0&&Ue!==null&&!Yn}updateConfig(t){this.config={...this.config,...t}}activate(){if(Yn||!this.config.enabled||!Ue){let r=df(),s=!1;return{run:i=>s?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):i(),deactivate:()=>{s=!0},executionId:r}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let t=df(),n=!1;return{run:r=>n?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):(this.activeExecutionIds.add(t),Ue.run({sandboxActive:!0,executionId:t},r)),deactivate:()=>{n||(n=!0,this.activeExecutionIds.delete(t),this.contextCache.delete(t),this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0))},executionId:t}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.activeExecutionIds.clear(),this.contextCache.clear(),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}getPatchFailures(){return[...this.patchFailures]}clearViolations(){this.violations=[]}getPathForTarget(t,n){return t===globalThis?`globalThis.${n}`:t===process?`process.${n}`:t===Error?`Error.${n}`:t===Function.prototype?`Function.prototype.${n}`:t===Object.prototype?`Object.prototype.${n}`:`.${n}`}static runTrusted(t){if(!Ue)return t();let n=Ue.getStore();if(!n)return t();let{executionId:r}=n;return Ue.run({...n,trusted:!0},()=>{e.enterTrustedScope(r);try{let s=t();return typeof s=="object"&&s!==null&&"finally"in s&&typeof s.finally=="function"?s.finally(()=>{e.leaveTrustedScope(r)}):(e.leaveTrustedScope(r),s)}catch(s){throw e.leaveTrustedScope(r),s}})}static async runTrustedAsync(t){if(!Ue)return t();let n=Ue.getStore();if(!n)return t();let{executionId:r}=n;return Ue.run({...n,trusted:!0},async()=>{e.enterTrustedScope(r);try{return await t()}finally{e.leaveTrustedScope(r)}})}shouldBlock(){if(Yn||this.config.auditMode||!Ue)return!1;let t=Ue?.getStore();return!(t?.sandboxActive!==!0||t.trusted||e.isTrustedScopeActive(t.executionId))}recordViolation(t,n,r){let s={timestamp:Date.now(),type:t,message:r,path:n,stack:new Error().stack,executionId:Ue?.getStore()?.executionId};if(this.violations.lengthr.includes(i));if(s.length>0)throw this.restorePatches(),new Error(`DefenseInDepthBox: critical patches failed: ${s.join(", ")}`)}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(t){this.patchFailures.push("AsyncFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(t){this.patchFailures.push("GeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(async function*(){}).constructor,n=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&t!==n&&this.patchPrototypeConstructor(t.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(t){this.patchFailures.push("AsyncGeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}}protectErrorPrepareStackTrace(){let t=this;try{let n=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:n});let r=n?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return r},set(s){if(t.shouldBlock()){let i="Error.prepareStackTrace modification is blocked during script execution",o=t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",i);throw new me(i,o)}t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),r=s},configurable:!0})}catch(n){this.patchFailures.push("Error.prepareStackTrace"),console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",n instanceof Error?n.message:n)}}protectPromiseThen(){let t=this;try{let i=function(...o){return Ue.run(this.captured,()=>{if(!this.box.isExecutionIdActive(this.executionId)){if(this.box.recordViolation("promise_then_after_deactivate","Promise.then","Promise.then callback is blocked after defense deactivation"),this.box.config.auditMode)return Reflect.apply(this.cb,void 0,o);if(this.kind==="fulfilled")return o[0];throw o[0]}return Reflect.apply(this.cb,void 0,o)})};var n=i;let r=Object.getOwnPropertyDescriptor(Promise.prototype,"then");this.originalDescriptors.push({target:Promise.prototype,prop:"then",descriptor:r});let s=r?.value;if(typeof s!="function")return;Object.defineProperty(Promise.prototype,"then",{value:function(a,l){if(!Ue)return Reflect.apply(s,this,[a,l]);let c=Ue.getStore(),u=c?.sandboxActive===!0&&c.trusted!==!0?c.executionId:void 0;if(!u)return Reflect.apply(s,this,[a,l]);let f=t.getCachedContext(u),p=(h,d)=>typeof h!="function"?h:i.bind({box:t,executionId:u,captured:f,cb:h,kind:d});return Reflect.apply(s,this,[p(a,"fulfilled"),p(l,"rejected")])},writable:!0,configurable:!0})}catch(r){this.patchFailures.push("Promise.prototype.then"),console.debug("[DefenseInDepthBox] Could not protect Promise.prototype.then:",r instanceof Error?r.message:r)}}patchPrototypeConstructor(t,n,r){let s=this;try{let i=Object.getOwnPropertyDescriptor(t,"constructor");this.originalDescriptors.push({target:t,prop:"constructor",descriptor:i});let o=i?.value;Object.defineProperty(t,"constructor",{get(){if(s.shouldBlock()){let a=`${n} access is blocked during script execution`,l=s.recordViolation(r,n,a);throw new me(a,l)}return s.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&s.recordViolation(r,n,`${n} accessed (audit mode)`),o},set(a){if(s.shouldBlock()){let l=`${n} modification is blocked during script execution`,c=s.recordViolation(r,n,l);throw new me(l,c)}Object.defineProperty(this,"constructor",{value:a,writable:!0,configurable:!0})},configurable:!0})}catch(i){this.patchFailures.push(n),console.debug(`[DefenseInDepthBox] Could not patch ${n}:`,i instanceof Error?i.message:i)}}protectProcessMainModule(){if(typeof process>"u")return;let t=this;try{let n=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:n});let r=n?.value;r!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(t.shouldBlock()){let s="process.mainModule access is blocked during script execution",i=t.recordViolation("process_main_module","process.mainModule",s);throw new me(s,i)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),r},set(s){if(t.shouldBlock()){let i="process.mainModule modification is blocked during script execution",o=t.recordViolation("process_main_module","process.mainModule",i);throw new me(i,o)}Object.defineProperty(process,"mainModule",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(n){this.patchFailures.push("process.mainModule"),console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",n instanceof Error?n.message:n)}}protectProcessExecPath(){if(typeof process>"u")return;let t=this;try{let n=Object.getOwnPropertyDescriptor(process,"execPath");this.originalDescriptors.push({target:process,prop:"execPath",descriptor:n});let r=n?.value??process.execPath;Object.defineProperty(process,"execPath",{get(){if(t.shouldBlock()){let s="process.execPath access is blocked during script execution",i=t.recordViolation("process_exec_path","process.execPath",s);throw new me(s,i)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("process_exec_path","process.execPath","process.execPath accessed (audit mode)"),r},set(s){if(t.shouldBlock()){let i="process.execPath modification is blocked during script execution",o=t.recordViolation("process_exec_path","process.execPath",i);throw new me(i,o)}Object.defineProperty(process,"execPath",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(n){this.patchFailures.push("process.execPath"),console.debug("[DefenseInDepthBox] Could not protect process.execPath:",n instanceof Error?n.message:n)}}lockWellKnownSymbols(){let t=(n,r)=>{try{let s=Object.getOwnPropertyDescriptor(n,r);if(s?.configurable){if("value"in s){Object.defineProperty(n,r,{...s,configurable:!1,writable:!1});return}Object.defineProperty(n,r,{...s,configurable:!1})}}catch{}};for(let n of[Array,Map,Set,RegExp,Promise])t(n,Symbol.species);for(let n of[Array.prototype,String.prototype,Map.prototype,Set.prototype])t(n,Symbol.iterator);t(Symbol.prototype,Symbol.toPrimitive),t(Date.prototype,Symbol.toPrimitive);for(let n of[Symbol.match,Symbol.matchAll,Symbol.replace,Symbol.search,Symbol.split])t(RegExp.prototype,n);t(Function.prototype,Symbol.hasInstance),t(Array.prototype,Symbol.unscopables);for(let n of[Map.prototype,Set.prototype,Promise.prototype,ArrayBuffer.prototype])t(n,Symbol.toStringTag);try{let n=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");this.originalDescriptors.push({target:Error,prop:"stackTraceLimit",descriptor:n}),Object.defineProperty(Error,"stackTraceLimit",{value:Error.stackTraceLimit,writable:!1,configurable:!0})}catch{}}protectProxyRevocable(){let t=this;try{let n=Proxy.revocable;if(typeof n!="function")return;let r=Object.getOwnPropertyDescriptor(Proxy,"revocable");this.originalDescriptors.push({target:Proxy,prop:"revocable",descriptor:r}),Object.defineProperty(Proxy,"revocable",{value:function(i,o){if(t.shouldBlock()){let a="Proxy.revocable is blocked during script execution",l=t.recordViolation("proxy","Proxy.revocable",a);throw new me(a,l)}return t.config.auditMode&&Ue?.getStore()?.sandboxActive===!0&&t.recordViolation("proxy","Proxy.revocable","Proxy.revocable called (audit mode)"),n(i,o)},writable:!1,configurable:!0})}catch(n){this.patchFailures.push("Proxy.revocable"),console.debug("[DefenseInDepthBox] Could not protect Proxy.revocable:",n instanceof Error?n.message:n)}}protectDynamicImport(){if(!(Yn||e.importHooksRegistered))try{let t=this,n=jn("node:module"),r=new Set;for(let o of n.builtinModules??[]){let a=o.startsWith("node:")?o.slice(5):o;r.add(a);let l=a.indexOf("/");l>0&&r.add(a.slice(0,l))}let s=o=>{if(o.startsWith("./")||o.startsWith("../")||o.startsWith("/")||o.startsWith("file:")||o.startsWith("data:")||o.startsWith("blob:")||o.startsWith("http:")||o.startsWith("https:"))return!1;let a=o.startsWith("node:")?o.slice(5):o;if(!a)return!1;if(typeof n.isBuiltin=="function"&&n.isBuiltin(a)||r.has(a))return!0;let l=a.indexOf("/");return l>0&&r.has(a.slice(0,l))},i=()=>{let o=Ue?.getStore();return t.config.auditMode===!0&&o?.sandboxActive===!0&&o.trusted!==!0&&!e.isTrustedScopeActive(o.executionId)};if(typeof n.registerHooks=="function"){n.registerHooks({resolve(o,a,l){if(o.startsWith("data:")||o.startsWith("blob:"))throw new Error(`dynamic import of ${o.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);if(s(o)){let c=`import(${o})`,u=`dynamic import of Node.js builtin '${o}' is blocked during script execution`;if(t.shouldBlock()){let f=t.recordViolation("dynamic_import_builtin",c,u);throw new me(u,f)}i()&&t.recordViolation("dynamic_import_builtin",c,`dynamic import of Node.js builtin '${o}' called (audit mode)`)}return l(o,a)}}),e.importHooksRegistered=!0;return}if(typeof n.register=="function"){let o=["export async function resolve(specifier, context, nextResolve) {",' if (specifier.startsWith("data:") || specifier.startsWith("blob:")) {',' throw new Error("dynamic import of " + (specifier.startsWith("data:") ? "data:" : "blob:") + " URLs is blocked by defense-in-depth");'," }"," return nextResolve(specifier, context);","}"].join(` +`);n.register(`data:text/javascript,${encodeURIComponent(o)}`),e.importHooksRegistered=!0}}catch(t){console.debug("[DefenseInDepthBox] Could not register import() hooks:",t instanceof Error?t.message:t)}}protectModuleLoad(){if(!Yn)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof jn<"u"&&typeof jn.main<"u"&&(t=jn.main.constructor),!t||typeof t._load!="function")return;let n=t._load,r=Object.getOwnPropertyDescriptor(t,"_load");this.originalDescriptors.push({target:t,prop:"_load",descriptor:r});let i=this.createBlockingProxy(n,"Module._load","module_load");Object.defineProperty(t,"_load",{value:i,writable:!0,configurable:!0})}catch(t){this.patchFailures.push("Module._load"),console.debug("[DefenseInDepthBox] Could not protect Module._load:",t instanceof Error?t.message:t)}}protectModuleResolveFilename(){if(!Yn)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof jn<"u"&&typeof jn.main<"u"&&(t=jn.main.constructor),!t||typeof t._resolveFilename!="function")return;let n=t._resolveFilename,r=Object.getOwnPropertyDescriptor(t,"_resolveFilename");this.originalDescriptors.push({target:t,prop:"_resolveFilename",descriptor:r});let i=this.createBlockingProxy(n,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(t,"_resolveFilename",{value:i,writable:!0,configurable:!0})}catch(t){this.patchFailures.push("Module._resolveFilename"),console.debug("[DefenseInDepthBox] Could not protect Module._resolveFilename:",t instanceof Error?t.message:t)}}applyPatch(t){let{target:n,prop:r,violationType:s,strategy:i}=t;try{let o=n[r];if(o===void 0)return;let a=Object.getOwnPropertyDescriptor(n,r);if(this.originalDescriptors.push({target:n,prop:r,descriptor:a}),i==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let l=this.getPathForTarget(n,r),c=typeof o=="function"?this.createBlockingProxy(o,l,s):this.createBlockingObjectProxy(o,l,s,t.allowedKeys);Object.defineProperty(n,r,{value:c,writable:!0,configurable:!0})}}catch(o){let a=this.getPathForTarget(n,r);this.patchFailures.push(a),console.debug(`[DefenseInDepthBox] Could not patch ${a}:`,o instanceof Error?o.message:o)}}restorePatches(){for(let t=this.originalDescriptors.length-1;t>=0;t--){let{target:n,prop:r,descriptor:s}=this.originalDescriptors[t];try{s?Object.defineProperty(n,r,s):delete n[r]}catch(i){let o=this.getPathForTarget(n,r);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,i instanceof Error?i.message:i)}}this.originalDescriptors=[]}}});function p7(e){return typeof e!="function"?e:xt.bindCurrentContext(e)}var u7,f7,yv,wv,gr,zr,Ts=O(()=>{"use strict";nn();u7=globalThis.setTimeout.bind(globalThis),f7=globalThis.clearTimeout.bind(globalThis),yv=globalThis.setInterval.bind(globalThis),wv=globalThis.clearInterval.bind(globalThis);gr=((e,t,...n)=>u7(p7(e),t,...n)),zr=f7});var mf={};te(mf,{echoCommand:()=>d7,flagsForFuzzing:()=>m7});function h7(e){let t="",n=0;for(;n=e.length){t+="\\";break}let r=e[n+1];switch(r){case"\\":t+="\\",n+=2;break;case"n":t+=` +`,n+=2;break;case"t":t+=" ",n+=2;break;case"r":t+="\r",n+=2;break;case"a":t+="\x07",n+=2;break;case"b":t+="\b",n+=2;break;case"f":t+="\f",n+=2;break;case"v":t+="\v",n+=2;break;case"e":case"E":t+="\x1B",n+=2;break;case"c":return{output:t,stop:!0};case"0":{let s="",i=n+2;for(;i{"use strict";d7={name:"echo",async execute(e,t){let n=!1,r=t.xpgEcho??!1,s=0;for(;s255)return t;i>127&&(n=!0)}if(!n)return t;let r=new Uint8Array(t.length);for(let s=0;s{"use strict";g7=new TextDecoder("utf-8",{fatal:!0}),y7=new TextEncoder;yf=""});function U(e){let t=`${e.name} - ${e.summary} `;if(t+=`Usage: ${e.usage} `,e.description){if(t+=` @@ -24,204 +24,206 @@ Notes: `;for(let n of e.notes)t+=` ${n} `}return{stdout:t,stderr:"",exitCode:0}}function B(e){return e.includes("--help")}function K(e,t){return{stdout:"",stderr:t.startsWith("--")?`${e}: unrecognized option '${t}' `:`${e}: invalid option -- '${t.replace(/^-/,"")}' -`,exitCode:1}}var oe=v(()=>{"use strict"});function Ae(e,t,n){let r=new Map,s=new Map;for(let[l,c]of Object.entries(n)){let u={name:l,type:c.type};c.short&&r.set(c.short,u),c.long&&s.set(c.long,u)}let i=Object.create(null);for(let[l,c]of Object.entries(n))c.default!==void 0?i[l]=c.default:c.type==="boolean"&&(i[l]=!1);let o=[],a=!1;for(let l=0;l=t.length)return{ok:!1,error:{stdout:"",stderr:`${e}: option '--${f}' requires an argument +`,exitCode:1}}var oe=O(()=>{"use strict"});function Ae(e,t,n){let r=new Map,s=new Map;for(let[l,c]of Object.entries(n)){let u={name:l,type:c.type};c.short&&r.set(c.short,u),c.long&&s.set(c.long,u)}let i=Object.create(null);for(let[l,c]of Object.entries(n))c.default!==void 0?i[l]=c.default:c.type==="boolean"&&(i[l]=!1);let o=[],a=!1;for(let l=0;l=t.length)return{ok:!1,error:{stdout:"",stderr:`${e}: option '--${f}' requires an argument `,exitCode:1}};p=t[++l]}i[d]=m==="number"?parseInt(p,10):p}}else{let u=c.slice(1);for(let f=0;f{"use strict";oe()});var rs=v(()=>{"use strict"});async function Ir(e,t,n){let{cmdName:r,allowStdinMarker:s=!0,stopOnError:i=!1,batchSize:o=100}=n;if(t.length===0)return{files:[{filename:"",content:e.stdin}],stderr:"",exitCode:0};let a=[],l="",c=0;for(let u=0;u{if(s&&h==="-")return{filename:"-",content:e.stdin,error:null};try{let d=e.fs.resolvePath(e.cwd,h),m=await fn(e.fs,d);return{filename:h,content:m,error:null}}catch{return{filename:h,content:Gf,error:`${r}: ${h}: No such file or directory -`}}}));for(let h of p)if(h.error){if(l+=h.error,c=1,i)return{files:a,stderr:l,exitCode:c}}else a.push({filename:h.filename,content:h.content})}return{files:a,stderr:l,exitCode:c}}async function ss(e,t,n){let r=await Ir(e,t,{...n,stopOnError:!0});return r.exitCode!==0?{ok:!1,error:{stdout:"",stderr:r.stderr,exitCode:r.exitCode}}:{ok:!0,content:r.files.map(i=>i.content).join("")}}var $r=v(()=>{"use strict";ye();rs()});var qf={};ee(qf,{catCommand:()=>d4,flagsForFuzzing:()=>g4});function m4(e,t){let n=e.split(` +`,exitCode:1}};i[d]=m==="number"?parseInt(g,10):g;break}}}}return{ok:!0,result:{flags:i,positional:o}}}var ct=O(()=>{"use strict";oe()});var Hr=O(()=>{"use strict"});async function yr(e,t,n){let{cmdName:r,allowStdinMarker:s=!0,stopOnError:i=!1,batchSize:o=100}=n;if(t.length===0)return{files:[{filename:"",content:e.stdin}],stderr:"",exitCode:0};let a=[],l="",c=0;for(let u=0;u{if(s&&h==="-")return{filename:"-",content:e.stdin,error:null};try{let d=e.fs.resolvePath(e.cwd,h),m=await sn(e.fs,d);return{filename:h,content:m,error:null}}catch{return{filename:h,content:yf,error:`${r}: ${h}: No such file or directory +`}}}));for(let h of p)if(h.error){if(l+=h.error,c=1,i)return{files:a,stderr:l,exitCode:c}}else a.push({filename:h.filename,content:h.content})}return{files:a,stderr:l,exitCode:c}}async function jr(e,t,n){let r=await yr(e,t,{...n,stopOnError:!0});return r.exitCode!==0?{ok:!1,error:{stdout:"",stderr:r.stderr,exitCode:r.exitCode}}:{ok:!0,content:r.files.map(i=>i.content).join("")}}var wr=O(()=>{"use strict";ye();Hr()});var bf={};te(bf,{catCommand:()=>E7,flagsForFuzzing:()=>S7});function A7(e,t){let n=e.split(` `),r=e.endsWith(` `),s=r?n.slice(0,-1):n;return{content:s.map((o,a)=>`${String(t+a).padStart(6," ")} ${o}`).join(` `)+(r?` -`:""),nextLineNumber:t+s.length}}var p4,h4,d4,g4,Zf=v(()=>{"use strict";ye();ct();$r();oe();p4={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"]},h4={number:{short:"n",long:"number",type:"boolean"}},d4={name:"cat",async execute(e,t){if(B(e))return U(p4);let n=Ae("cat",e,h4);if(!n.ok)return n.error;let r=n.result.flags.number,s=n.result.positional,i=await Ir(t,s,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),o="",a=1;for(let{content:l}of i.files){let c=l;if(r){let u=m4(c,a);o+=u.content,a=u.nextLineNumber}else o+=c}return{stdout:o,stderr:i.stderr,exitCode:i.exitCode,stdoutEncoding:"binary"}}};g4={name:"cat",flags:[{flag:"-n",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-b",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-e",type:"boolean"},{flag:"-t",type:"boolean"}],stdinType:"text",needsFiles:!0}});function Bi(e){return e instanceof It||e instanceof $t||e instanceof St}var Nt,It,$t,St,Ht,Rt,we,Le,Pt,_n,is,X,os,Fn,jt,xe=v(()=>{"use strict";Nt=class extends Error{stdout;stderr;constructor(t,n="",r=""){super(t),this.stdout=n,this.stderr=r}prependOutput(t,n){this.stdout=t+this.stdout,this.stderr=n+this.stderr}},It=class extends Nt{levels;name="BreakError";constructor(t=1,n="",r=""){super("break",n,r),this.levels=t}},$t=class extends Nt{levels;name="ContinueError";constructor(t=1,n="",r=""){super("continue",n,r),this.levels=t}},St=class extends Nt{exitCode;name="ReturnError";constructor(t=0,n="",r=""){super("return",n,r),this.exitCode=t}},Ht=class extends Nt{exitCode;name="ErrexitError";constructor(t,n="",r=""){super(`errexit: command exited with status ${t}`,n,r),this.exitCode=t}},Rt=class extends Nt{varName;name="NounsetError";constructor(t,n=""){super(`${t}: unbound variable`,n,`bash: ${t}: unbound variable -`),this.varName=t}},we=class extends Nt{exitCode;name="ExitError";constructor(t,n="",r=""){super("exit",n,r),this.exitCode=t}},Le=class extends Nt{name="ArithmeticError";fatal;constructor(t,n="",r="",s=!1){super(t,n,r),this.stderr=r||`bash: ${t} -`,this.fatal=s}},Pt=class extends Nt{name="BadSubstitutionError";constructor(t,n="",r=""){super(t,n,r),this.stderr=r||`bash: ${t}: bad substitution -`}},_n=class extends Nt{name="GlobError";constructor(t,n="",r=""){super(`no match: ${t}`,n,r),this.stderr=r||`bash: no match: ${t} -`}},is=class extends Nt{name="BraceExpansionError";constructor(t,n="",r=""){super(t,n,r),this.stderr=r||`bash: ${t} -`}},X=class extends Nt{limitType;name="ExecutionLimitError";static EXIT_CODE=126;constructor(t,n,r="",s=""){super(t,r,s),this.limitType=n,this.stderr=s||`bash: ${t} -`}},os=class extends Nt{name="ExecutionAbortedError";constructor(t="",n=""){super("execution aborted",t,n)}},Fn=class extends Nt{name="SubshellExitError";constructor(t="",n=""){super("subshell exit",t,n)}};jt=class extends Nt{exitCode;name="PosixFatalError";constructor(t,n="",r=""){super("posix fatal error",n,r),this.exitCode=t}}});function Xe(e){return e instanceof Error?e.message:String(e)}var nn=v(()=>{"use strict"});function Wi(e,t,n){let r=e;n>=0&&r.length>n&&(r=r.slice(0,n));let s=Math.abs(t);return s>r.length&&(t<0?r=r.padEnd(s," "):r=r.padStart(s," ")),r}function Kf(e,t){let n=t,r=0,s=-1,i=!1;for(n0&&(r=-r),[r,s,n-t]}function zi(e){let t="",n=0;for(;n0){try{let o=new TextDecoder("utf-8",{fatal:!0});t+=o.decode(new Uint8Array(s))}catch{for(let o of s)t+=String.fromCharCode(o)}n=i}else t+=e[n],n++;break}case"u":{let s="",i=n+2;for(;i{"use strict"});function Tr(e,t,n){let r=new Date(t*1e3),s="",i=0;for(;is.find(u=>u.type===c)?.value??"",o=new Map([["Sun",0],["Mon",1],["Tue",2],["Wed",3],["Thu",4],["Fri",5],["Sat",6]]),a=i("weekday"),l=(c,u)=>{let f=Number.parseInt(c,10);return Number.isNaN(f)?u:f};return{year:l(i("year"),e.getFullYear()),month:l(i("month"),e.getMonth()+1),day:l(i("day"),e.getDate()),hour:l(i("hour"),e.getHours())%24,minute:l(i("minute"),e.getMinutes()),second:l(i("second"),e.getSeconds()),weekday:o.get(a)??e.getDay()}}catch{return{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),weekday:e.getDay()}}}function w4(e,t,n){let r=y4(e,n),s=(l,c=2)=>String(l).padStart(c,"0"),i=Yf(r.year,r.month,r.day),o=Qf(r.year,r.month,r.day,r.weekday,0),a=Qf(r.year,r.month,r.day,r.weekday,1);switch(t){case"a":return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][r.weekday];case"A":return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][r.weekday];case"b":case"h":return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][r.month-1];case"B":return["January","February","March","April","May","June","July","August","September","October","November","December"][r.month-1];case"c":return`${["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][r.weekday]} ${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][r.month-1]} ${String(r.day).padStart(2," ")} ${s(r.hour)}:${s(r.minute)}:${s(r.second)} ${r.year}`;case"C":return s(Math.floor(r.year/100));case"d":return s(r.day);case"D":return`${s(r.month)}/${s(r.day)}/${s(r.year%100)}`;case"e":return String(r.day).padStart(2," ");case"F":return`${r.year}-${s(r.month)}-${s(r.day)}`;case"g":return s(Xf(r.year,r.month,r.day)%100);case"G":return String(Xf(r.year,r.month,r.day));case"H":return s(r.hour);case"I":return s(r.hour%12||12);case"j":return String(i).padStart(3,"0");case"k":return String(r.hour).padStart(2," ");case"l":return String(r.hour%12||12).padStart(2," ");case"m":return s(r.month);case"M":return s(r.minute);case"n":return` -`;case"N":return"000000000";case"p":return r.hour<12?"AM":"PM";case"P":return r.hour<12?"am":"pm";case"r":return`${s(r.hour%12||12)}:${s(r.minute)}:${s(r.second)} ${r.hour<12?"AM":"PM"}`;case"R":return`${s(r.hour)}:${s(r.minute)}`;case"s":return String(Math.floor(e.getTime()/1e3));case"S":return s(r.second);case"t":return" ";case"T":return`${s(r.hour)}:${s(r.minute)}:${s(r.second)}`;case"u":return String(r.weekday===0?7:r.weekday);case"U":return s(o);case"V":return s(E4(r.year,r.month,r.day));case"w":return String(r.weekday);case"W":return s(a);case"x":return`${s(r.month)}/${s(r.day)}/${s(r.year%100)}`;case"X":return`${s(r.hour)}:${s(r.minute)}:${s(r.second)}`;case"y":return s(r.year%100);case"Y":return String(r.year);case"z":return b4(e,n);case"Z":return x4(e,n);case"%":return"%";default:return null}}function b4(e,t){if(!t){let o=-e.getTimezoneOffset(),a=o>=0?"+":"-",l=Math.floor(Math.abs(o)/60),c=Math.abs(o)%60;return`${a}${String(l).padStart(2,"0")}${String(c).padStart(2,"0")}`}try{let l=new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"longOffset"}).formatToParts(e).find(c=>c.type==="timeZoneName");if(l){let c=l.value.match(/GMT([+-])(\d{2}):(\d{2})/);if(c)return`${c[1]}${c[2]}${c[3]}`;if(l.value==="GMT"||l.value==="UTC")return"+0000"}}catch{}let n=-e.getTimezoneOffset(),r=n>=0?"+":"-",s=Math.floor(Math.abs(n)/60),i=Math.abs(n)%60;return`${r}${String(s).padStart(2,"0")}${String(i).padStart(2,"0")}`}function x4(e,t){try{return new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(e).find(i=>i.type==="timeZoneName")?.value??"UTC"}catch{return"UTC"}}function Yf(e,t,n){let r=[31,28,31,30,31,30,31,31,30,31,30,31];(e%4===0&&e%100!==0||e%400===0)&&(r[1]=29);let i=n;for(let o=0;o{"use strict"});var e1={};ee(e1,{flagsForFuzzing:()=>D4,printfCommand:()=>C4});import{sprintf as as}from"sprintf-js";function A4(e){let t="",n=0;for(;n=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+31114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function v4(e,t,n,r){let s="",i=0,o=0,a=!1,l="";for(;i=0&&$.length>I&&($=$.slice(0,I)),A!==0){let C=Math.abs(A);$.length>>0:i;return{value:Jf(e.replace("u","d"),o),parseError:r,parseErrMsg:s}}case"x":case"X":{let i=Hi(n);return r=xn,r&&(s=`printf: ${n}: invalid number -`),{value:I4(e,i),parseError:r,parseErrMsg:s}}case"e":case"E":case"f":case"F":case"g":case"G":{let i=parseFloat(n)||0;return{value:R4(e,t,i),parseError:!1,parseErrMsg:""}}case"c":{if(n==="")return{value:"",parseError:!1,parseErrMsg:""};let a=new TextEncoder().encode(n)[0];return{value:String.fromCharCode(a),parseError:!1,parseErrMsg:""}}case"s":return{value:T4(e,n),parseError:!1,parseErrMsg:""};case"q":return{value:O4(e,n),parseError:!1,parseErrMsg:""};case"b":{let i=P4(n);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:as(e,n),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder -`}}}}function Hi(e){xn=!1;let t=e.trimStart(),n=t!==t.trimEnd();if(e=t.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let r=parseInt(e,16);return Number.isNaN(r)?(xn=!0,0):(n&&(xn=!0),r)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return n&&(xn=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){xn=!0;let r=e.match(/^(\d+)#/);return r?parseInt(r[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){xn=!0;let r=parseInt(e,10);return Number.isNaN(r)?0:r}return n&&(xn=!0),parseInt(e,10)||0}function Jf(e,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!n)return as(e.replace(/\.\d*/,""),t);let r=n[1]||"",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=t<0,a=Math.abs(t),l=String(a);i>=0&&(l=l.padStart(i,"0"));let c="";o?c="-":r.includes("+")?c="+":r.includes(" ")&&(c=" ");let u=c+l;return s>u.length&&(r.includes("-")?u=u.padEnd(s," "):r.includes("0")&&i<0?u=c+l.padStart(s-c.length,"0"):u=u.padStart(s," ")),u}function N4(e,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!n)return as(e,t);let r=n[1]||"",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=Math.abs(t).toString(8);i>=0&&(o=o.padStart(i,"0")),r.includes("#")&&!o.startsWith("0")&&(o=`0${o}`);let a=o;return s>a.length&&(r.includes("-")?a=a.padEnd(s," "):r.includes("0")&&i<0?a=a.padStart(s,"0"):a=a.padStart(s," ")),a}function I4(e,t){let n=e.includes("X"),r=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!r)return as(e,t);let s=r[1]||"",i=r[2]?parseInt(r[2],10):0,o=r[3]!==void 0?r[4]?parseInt(r[4],10):0:-1,a=Math.abs(t).toString(16);n&&(a=a.toUpperCase()),o>=0&&(a=a.padStart(o,"0"));let l="";s.includes("#")&&t!==0&&(l=n?"0X":"0x");let c=l+a;return i>c.length&&(s.includes("-")?c=c.padEnd(i," "):s.includes("0")&&o<0?c=l+a.padStart(i-l.length,"0"):c=c.padStart(i," ")),c}function $4(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f-\xff]/.test(e)){let r="$'";for(let s of e){let i=s.charCodeAt(0);s==="'"?r+="\\'":s==="\\"?r+="\\\\":s===` -`?r+="\\n":s===" "?r+="\\t":s==="\r"?r+="\\r":s==="\x07"?r+="\\a":s==="\b"?r+="\\b":s==="\f"?r+="\\f":s==="\v"?r+="\\v":s==="\x1B"?r+="\\E":i<32||i>=127&&i<=255?r+=`\\${i.toString(8).padStart(3,"0")}`:s==='"'?r+='\\"':r+=s}return r+="'",r}let n="";for(let r of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(r)?n+=`\\${r}`:n+=r;return n}function T4(e,t){let n=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!n)return as(e.replace(/0+(?=\d)/,""),t);let r=n[1]==="-",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=r?-s:s;return Wi(t,o,i)}function O4(e,t){let n=$4(t),r=e.match(/^%(-?)(\d*)q$/);if(!r)return n;let s=r[1]==="-",i=r[2]?parseInt(r[2],10):0,o=n;return i>o.length&&(s?o=o.padEnd(i," "):o=o.padStart(i," ")),o}function R4(e,t,n){let r=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!r)return as(e,n);let s=r[1]||"",i=r[2]?parseInt(r[2],10):0,o=r[3]!==void 0?r[4]?parseInt(r[4],10):0:6,a,l=t.toLowerCase();if(l==="e"?(a=n.toExponential(o),a=a.replace(/e([+-])(\d)$/,"e$10$2"),t==="E"&&(a=a.toUpperCase())):l==="f"?(a=n.toFixed(o),s.includes("#")&&o===0&&!a.includes(".")&&(a+=".")):l==="g"?(a=n.toPrecision(o||1),s.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),t==="G"&&(a=a.toUpperCase())):a=n.toString(),n>=0&&(s.includes("+")?a=`+${a}`:s.includes(" ")&&(a=` ${a}`)),i>a.length)if(s.includes("-"))a=a.padEnd(i," ");else if(s.includes("0")){let c=a.match(/^[+ -]/)?.[0]||"",u=c?a.slice(1):a;a=c+u.padStart(i-c.length,"0")}else a=a.padStart(i," ");return a}function P4(e){let t="",n=0;for(;n0?(t+=A4(s),n=i):(t+="\\x",n+=2);break}case"u":{let s="",i=n+2;for(;i{"use strict";xe();nn();oe();Xa();Ya();S4={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},C4={name:"printf",async execute(e,t){if(B(e))return U(S4);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments] +`:""),nextLineNumber:t+s.length}}var b7,x7,E7,S7,xf=O(()=>{"use strict";ye();ct();wr();oe();b7={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"]},x7={number:{short:"n",long:"number",type:"boolean"}},E7={name:"cat",async execute(e,t){if(B(e))return U(b7);let n=Ae("cat",e,x7);if(!n.ok)return n.error;let r=n.result.flags.number,s=n.result.positional,i=await yr(t,s,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),o="",a=1;for(let{content:l}of i.files){let c=l;if(r){let u=A7(c,a);o+=u.content,a=u.nextLineNumber}else o+=c}return{stdout:o,stderr:i.stderr,exitCode:i.exitCode,stdoutEncoding:"binary"}}};S7={name:"cat",flags:[{flag:"-n",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-b",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-e",type:"boolean"},{flag:"-t",type:"boolean"}],stdinType:"text",needsFiles:!0}});function Ei(e){return e instanceof Nt||e instanceof It||e instanceof At}var kt,Nt,It,At,Ut,Tt,we,Le,Ot,Nn,Gr,X,Vr,In,Bt,xe=O(()=>{"use strict";kt=class extends Error{stdout;stderr;constructor(t,n="",r=""){super(t),this.stdout=n,this.stderr=r}prependOutput(t,n){this.stdout=t+this.stdout,this.stderr=n+this.stderr}},Nt=class extends kt{levels;name="BreakError";constructor(t=1,n="",r=""){super("break",n,r),this.levels=t}},It=class extends kt{levels;name="ContinueError";constructor(t=1,n="",r=""){super("continue",n,r),this.levels=t}},At=class extends kt{exitCode;name="ReturnError";constructor(t=0,n="",r=""){super("return",n,r),this.exitCode=t}},Ut=class extends kt{exitCode;name="ErrexitError";constructor(t,n="",r=""){super(`errexit: command exited with status ${t}`,n,r),this.exitCode=t}},Tt=class extends kt{varName;name="NounsetError";constructor(t,n=""){super(`${t}: unbound variable`,n,`bash: ${t}: unbound variable +`),this.varName=t}},we=class extends kt{exitCode;name="ExitError";constructor(t,n="",r=""){super("exit",n,r),this.exitCode=t}},Le=class extends kt{name="ArithmeticError";fatal;constructor(t,n="",r="",s=!1){super(t,n,r),this.stderr=r||`bash: ${t} +`,this.fatal=s}},Ot=class extends kt{name="BadSubstitutionError";constructor(t,n="",r=""){super(t,n,r),this.stderr=r||`bash: ${t}: bad substitution +`}},Nn=class extends kt{name="GlobError";constructor(t,n="",r=""){super(`no match: ${t}`,n,r),this.stderr=r||`bash: no match: ${t} +`}},Gr=class extends kt{name="BraceExpansionError";constructor(t,n="",r=""){super(t,n,r),this.stderr=r||`bash: ${t} +`}},X=class extends kt{limitType;name="ExecutionLimitError";static EXIT_CODE=126;constructor(t,n,r="",s=""){super(t,r,s),this.limitType=n,this.stderr=s||`bash: ${t} +`}},Vr=class extends kt{name="ExecutionAbortedError";constructor(t="",n=""){super("execution aborted",t,n)}},In=class extends kt{name="SubshellExitError";constructor(t="",n=""){super("subshell exit",t,n)}};Bt=class extends kt{exitCode;name="PosixFatalError";constructor(t,n="",r=""){super("posix fatal error",n,r),this.exitCode=t}}});function Xe(e){return e instanceof Error?e.message:String(e)}var Qt=O(()=>{"use strict"});function Ai(e,t,n){let r=e;n>=0&&r.length>n&&(r=r.slice(0,n));let s=Math.abs(t);return s>r.length&&(t<0?r=r.padEnd(s," "):r=r.padStart(s," ")),r}function Ef(e,t){let n=t,r=0,s=-1,i=!1;for(n0&&(r=-r),[r,s,n-t]}function Si(e){let t="",n=0;for(;n0){try{let o=new TextDecoder("utf-8",{fatal:!0});t+=o.decode(new Uint8Array(s))}catch{for(let o of s)t+=String.fromCharCode(o)}n=i}else t+=e[n],n++;break}case"u":{let s="",i=n+2;for(;i{"use strict"});function br(e,t,n){let r=new Date(t*1e3),s="",i=0;for(;is.find(u=>u.type===c)?.value??"",o=new Map([["Sun",0],["Mon",1],["Tue",2],["Wed",3],["Thu",4],["Fri",5],["Sat",6]]),a=i("weekday"),l=(c,u)=>{let f=Number.parseInt(c,10);return Number.isNaN(f)?u:f};return{year:l(i("year"),e.getFullYear()),month:l(i("month"),e.getMonth()+1),day:l(i("day"),e.getDate()),hour:l(i("hour"),e.getHours())%24,minute:l(i("minute"),e.getMinutes()),second:l(i("second"),e.getSeconds()),weekday:o.get(a)??e.getDay()}}catch{return{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),weekday:e.getDay()}}}function v7(e,t,n){let r=C7(e,n),s=(l,c=2)=>String(l).padStart(c,"0"),i=Cf(r.year,r.month,r.day),o=Af(r.year,r.month,r.day,r.weekday,0),a=Af(r.year,r.month,r.day,r.weekday,1);switch(t){case"a":return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][r.weekday];case"A":return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][r.weekday];case"b":case"h":return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][r.month-1];case"B":return["January","February","March","April","May","June","July","August","September","October","November","December"][r.month-1];case"c":return`${["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][r.weekday]} ${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][r.month-1]} ${String(r.day).padStart(2," ")} ${s(r.hour)}:${s(r.minute)}:${s(r.second)} ${r.year}`;case"C":return s(Math.floor(r.year/100));case"d":return s(r.day);case"D":return`${s(r.month)}/${s(r.day)}/${s(r.year%100)}`;case"e":return String(r.day).padStart(2," ");case"F":return`${r.year}-${s(r.month)}-${s(r.day)}`;case"g":return s(Sf(r.year,r.month,r.day)%100);case"G":return String(Sf(r.year,r.month,r.day));case"H":return s(r.hour);case"I":return s(r.hour%12||12);case"j":return String(i).padStart(3,"0");case"k":return String(r.hour).padStart(2," ");case"l":return String(r.hour%12||12).padStart(2," ");case"m":return s(r.month);case"M":return s(r.minute);case"n":return` +`;case"N":return"000000000";case"p":return r.hour<12?"AM":"PM";case"P":return r.hour<12?"am":"pm";case"r":return`${s(r.hour%12||12)}:${s(r.minute)}:${s(r.second)} ${r.hour<12?"AM":"PM"}`;case"R":return`${s(r.hour)}:${s(r.minute)}`;case"s":return String(Math.floor(e.getTime()/1e3));case"S":return s(r.second);case"t":return" ";case"T":return`${s(r.hour)}:${s(r.minute)}:${s(r.second)}`;case"u":return String(r.weekday===0?7:r.weekday);case"U":return s(o);case"V":return s(I7(r.year,r.month,r.day));case"w":return String(r.weekday);case"W":return s(a);case"x":return`${s(r.month)}/${s(r.day)}/${s(r.year%100)}`;case"X":return`${s(r.hour)}:${s(r.minute)}:${s(r.second)}`;case"y":return s(r.year%100);case"Y":return String(r.year);case"z":return k7(e,n);case"Z":return N7(e,n);case"%":return"%";default:return null}}function k7(e,t){if(!t){let o=-e.getTimezoneOffset(),a=o>=0?"+":"-",l=Math.floor(Math.abs(o)/60),c=Math.abs(o)%60;return`${a}${String(l).padStart(2,"0")}${String(c).padStart(2,"0")}`}try{let l=new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"longOffset"}).formatToParts(e).find(c=>c.type==="timeZoneName");if(l){let c=l.value.match(/GMT([+-])(\d{2}):(\d{2})/);if(c)return`${c[1]}${c[2]}${c[3]}`;if(l.value==="GMT"||l.value==="UTC")return"+0000"}}catch{}let n=-e.getTimezoneOffset(),r=n>=0?"+":"-",s=Math.floor(Math.abs(n)/60),i=Math.abs(n)%60;return`${r}${String(s).padStart(2,"0")}${String(i).padStart(2,"0")}`}function N7(e,t){try{return new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(e).find(i=>i.type==="timeZoneName")?.value??"UTC"}catch{return"UTC"}}function Cf(e,t,n){let r=[31,28,31,30,31,30,31,31,30,31,30,31];(e%4===0&&e%100!==0||e%400===0)&&(r[1]=29);let i=n;for(let o=0;o{"use strict"});var kf={};te(kf,{flagsForFuzzing:()=>W7,printfCommand:()=>O7});import{sprintf as qr}from"sprintf-js";function $7(e){let t="",n=0;for(;n=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+31114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function R7(e,t,n,r){let s="",i=0,o=0,a=!1,l="";for(;i=0&&I.length>v&&(I=I.slice(0,v)),A!==0){let C=Math.abs(A);I.length>>0:i;return{value:vf(e.replace("u","d"),o),parseError:r,parseErrMsg:s}}case"x":case"X":{let i=Ci(n);return r=hn,r&&(s=`printf: ${n}: invalid number +`),{value:_7(e,i),parseError:r,parseErrMsg:s}}case"e":case"E":case"f":case"F":case"g":case"G":{let i=parseFloat(n)||0;return{value:U7(e,t,i),parseError:!1,parseErrMsg:""}}case"c":{if(n==="")return{value:"",parseError:!1,parseErrMsg:""};let a=new TextEncoder().encode(n)[0];return{value:String.fromCharCode(a),parseError:!1,parseErrMsg:""}}case"s":return{value:L7(e,n),parseError:!1,parseErrMsg:""};case"q":return{value:M7(e,n),parseError:!1,parseErrMsg:""};case"b":{let i=B7(n);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:qr(e,n),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder +`}}}}function Ci(e){hn=!1;let t=e.trimStart(),n=t!==t.trimEnd();if(e=t.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let r=parseInt(e,16);return Number.isNaN(r)?(hn=!0,0):(n&&(hn=!0),r)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return n&&(hn=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){hn=!0;let r=e.match(/^(\d+)#/);return r?parseInt(r[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){hn=!0;let r=parseInt(e,10);return Number.isNaN(r)?0:r}return n&&(hn=!0),parseInt(e,10)||0}function vf(e,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!n)return qr(e.replace(/\.\d*/,""),t);let r=n[1]||"",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=t<0,a=Math.abs(t),l=String(a);i>=0&&(l=l.padStart(i,"0"));let c="";o?c="-":r.includes("+")?c="+":r.includes(" ")&&(c=" ");let u=c+l;return s>u.length&&(r.includes("-")?u=u.padEnd(s," "):r.includes("0")&&i<0?u=c+l.padStart(s-c.length,"0"):u=u.padStart(s," ")),u}function D7(e,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!n)return qr(e,t);let r=n[1]||"",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=Math.abs(t).toString(8);i>=0&&(o=o.padStart(i,"0")),r.includes("#")&&!o.startsWith("0")&&(o=`0${o}`);let a=o;return s>a.length&&(r.includes("-")?a=a.padEnd(s," "):r.includes("0")&&i<0?a=a.padStart(s,"0"):a=a.padStart(s," ")),a}function _7(e,t){let n=e.includes("X"),r=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!r)return qr(e,t);let s=r[1]||"",i=r[2]?parseInt(r[2],10):0,o=r[3]!==void 0?r[4]?parseInt(r[4],10):0:-1,a=Math.abs(t).toString(16);n&&(a=a.toUpperCase()),o>=0&&(a=a.padStart(o,"0"));let l="";s.includes("#")&&t!==0&&(l=n?"0X":"0x");let c=l+a;return i>c.length&&(s.includes("-")?c=c.padEnd(i," "):s.includes("0")&&o<0?c=l+a.padStart(i-l.length,"0"):c=c.padStart(i," ")),c}function F7(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f-\xff]/.test(e)){let r="$'";for(let s of e){let i=s.charCodeAt(0);s==="'"?r+="\\'":s==="\\"?r+="\\\\":s===` +`?r+="\\n":s===" "?r+="\\t":s==="\r"?r+="\\r":s==="\x07"?r+="\\a":s==="\b"?r+="\\b":s==="\f"?r+="\\f":s==="\v"?r+="\\v":s==="\x1B"?r+="\\E":i<32||i>=127&&i<=255?r+=`\\${i.toString(8).padStart(3,"0")}`:s==='"'?r+='\\"':r+=s}return r+="'",r}let n="";for(let r of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(r)?n+=`\\${r}`:n+=r;return n}function L7(e,t){let n=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!n)return qr(e.replace(/0+(?=\d)/,""),t);let r=n[1]==="-",s=n[2]?parseInt(n[2],10):0,i=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=r?-s:s;return Ai(t,o,i)}function M7(e,t){let n=F7(t),r=e.match(/^%(-?)(\d*)q$/);if(!r)return n;let s=r[1]==="-",i=r[2]?parseInt(r[2],10):0,o=n;return i>o.length&&(s?o=o.padEnd(i," "):o=o.padStart(i," ")),o}function U7(e,t,n){let r=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!r)return qr(e,n);let s=r[1]||"",i=r[2]?parseInt(r[2],10):0,o=r[3]!==void 0?r[4]?parseInt(r[4],10):0:6,a,l=t.toLowerCase();if(l==="e"?(a=n.toExponential(o),a=a.replace(/e([+-])(\d)$/,"e$10$2"),t==="E"&&(a=a.toUpperCase())):l==="f"?(a=n.toFixed(o),s.includes("#")&&o===0&&!a.includes(".")&&(a+=".")):l==="g"?(a=n.toPrecision(o||1),s.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),t==="G"&&(a=a.toUpperCase())):a=n.toString(),n>=0&&(s.includes("+")?a=`+${a}`:s.includes(" ")&&(a=` ${a}`)),i>a.length)if(s.includes("-"))a=a.padEnd(i," ");else if(s.includes("0")){let c=a.match(/^[+ -]/)?.[0]||"",u=c?a.slice(1):a;a=c+u.padStart(i-c.length,"0")}else a=a.padStart(i," ");return a}function B7(e){let t="",n=0;for(;n0?(t+=$7(s),n=i):(t+="\\x",n+=2);break}case"u":{let s="",i=n+2;for(;i{"use strict";xe();Qt();oe();Pa();Da();T7={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},O7={name:"printf",async execute(e,t){if(B(e))return U(T7);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments] `,exitCode:2};let n=null,r=0;for(;r=e.length)return{stdout:"",stderr:`printf: -v: option requires an argument `,exitCode:1};if(n=e[r+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[a-zA-Z0-9_@*"'$]+\])?$/.test(n))return{stdout:"",stderr:`printf: \`${n}': not a valid identifier `,exitCode:2};r+=2}else{if(o.startsWith("-")&&o!=="-")break;break}}if(r>=e.length)return{stdout:"",stderr:`printf: usage: printf format [arguments] -`,exitCode:1};let s=e[r],i=e.slice(r+1);try{let o=zi(s),a="",l=0,c=!1,u="",f=t.env.get("TZ"),p=t.limits?.maxStringLength;do{let{result:h,argsConsumed:d,error:m,errMsg:g,stopped:y}=v4(o,i,l,f);if(a+=h,p!==void 0&&p>0&&a.length>p)throw new X(`printf: output size limit exceeded (${p} bytes)`,"string_length");if(l+=d,m&&(c=!0,g&&(u=g)),y)break}while(l0);if(l===0&&i.length>0,n){let h=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(['"]?)(.+?)\2\]$/);if(h){let d=h[1],m=h[3];m=m.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(g,y)=>t.env.get(y)??""),t.env.set(`${d}_${m}`,a)}else t.env.set(n,a);return{stdout:"",stderr:u,exitCode:c?1:0}}return{stdout:a,stderr:u,exitCode:c?1:0}}catch(o){if(o instanceof X)throw o;return{stdout:"",stderr:`printf: ${Xe(o)} -`,exitCode:1}}}};xn=!1;D4={name:"printf",flags:[{flag:"-v",type:"value",valueHint:"string"}],stdinType:"none",needsArgs:!0}});var s1={};ee(s1,{flagsForFuzzing:()=>U4,lsCommand:()=>L4});import{minimatch as n1}from"minimatch";function ji(e){if(e<1024)return String(e);if(e<1024*1024){let n=e/1024;return n<10?`${n.toFixed(1)}K`:`${Math.round(n)}K`}if(e<1024*1024*1024){let n=e/1048576;return n<10?`${n.toFixed(1)}M`:`${Math.round(n)}M`}let t=e/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function Gi(e){let n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()],r=String(e.getDate()).padStart(2," "),s=new Date,i=new Date(s.getTime()-4320*60*60*1e3);if(e>i){let a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r} ${a}:${l}`}let o=e.getFullYear();return`${n} ${r} ${o}`}function Or(e){return e.isDirectory?"/":e.isSymbolicLink?"@":(e.mode&73)!==0?"*":""}async function M4(e,t,n,r,s,i=!1,o=!1,a=!1,l=!1){let c=n||r,u=t.fs.getAllPaths(),f=t.fs.resolvePath(t.cwd,"."),p=[];for(let h of u){let d=h.startsWith(f)&&h.slice(f.length+1)||h;if(n1(d,e)||n1(h,e)){let m=d.split("/").pop()||d;if(!c&&m.startsWith("."))continue;p.push(d||h)}}if(p.length===0)return{stdout:"",stderr:`ls: ${e}: No such file or directory -`,exitCode:2};if(a){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.stat(m);h.push({path:d,size:g.size??0})}catch{h.push({path:d,size:0})}}h.sort((d,m)=>m.size-d.size),p.length=0,p.push(...h.map(d=>d.path))}else p.sort();if(i&&p.reverse(),s){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.stat(m),y=g.isDirectory?"drwxr-xr-x":"-rw-r--r--",w=l?Or(await t.fs.lstat(m)):g.isDirectory?"/":"",b=g.size??0,x=o?ji(b).padStart(5):String(b).padStart(5),A=g.mtime??new Date(0),I=Gi(A);h.push(`${y} 1 user user ${x} ${I} ${d}${w}`)}catch{h.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${d}`)}}return{stdout:`${h.join(` +`,exitCode:1};let s=e[r],i=e.slice(r+1);try{let o=Si(s),a="",l=0,c=!1,u="",f=t.env.get("TZ"),p=t.limits?.maxStringLength;do{let{result:h,argsConsumed:d,error:m,errMsg:g,stopped:y}=R7(o,i,l,f);if(a+=h,p!==void 0&&p>0&&a.length>p)throw new X(`printf: output size limit exceeded (${p} bytes)`,"string_length");if(l+=d,m&&(c=!0,g&&(u=g)),y)break}while(l0);if(l===0&&i.length>0,n){let h=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(['"]?)(.+?)\2\]$/);if(h){let d=h[1],m=h[3];m=m.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(g,y)=>t.env.get(y)??""),t.env.set(`${d}_${m}`,a)}else t.env.set(n,a);return{stdout:"",stderr:u,exitCode:c?1:0}}return{stdout:a,stderr:u,exitCode:c?1:0}}catch(o){if(o instanceof X)throw o;return{stdout:"",stderr:`printf: ${Xe(o)} +`,exitCode:1}}}};hn=!1;W7={name:"printf",flags:[{flag:"-v",type:"value",valueHint:"string"}],stdinType:"none",needsArgs:!0}});var Tf={};te(Tf,{flagsForFuzzing:()=>V7,lsCommand:()=>j7});import{minimatch as If}from"minimatch";function vi(e){if(e<1024)return String(e);if(e<1024*1024){let n=e/1024;return n<10?`${n.toFixed(1)}K`:`${Math.round(n)}K`}if(e<1024*1024*1024){let n=e/1048576;return n<10?`${n.toFixed(1)}M`:`${Math.round(n)}M`}let t=e/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function ki(e){let n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()],r=String(e.getDate()).padStart(2," "),s=new Date,i=new Date(s.getTime()-4320*60*60*1e3);if(e>i){let a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r} ${a}:${l}`}let o=e.getFullYear();return`${n} ${r} ${o}`}function xr(e){return e.isDirectory?"/":e.isSymbolicLink?"@":(e.mode&73)!==0?"*":""}async function G7(e,t,n,r,s,i=!1,o=!1,a=!1,l=!1){let c=n||r,u=t.fs.getAllPaths(),f=t.fs.resolvePath(t.cwd,"."),p=[];for(let h of u){let d=h.startsWith(f)&&h.slice(f.length+1)||h;if(If(d,e)||If(h,e)){let m=d.split("/").pop()||d;if(!c&&m.startsWith("."))continue;p.push(d||h)}}if(p.length===0)return{stdout:"",stderr:`ls: ${e}: No such file or directory +`,exitCode:2};if(a){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.stat(m);h.push({path:d,size:g.size??0})}catch{h.push({path:d,size:0})}}h.sort((d,m)=>m.size-d.size),p.length=0,p.push(...h.map(d=>d.path))}else p.sort();if(i&&p.reverse(),s){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.stat(m),y=g.isDirectory?"drwxr-xr-x":"-rw-r--r--",w=l?xr(await t.fs.lstat(m)):g.isDirectory?"/":"",b=g.size??0,x=o?vi(b).padStart(5):String(b).padStart(5),A=g.mtime??new Date(0),v=ki(A);h.push(`${y} 1 user user ${x} ${v} ${d}${w}`)}catch{h.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${d}`)}}return{stdout:`${h.join(` `)} -`,stderr:"",exitCode:0}}if(l){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.lstat(m);h.push(`${d}${Or(g)}`)}catch{h.push(d)}}return{stdout:`${h.join(` +`,stderr:"",exitCode:0}}if(l){let h=[];for(let d of p){let m=t.fs.resolvePath(t.cwd,d);try{let g=await t.fs.lstat(m);h.push(`${d}${xr(g)}`)}catch{h.push(d)}}return{stdout:`${h.join(` `)} `,stderr:"",exitCode:0}}return{stdout:`${p.join(` `)} -`,stderr:"",exitCode:0}}async function r1(e,t,n,r,s,i,o,a=!1,l=!1,c=!1,u=!1,f=!1){let p=n||r,h=t.fs.resolvePath(t.cwd,e);try{let d=await t.fs.stat(h);if(!d.isDirectory){let y=u?Or(await t.fs.lstat(h)):"";if(s){let w=d.size??0,b=l?ji(w).padStart(5):String(w).padStart(5),x=d.mtime??new Date(0),A=Gi(x);return{stdout:`-rw-r--r-- 1 user user ${b} ${A} ${e}${y} +`,stderr:"",exitCode:0}}async function $f(e,t,n,r,s,i,o,a=!1,l=!1,c=!1,u=!1,f=!1){let p=n||r,h=t.fs.resolvePath(t.cwd,e);try{let d=await t.fs.stat(h);if(!d.isDirectory){let y=u?xr(await t.fs.lstat(h)):"";if(s){let w=d.size??0,b=l?vi(w).padStart(5):String(w).padStart(5),x=d.mtime??new Date(0),A=ki(x);return{stdout:`-rw-r--r-- 1 user user ${b} ${A} ${e}${y} `,stderr:"",exitCode:0}}return{stdout:`${e}${y} `,stderr:"",exitCode:0}}let m=await t.fs.readdir(h);if(p||(m=m.filter(y=>!y.startsWith("."))),c){let y=[];for(let w of m){let b=h==="/"?`/${w}`:`${h}/${w}`;try{let x=await t.fs.stat(b);y.push({name:w,size:x.size??0})}catch{y.push({name:w,size:0})}}y.sort((w,b)=>b.size-w.size),m=y.map(w=>w.name)}else m.sort();n&&(m=[".","..",...m]),a&&m.reverse();let g="";if((i||o)&&(g+=`${e}: `),s){g+=`total ${m.length} `;let y=m.filter(A=>A==="."||A===".."),w=m.filter(A=>A!=="."&&A!=="..");for(let A of y)g+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${A} -`;let b=[];for(let A=0;A{let R=h==="/"?`/${M}`:`${h}/${M}`;try{let L=await t.fs.stat(R),$=L.isDirectory?"drwxr-xr-x":"-rw-r--r--",C=u?Or(await t.fs.lstat(R)):L.isDirectory?"/":"",T=L.size??0,N=l?ji(T).padStart(5):String(T).padStart(5),P=L.mtime??new Date(0),F=Gi(P);return{name:M,line:`${$} 1 user user ${N} ${F} ${M}${C} -`}}catch{return{name:M,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${M} -`}}}));b.push(...O)}let x=new Map(w.map((A,I)=>[A,I]));b.sort((A,I)=>(x.get(A.name)??0)-(x.get(I.name)??0));for(let{line:A}of b)g+=A}else if(u){let y=[],w=m.filter(x=>x!=="."&&x!==".."),b=m.filter(x=>x==="."||x==="..");for(let x of b)y.push(`${x}/`);for(let x=0;x{let M=h==="/"?`/${O}`:`${h}/${O}`;try{let R=await t.fs.lstat(M);return`${O}${Or(R)}`}catch{return O}}));y.push(...I)}g+=y.join(` +`;let b=[];for(let A=0;A{let R=h==="/"?`/${F}`:`${h}/${F}`;try{let M=await t.fs.stat(R),I=M.isDirectory?"drwxr-xr-x":"-rw-r--r--",C=u?xr(await t.fs.lstat(R)):M.isDirectory?"/":"",T=M.size??0,N=l?vi(T).padStart(5):String(T).padStart(5),P=M.mtime??new Date(0),L=ki(P);return{name:F,line:`${I} 1 user user ${N} ${L} ${F}${C} +`}}catch{return{name:F,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${F} +`}}}));b.push(...$)}let x=new Map(w.map((A,v)=>[A,v]));b.sort((A,v)=>(x.get(A.name)??0)-(x.get(v.name)??0));for(let{line:A}of b)g+=A}else if(u){let y=[],w=m.filter(x=>x!=="."&&x!==".."),b=m.filter(x=>x==="."||x==="..");for(let x of b)y.push(`${x}/`);for(let x=0;x{let F=h==="/"?`/${$}`:`${h}/${$}`;try{let R=await t.fs.lstat(F);return`${$}${xr(R)}`}catch{return $}}));y.push(...v)}g+=y.join(` `)+(y.length?` `:"")}else g+=m.join(` `)+(m.length?` -`:"");if(i){let y=m.filter(x=>x!=="."&&x!==".."),w=[];if(t.fs.readdirWithFileTypes)w=(await t.fs.readdirWithFileTypes(h)).filter(A=>A.isDirectory&&y.includes(A.name)).map(A=>({name:A.name,isDirectory:!0}));else for(let x=0;x{let M=h==="/"?`/${O}`:`${h}/${O}`;try{let R=await t.fs.stat(M);return{name:O,isDirectory:R.isDirectory}}catch{return{name:O,isDirectory:!1}}}));w.push(...I.filter(O=>O.isDirectory))}w.sort((x,A)=>x.name.localeCompare(A.name)),a&&w.reverse();let b=[];for(let x=0;x{let M=e==="."?`./${O.name}`:`${e}/${O.name}`,R=await r1(M,t,n,r,s,i,!1,a,l,c,u,!0);return{name:O.name,result:R}}));b.push(...I)}b.sort((x,A)=>x.name.localeCompare(A.name)),a&&b.reverse();for(let{result:x}of b)g+=` +`:"");if(i){let y=m.filter(x=>x!=="."&&x!==".."),w=[];if(t.fs.readdirWithFileTypes)w=(await t.fs.readdirWithFileTypes(h)).filter(A=>A.isDirectory&&y.includes(A.name)).map(A=>({name:A.name,isDirectory:!0}));else for(let x=0;x{let F=h==="/"?`/${$}`:`${h}/${$}`;try{let R=await t.fs.stat(F);return{name:$,isDirectory:R.isDirectory}}catch{return{name:$,isDirectory:!1}}}));w.push(...v.filter($=>$.isDirectory))}w.sort((x,A)=>x.name.localeCompare(A.name)),a&&w.reverse();let b=[];for(let x=0;x{let F=e==="."?`./${$.name}`:`${e}/${$.name}`,R=await $f(F,t,n,r,s,i,!1,a,l,c,u,!0);return{name:$.name,result:R}}));b.push(...v)}b.sort((x,A)=>x.name.localeCompare(A.name)),a&&b.reverse();for(let{result:x}of b)g+=` `,g+=x.stdout}return{stdout:g,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${e}: No such file or directory -`,exitCode:2}}}var _4,F4,L4,U4,i1=v(()=>{"use strict";ct();rs();oe();_4={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","-F, --classify append indicator (one of */=>@) to entries","-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"]},F4={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"},classifyFiles:{short:"F",long:"classify",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},L4={name:"ls",async execute(e,t){if(B(e))return U(_4);let n=Ae("ls",e,F4);if(!n.ok)return n.error;let r=n.result.flags.showAll,s=n.result.flags.showAlmostAll,i=n.result.flags.longFormat,o=n.result.flags.humanReadable,a=n.result.flags.recursive,l=n.result.flags.reverse,c=n.result.flags.sortBySize,u=n.result.flags.classifyFiles,f=n.result.flags.directoryOnly,p=n.result.flags.sortByTime;n.result.flags.onePerLine;let h=n.result.positional;h.length===0&&h.push(".");let d="",m="",g=0;for(let y=0;y0&&d&&!d.endsWith(` +`,exitCode:2}}}var z7,H7,j7,V7,Of=O(()=>{"use strict";ct();Hr();oe();z7={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","-F, --classify append indicator (one of */=>@) to entries","-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"]},H7={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"},classifyFiles:{short:"F",long:"classify",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},j7={name:"ls",async execute(e,t){if(B(e))return U(z7);let n=Ae("ls",e,H7);if(!n.ok)return n.error;let r=n.result.flags.showAll,s=n.result.flags.showAlmostAll,i=n.result.flags.longFormat,o=n.result.flags.humanReadable,a=n.result.flags.recursive,l=n.result.flags.reverse,c=n.result.flags.sortBySize,u=n.result.flags.classifyFiles,f=n.result.flags.directoryOnly,p=n.result.flags.sortByTime;n.result.flags.onePerLine;let h=n.result.positional;h.length===0&&h.push(".");let d="",m="",g=0;for(let y=0;y0&&d&&!d.endsWith(` `)&&(d+=` -`),f){let b=t.fs.resolvePath(t.cwd,w);try{let x=await t.fs.stat(b);if(i){let A=x.isDirectory?"drwxr-xr-x":"-rw-r--r--",I=u?Or(await t.fs.lstat(b)):x.isDirectory?"/":"",O=x.size??0,M=o?ji(O).padStart(5):String(O).padStart(5),R=x.mtime??new Date(0),L=Gi(R);d+=`${A} 1 user user ${M} ${L} ${w}${I} -`}else{let A=u?Or(await t.fs.lstat(b)):"";d+=`${w}${A} +`),f){let b=t.fs.resolvePath(t.cwd,w);try{let x=await t.fs.stat(b);if(i){let A=x.isDirectory?"drwxr-xr-x":"-rw-r--r--",v=u?xr(await t.fs.lstat(b)):x.isDirectory?"/":"",$=x.size??0,F=o?vi($).padStart(5):String($).padStart(5),R=x.mtime??new Date(0),M=ki(R);d+=`${A} 1 user user ${F} ${M} ${w}${v} +`}else{let A=u?xr(await t.fs.lstat(b)):"";d+=`${w}${A} `}}catch{m+=`ls: cannot access '${w}': No such file or directory -`,g=2}continue}if(w.includes("*")||w.includes("?")||w.includes("[")){let b=await M4(w,t,r,s,i,l,o,c,u);d+=b.stdout,m+=b.stderr,b.exitCode!==0&&(g=b.exitCode)}else{let b=await r1(w,t,r,s,i,a,h.length>1,l,o,c,u);d+=b.stdout,m+=b.stderr,b.exitCode!==0&&(g=b.exitCode)}}return{stdout:d,stderr:m,exitCode:g}}};U4={name:"ls",flags:[{flag:"-a",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-1",type:"boolean"}],needsFiles:!0}});function B4(e,t,n){if(!e)return e;let r=e.replace(/\n\s+at\s.*/g,"");return n&&(r=r.replace(/\bfile:\/\/\/?[^\s'",)}\]:]+/g,"")),r=r.replace(t?/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap|workspace|root|srv|mnt|app))\b[^\s'",)}\]:]*/g:/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,""),r=r.replace(/node:internal\/[^\s'",)}\]:]+/g,""),r=r.replace(/[A-Z]:\\[^\s'",)}\]:]+/g,""),n&&(r=r.replace(/\\\\[^\s\\]+\\[^\s'",)}\]:]+/g,"")),r}function He(e){return B4(e,!1,!1)}var En=v(()=>{"use strict"});var o1={};ee(o1,{flagsForFuzzing:()=>H4,mkdirCommand:()=>z4});var W4,z4,H4,a1=v(()=>{"use strict";En();nn();ct();W4={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},z4={name:"mkdir",async execute(e,t){let n=Ae("mkdir",e,W4);if(!n.ok)return n.error;let r=n.result.flags.recursive,s=n.result.flags.verbose,i=n.result.positional;if(i.length===0)return{stdout:"",stderr:`mkdir: missing operand +`,g=2}continue}if(w.includes("*")||w.includes("?")||w.includes("[")){let b=await G7(w,t,r,s,i,l,o,c,u);d+=b.stdout,m+=b.stderr,b.exitCode!==0&&(g=b.exitCode)}else{let b=await $f(w,t,r,s,i,a,h.length>1,l,o,c,u);d+=b.stdout,m+=b.stderr,b.exitCode!==0&&(g=b.exitCode)}}return{stdout:d,stderr:m,exitCode:g}}};V7={name:"ls",flags:[{flag:"-a",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-1",type:"boolean"}],needsFiles:!0}});function q7(e,t,n){if(!e)return e;let r=e.replace(/\n\s+at\s.*/g,"");return n&&(r=r.replace(/\bfile:\/\/\/?[^\s'",)}\]:]+/g,"")),r=r.replace(t?/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap|workspace|root|srv|mnt|app))\b[^\s'",)}\]:]*/g:/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,""),r=r.replace(/node:internal\/[^\s'",)}\]:]+/g,""),r=r.replace(/[A-Z]:\\[^\s'",)}\]:]+/g,""),n&&(r=r.replace(/\\\\[^\s\\]+\\[^\s'",)}\]:]+/g,"")),r}function He(e){return q7(e,!1,!1)}var dn=O(()=>{"use strict"});var Rf={};te(Rf,{flagsForFuzzing:()=>Q7,mkdirCommand:()=>K7});var Z7,K7,Q7,Pf=O(()=>{"use strict";dn();Qt();ct();Z7={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},K7={name:"mkdir",async execute(e,t){let n=Ae("mkdir",e,Z7);if(!n.ok)return n.error;let r=n.result.flags.recursive,s=n.result.flags.verbose,i=n.result.positional;if(i.length===0)return{stdout:"",stderr:`mkdir: missing operand `,exitCode:1};let o="",a="",l=0;for(let c of i)try{let u=t.fs.resolvePath(t.cwd,c);await t.fs.mkdir(u,{recursive:r}),s&&(o+=`mkdir: created directory '${c}' `)}catch(u){let f=Xe(u);f.includes("ENOENT")||f.includes("no such file")?a+=`mkdir: cannot create directory '${c}': No such file or directory `:f.includes("EEXIST")||f.includes("already exists")?a+=`mkdir: cannot create directory '${c}': File exists `:a+=`mkdir: cannot create directory '${c}': ${He(f)} -`,l=1}return{stdout:o,stderr:a,exitCode:l}}},H4={name:"mkdir",flags:[{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var u1={};ee(u1,{flagsForFuzzing:()=>Z4,rmdirCommand:()=>V4});async function q4(e,t,n,r){let s="",i="",a=e.fs.resolvePath(e.cwd,t),l=await l1(e,a,t,r);if(s+=l.stdout,i+=l.stderr,l.exitCode!==0)return{stdout:s,stderr:i,exitCode:l.exitCode};if(n){let c=a,u=t;for(;;){let f=c1(c),p=c1(u);if(f===c||f==="/"||f==="."||p==="."||p==="")break;let h=await l1(e,f,p,r);if(s+=h.stdout,h.exitCode!==0)break;c=f,u=p}}return{stdout:s,stderr:i,exitCode:0}}async function l1(e,t,n,r){try{if(!await e.fs.exists(t))return{stdout:"",stderr:`rmdir: failed to remove '${n}': No such file or directory +`,l=1}return{stdout:o,stderr:a,exitCode:l}}},Q7={name:"mkdir",flags:[{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var Ff={};te(Ff,{flagsForFuzzing:()=>t4,rmdirCommand:()=>J7});async function e4(e,t,n,r){let s="",i="",a=e.fs.resolvePath(e.cwd,t),l=await Df(e,a,t,r);if(s+=l.stdout,i+=l.stderr,l.exitCode!==0)return{stdout:s,stderr:i,exitCode:l.exitCode};if(n){let c=a,u=t;for(;;){let f=_f(c),p=_f(u);if(f===c||f==="/"||f==="."||p==="."||p==="")break;let h=await Df(e,f,p,r);if(s+=h.stdout,h.exitCode!==0)break;c=f,u=p}}return{stdout:s,stderr:i,exitCode:0}}async function Df(e,t,n,r){try{if(!await e.fs.exists(t))return{stdout:"",stderr:`rmdir: failed to remove '${n}': No such file or directory `,exitCode:1};if(!(await e.fs.stat(t)).isDirectory)return{stdout:"",stderr:`rmdir: failed to remove '${n}': Not a directory `,exitCode:1};if((await e.fs.readdir(t)).length>0)return{stdout:"",stderr:`rmdir: failed to remove '${n}': Directory not empty `,exitCode:1};await e.fs.rm(t,{recursive:!1,force:!1});let a="";return r&&(a=`rmdir: removing directory, '${n}' `),{stdout:a,stderr:"",exitCode:0}}catch(s){let i=Xe(s);return{stdout:"",stderr:`rmdir: failed to remove '${n}': ${i} -`,exitCode:1}}}function c1(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n===-1?".":n===0?"/":t.substring(0,n)}var j4,G4,V4,Z4,f1=v(()=>{"use strict";nn();ct();j4=`Usage: rmdir [-pv] DIRECTORY... +`,exitCode:1}}}function _f(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n===-1?".":n===0?"/":t.substring(0,n)}var X7,Y7,J7,t4,Lf=O(()=>{"use strict";Qt();ct();X7=`Usage: rmdir [-pv] DIRECTORY... Remove empty directories. Options: -p, --parents Remove DIRECTORY and its ancestors - -v, --verbose Output a diagnostic for every directory processed`,G4={parents:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"},help:{long:"help",type:"boolean"}},V4={name:"rmdir",async execute(e,t){let n=Ae("rmdir",e,G4);if(!n.ok)return n.error;if(n.result.flags.help)return{stdout:`${j4} + -v, --verbose Output a diagnostic for every directory processed`,Y7={parents:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"},help:{long:"help",type:"boolean"}},J7={name:"rmdir",async execute(e,t){let n=Ae("rmdir",e,Y7);if(!n.ok)return n.error;if(n.result.flags.help)return{stdout:`${X7} `,stderr:"",exitCode:0};let r=n.result.flags.parents,s=n.result.flags.verbose,i=n.result.positional;if(i.length===0)return{stdout:"",stderr:`rmdir: missing operand -`,exitCode:1};let o="",a="",l=0;for(let c of i){let u=await q4(t,c,r,s);o+=u.stdout,a+=u.stderr,u.exitCode!==0&&(l=u.exitCode)}return{stdout:o,stderr:a,exitCode:l}}};Z4={name:"rmdir",flags:[{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var p1={};ee(p1,{flagsForFuzzing:()=>X4,touchCommand:()=>Q4});function K4(e){let t=e.replace(/\//g,"-"),n=new Date(t);if(!Number.isNaN(n.getTime()))return n;let r=t.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(r){let[,i,o,a]=r;if(n=new Date(Number.parseInt(i,10),Number.parseInt(o,10)-1,Number.parseInt(a,10)),!Number.isNaN(n.getTime()))return n}let s=t.match(/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/);if(s){let[,i,o,a,l,c,u]=s;if(n=new Date(Number.parseInt(i,10),Number.parseInt(o,10)-1,Number.parseInt(a,10),Number.parseInt(l,10),Number.parseInt(c,10),Number.parseInt(u,10)),!Number.isNaN(n.getTime()))return n}return null}var Q4,X4,h1=v(()=>{"use strict";nn();oe();Q4={name:"touch",async execute(e,t){let n=[],r=null,s=!1;for(let l=0;l=e.length)return{stdout:"",stderr:`touch: option requires an argument -- 'd' +`,exitCode:1};let o="",a="",l=0;for(let c of i){let u=await e4(t,c,r,s);o+=u.stdout,a+=u.stderr,u.exitCode!==0&&(l=u.exitCode)}return{stdout:o,stderr:a,exitCode:l}}};t4={name:"rmdir",flags:[{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var Mf={};te(Mf,{flagsForFuzzing:()=>s4,touchCommand:()=>r4});function n4(e){let t=e.replace(/\//g,"-"),n=new Date(t);if(!Number.isNaN(n.getTime()))return n;let r=t.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(r){let[,i,o,a]=r;if(n=new Date(Number.parseInt(i,10),Number.parseInt(o,10)-1,Number.parseInt(a,10)),!Number.isNaN(n.getTime()))return n}let s=t.match(/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/);if(s){let[,i,o,a,l,c,u]=s;if(n=new Date(Number.parseInt(i,10),Number.parseInt(o,10)-1,Number.parseInt(a,10),Number.parseInt(l,10),Number.parseInt(c,10),Number.parseInt(u,10)),!Number.isNaN(n.getTime()))return n}return null}var r4,s4,Uf=O(()=>{"use strict";Qt();oe();r4={name:"touch",async execute(e,t){let n=[],r=null,s=!1;for(let l=0;l=e.length)return{stdout:"",stderr:`touch: option requires an argument -- 'd' `,exitCode:1};r=e[++l]}else if(c.startsWith("--date="))r=c.slice(7);else if(c==="-c"||c==="--no-create")s=!0;else if(c==="-a"||c==="-m"||c==="-r"||c==="-t")(c==="-r"||c==="-t")&&l++;else{if(c.startsWith("--"))return K("touch",c);if(c.startsWith("-")&&c.length>1){let u=!1;for(let f of c.slice(1))if(f==="c")s=!0;else if(!(f==="a"||f==="m"))if(f==="d"){if(l+1>=e.length)return{stdout:"",stderr:`touch: option requires an argument -- 'd' `,exitCode:1};r=e[++l],u=!0;break}else if(f==="r"||f==="t"){l++,u=!0;break}else return K("touch",`-${f}`);if(u)continue}else n.push(c)}}if(n.length===0)return{stdout:"",stderr:`touch: missing file operand -`,exitCode:1};let i=null;if(r!==null&&(i=K4(r),i===null))return{stdout:"",stderr:`touch: invalid date format '${r}' +`,exitCode:1};let i=null;if(r!==null&&(i=n4(r),i===null))return{stdout:"",stderr:`touch: invalid date format '${r}' `,exitCode:1};let o="",a=0;for(let l of n)try{let c=t.fs.resolvePath(t.cwd,l);if(!await t.fs.exists(c)){if(s)continue;await t.fs.writeFile(c,"")}let f=i??new Date;await t.fs.utimes(c,f,f)}catch(c){o+=`touch: cannot touch '${l}': ${Xe(c)} -`,a=1}return{stdout:"",stderr:o,exitCode:a}}},X4={name:"touch",flags:[{flag:"-c",type:"boolean"},{flag:"-a",type:"boolean"},{flag:"-m",type:"boolean"},{flag:"-d",type:"value",valueHint:"string"}],needsArgs:!0}});var d1={};ee(d1,{flagsForFuzzing:()=>e3,rmCommand:()=>J4});var Y4,J4,e3,m1=v(()=>{"use strict";En();nn();ct();Y4={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},J4={name:"rm",async execute(e,t){let n=Ae("rm",e,Y4);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.force,i=n.result.flags.verbose,o=n.result.positional;if(o.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand +`,a=1}return{stdout:"",stderr:o,exitCode:a}}},s4={name:"touch",flags:[{flag:"-c",type:"boolean"},{flag:"-a",type:"boolean"},{flag:"-m",type:"boolean"},{flag:"-d",type:"value",valueHint:"string"}],needsArgs:!0}});var Bf={};te(Bf,{flagsForFuzzing:()=>a4,rmCommand:()=>o4});var i4,o4,a4,Wf=O(()=>{"use strict";dn();Qt();ct();i4={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},o4={name:"rm",async execute(e,t){let n=Ae("rm",e,i4);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.force,i=n.result.flags.verbose,o=n.result.positional;if(o.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand `,exitCode:1};let a="",l="",c=0;for(let u of o)try{let f=t.fs.resolvePath(t.cwd,u);if((await t.fs.stat(f)).isDirectory&&!r){l+=`rm: cannot remove '${u}': Is a directory `,c=1;continue}await t.fs.rm(f,{recursive:r,force:s}),i&&(a+=`removed '${u}' `)}catch(f){if(!s){let p=Xe(f);p.includes("ENOENT")||p.includes("no such file")?l+=`rm: cannot remove '${u}': No such file or directory `:p.includes("ENOTEMPTY")||p.includes("not empty")?l+=`rm: cannot remove '${u}': Directory not empty `:l+=`rm: cannot remove '${u}': ${He(p)} -`,c=1}}return{stdout:a,stderr:l,exitCode:c}}},e3={name:"rm",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var g1={};ee(g1,{cpCommand:()=>r3,flagsForFuzzing:()=>s3});var t3,n3,r3,s3,y1=v(()=>{"use strict";nn();ct();oe();t3={name:"cp",summary:"copy files and directories",usage:"cp [OPTION]... SOURCE... DEST",options:["-r, -R, --recursive copy directories recursively","-n, --no-clobber do not overwrite an existing file","-p, --preserve preserve file attributes","-v, --verbose explain what is being done"," --help display this help and exit"]},n3={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},preserve:{short:"p",long:"preserve",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},r3={name:"cp",async execute(e,t){if(B(e))return U(t3);let n=Ae("cp",e,n3);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.noClobber,i=n.result.flags.preserve,o=n.result.flags.verbose,a=n.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand +`,c=1}}return{stdout:a,stderr:l,exitCode:c}}},a4={name:"rm",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var zf={};te(zf,{cpCommand:()=>u4,flagsForFuzzing:()=>f4});var l4,c4,u4,f4,Hf=O(()=>{"use strict";Qt();ct();oe();l4={name:"cp",summary:"copy files and directories",usage:"cp [OPTION]... SOURCE... DEST",options:["-r, -R, --recursive copy directories recursively","-n, --no-clobber do not overwrite an existing file","-p, --preserve preserve file attributes","-v, --verbose explain what is being done"," --help display this help and exit"]},c4={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},preserve:{short:"p",long:"preserve",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},u4={name:"cp",async execute(e,t){if(B(e))return U(l4);let n=Ae("cp",e,c4);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.noClobber,i=n.result.flags.preserve,o=n.result.flags.verbose,a=n.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand `,exitCode:1};let l=a.pop()??"",c=a,u=t.fs.resolvePath(t.cwd,l),f="",p="",h=0,d=!1;try{d=(await t.fs.stat(u)).isDirectory}catch{}if(c.length>1&&!d)return{stdout:"",stderr:`cp: target '${l}' is not a directory `,exitCode:1};for(let m of c)try{let g=t.fs.resolvePath(t.cwd,m),y=await t.fs.stat(g),w=u;if(d){let b=m.split("/").pop()||m;w=u==="/"?`/${b}`:`${u}/${b}`}if(y.isDirectory&&!r){p+=`cp: -r not specified; omitting directory '${m}' `,h=1;continue}if(s)try{await t.fs.stat(w);continue}catch{}await t.fs.cp(g,w,{recursive:r}),o&&(f+=`'${m}' -> '${w}' `)}catch(g){let y=Xe(g);y.includes("ENOENT")||y.includes("no such file")?p+=`cp: cannot stat '${m}': No such file or directory `:p+=`cp: cannot copy '${m}': ${y} -`,h=1}return{stdout:f,stderr:p,exitCode:h}}},s3={name:"cp",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2}});var w1={};ee(w1,{flagsForFuzzing:()=>l3,mvCommand:()=>a3});var i3,o3,a3,l3,b1=v(()=>{"use strict";nn();ct();oe();i3={name:"mv",summary:"move (rename) files",usage:"mv [OPTION]... SOURCE... DEST",options:["-f, --force do not prompt before overwriting","-n, --no-clobber do not overwrite an existing file","-v, --verbose explain what is being done"," --help display this help and exit"]},o3={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},a3={name:"mv",async execute(e,t){if(B(e))return U(i3);let n=Ae("mv",e,o3);if(!n.ok)return n.error;let r=n.result.flags.force,s=n.result.flags.noClobber,i=n.result.flags.verbose,o=n.result.positional;if(s&&(r=!1),o.length<2)return{stdout:"",stderr:`mv: missing destination file operand +`,h=1}return{stdout:f,stderr:p,exitCode:h}}},f4={name:"cp",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-p",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2}});var jf={};te(jf,{flagsForFuzzing:()=>m4,mvCommand:()=>d4});var p4,h4,d4,m4,Gf=O(()=>{"use strict";Qt();ct();oe();p4={name:"mv",summary:"move (rename) files",usage:"mv [OPTION]... SOURCE... DEST",options:["-f, --force do not prompt before overwriting","-n, --no-clobber do not overwrite an existing file","-v, --verbose explain what is being done"," --help display this help and exit"]},h4={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},d4={name:"mv",async execute(e,t){if(B(e))return U(p4);let n=Ae("mv",e,h4);if(!n.ok)return n.error;let r=n.result.flags.force,s=n.result.flags.noClobber,i=n.result.flags.verbose,o=n.result.positional;if(s&&(r=!1),o.length<2)return{stdout:"",stderr:`mv: missing destination file operand `,exitCode:1};let a=o.pop()??"",l=o,c=t.fs.resolvePath(t.cwd,a),u="",f="",p=0,h=!1;try{h=(await t.fs.stat(c)).isDirectory}catch{}if(l.length>1&&!h)return{stdout:"",stderr:`mv: target '${a}' is not a directory `,exitCode:1};for(let d of l)try{let m=t.fs.resolvePath(t.cwd,d),g=c;if(h){let y=d.split("/").pop()||d;g=c==="/"?`/${y}`:`${c}/${y}`}if(s)try{await t.fs.stat(g);continue}catch{}if(await t.fs.mv(m,g),i){let y=h?`${a}/${d.split("/").pop()||d}`:a;u+=`renamed '${d}' -> '${y}' `}}catch(m){let g=Xe(m);g.includes("ENOENT")||g.includes("no such file")?f+=`mv: cannot stat '${d}': No such file or directory `:f+=`mv: cannot move '${d}': ${g} -`,p=1}return{stdout:u,stderr:f,exitCode:p}}},l3={name:"mv",flags:[{flag:"-f",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2}});var x1={};ee(x1,{flagsForFuzzing:()=>f3,lnCommand:()=>u3});var c3,u3,f3,E1=v(()=>{"use strict";En();oe();c3={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},u3={name:"ln",async execute(e,t){if(B(e))return U(c3);let n=!1,r=!1,s=!1,i=0;for(;iw4,lnCommand:()=>y4});var g4,y4,w4,qf=O(()=>{"use strict";dn();oe();g4={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},y4={name:"ln",async execute(e,t){if(B(e))return U(g4);let n=!1,r=!1,s=!1,i=0;for(;i '${a}' -`),{stdout:u,stderr:"",exitCode:0}}},f3={name:"ln",flags:[{flag:"-s",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2}});var S1={};ee(S1,{chmodCommand:()=>h3,flagsForFuzzing:()=>d3});async function A1(e,t,n,r,s){let i="",o=await e.fs.readdir(t);for(let a of o){let l=t==="/"?`/${a}`:`${t}/${a}`,c;if(n!==void 0)c=n;else if(r!==void 0){let f=await e.fs.stat(l);c=Ja(r,f.mode)}else c=420;await e.fs.chmod(l,c),s&&(i+=`mode of '${l}' changed to ${c.toString(8).padStart(4,"0")} -`),(await e.fs.stat(l)).isDirectory&&(i+=await A1(e,l,n,r,s))}return i}function Ja(e,t=420){if(/^[0-7]+$/.test(e))return parseInt(e,8);let n=t&4095,r=e.split(",");for(let s of r){let i=s.match(/^([ugoa]*)([+\-=])([rwxXst]*)$/);if(!i)throw new Error(`Invalid mode: ${e}`);let o=i[1]||"a",a=i[2],l=i[3];(o==="a"||o==="")&&(o="ugo");let c=0;l.includes("r")&&(c|=4),l.includes("w")&&(c|=2),(l.includes("x")||l.includes("X"))&&(c|=1);let u=0;l.includes("s")&&(o.includes("u")&&(u|=2048),o.includes("g")&&(u|=1024)),l.includes("t")&&(u|=512);for(let f of o){let p=0;f==="u"?p=6:f==="g"?p=3:f==="o"&&(p=0);let h=c<{"use strict";oe();p3={name:"chmod",summary:"change file mode bits",usage:"chmod [OPTIONS] MODE FILE...",options:["-R change files recursively","-v output a diagnostic for every file processed"," --help display this help and exit"]},h3={name:"chmod",async execute(e,t){if(B(e))return U(p3);if(e.length<2)return{stdout:"",stderr:`chmod: missing operand +`),{stdout:u,stderr:"",exitCode:0}}},w4={name:"ln",flags:[{flag:"-s",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2}});var Kf={};te(Kf,{chmodCommand:()=>x4,flagsForFuzzing:()=>E4});async function Zf(e,t,n,r,s){let i="",o=await e.fs.readdir(t);for(let a of o){let l=t==="/"?`/${a}`:`${t}/${a}`,c;if(n!==void 0)c=n;else if(r!==void 0){let f=await e.fs.stat(l);c=_a(r,f.mode)}else c=420;await e.fs.chmod(l,c),s&&(i+=`mode of '${l}' changed to ${c.toString(8).padStart(4,"0")} +`),(await e.fs.stat(l)).isDirectory&&(i+=await Zf(e,l,n,r,s))}return i}function _a(e,t=420){if(/^[0-7]+$/.test(e))return parseInt(e,8);let n=t&4095,r=e.split(",");for(let s of r){let i=s.match(/^([ugoa]*)([+\-=])([rwxXst]*)$/);if(!i)throw new Error(`Invalid mode: ${e}`);let o=i[1]||"a",a=i[2],l=i[3];(o==="a"||o==="")&&(o="ugo");let c=0;l.includes("r")&&(c|=4),l.includes("w")&&(c|=2),(l.includes("x")||l.includes("X"))&&(c|=1);let u=0;l.includes("s")&&(o.includes("u")&&(u|=2048),o.includes("g")&&(u|=1024)),l.includes("t")&&(u|=512);for(let f of o){let p=0;f==="u"?p=6:f==="g"?p=3:f==="o"&&(p=0);let h=c<{"use strict";oe();b4={name:"chmod",summary:"change file mode bits",usage:"chmod [OPTIONS] MODE FILE...",options:["-R change files recursively","-v output a diagnostic for every file processed"," --help display this help and exit"]},x4={name:"chmod",async execute(e,t){if(B(e))return U(b4);if(e.length<2)return{stdout:"",stderr:`chmod: missing operand `,exitCode:1};let n=!1,r=!1,s=0;for(;sg3,pwdCommand:()=>m3});var m3,g3,k1=v(()=>{"use strict";m3={name:"pwd",async execute(e,t){let n=!1;for(let s of e)if(s==="-P")n=!0;else if(s==="-L")n=!1;else{if(s==="--")break;s.startsWith("-")}let r=t.cwd;if(n)try{r=await t.fs.realpath(t.cwd)}catch{}return{stdout:`${r} -`,stderr:"",exitCode:0}}},g3={name:"pwd",flags:[{flag:"-P",type:"boolean"},{flag:"-L",type:"boolean"}]}});var N1={};ee(N1,{flagsForFuzzing:()=>b3,readlinkCommand:()=>w3});var y3,w3,b3,I1=v(()=>{"use strict";oe();y3={name:"readlink",summary:"print resolved symbolic links or canonical file names",usage:"readlink [OPTIONS] FILE...",options:["-f canonicalize by following every symlink in every component of the given name recursively"," --help display this help and exit"]},w3={name:"readlink",async execute(e,t){if(B(e))return U(y3);let n=!1,r=0;for(;rS4,pwdCommand:()=>A4});var A4,S4,Yf=O(()=>{"use strict";A4={name:"pwd",async execute(e,t){let n=!1;for(let s of e)if(s==="-P")n=!0;else if(s==="-L")n=!1;else{if(s==="--")break;s.startsWith("-")}let r=t.cwd;if(n)try{r=await t.fs.realpath(t.cwd)}catch{}return{stdout:`${r} +`,stderr:"",exitCode:0}}},S4={name:"pwd",flags:[{flag:"-P",type:"boolean"},{flag:"-L",type:"boolean"}]}});var Jf={};te(Jf,{flagsForFuzzing:()=>k4,readlinkCommand:()=>v4});var C4,v4,k4,e1=O(()=>{"use strict";oe();C4={name:"readlink",summary:"print resolved symbolic links or canonical file names",usage:"readlink [OPTIONS] FILE...",options:["-f canonicalize by following every symlink in every component of the given name recursively"," --help display this help and exit"]},v4={name:"readlink",async execute(e,t){if(B(e))return U(C4);let n=!1,r=0;for(;r1,f=0;for(let p=0;p0&&(a+=` -`),a+=un(`==> ${h} <== +`,exitCode:1}}:{ok:!0,options:{lines:n,bytes:r,quiet:s,verbose:i,files:a,fromLine:o}}}async function Ii(e,t,n,r){let{quiet:s,verbose:i,files:o}=t;if(o.length===0)return{stdout:r(e.stdin),stderr:"",exitCode:0,stdoutEncoding:"binary"};let a="",l="",c=0,u=i||!s&&o.length>1,f=0;for(let p=0;p0&&(a+=` +`),a+=rn(`==> ${h} <== `)),a+=r(m),f++}catch{l+=`${n}: ${h}: No such file or directory -`,c=1}}return{stdout:a,stderr:l,exitCode:c,stdoutEncoding:"binary"}}function $1(e,t,n){if(n!==null)return e.slice(0,n);if(t===0)return"";let r=0,s=0,i=e.length;for(;r0?e.slice(0,r):""}function T1(e,t,n,r){if(n!==null)return e.slice(-n);let s=e.length;if(s===0)return"";if(r){let l=0,c=1;for(;l0?e.slice(0,r):""}function n1(e,t,n,r){if(n!==null)return e.slice(-n);let s=e.length;if(s===0)return"";if(r){let l=0,c=1;for(;l=0&&o{"use strict";ye();oe()});var O1={};ee(O1,{flagsForFuzzing:()=>A3,headCommand:()=>E3});var x3,E3,A3,R1=v(()=>{"use strict";oe();el();x3={name:"head",summary:"output the first part of files",usage:"head [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the first NUM bytes","-n, --lines=NUM print the first NUM lines (default 10)","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},E3={name:"head",async execute(e,t){if(B(e))return U(x3);let n=Vi(e,"head");if(!n.ok)return n.error;let{lines:r,bytes:s}=n.options;return qi(t,n.options,"head",i=>$1(i,r,s))}},A3={name:"head",flags:[{flag:"-n",type:"value",valueHint:"number"},{flag:"-c",type:"value",valueHint:"number"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"text",needsFiles:!0}});var P1={};ee(P1,{flagsForFuzzing:()=>v3,tailCommand:()=>C3});var S3,C3,v3,D1=v(()=>{"use strict";el();oe();S3={name:"tail",summary:"output the last part of files",usage:"tail [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the last NUM bytes","-n, --lines=NUM print the last NUM lines (default 10)","-n +NUM print starting from line NUM","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},C3={name:"tail",async execute(e,t){if(B(e))return U(S3);let n=Vi(e,"tail");if(!n.ok)return n.error;let{lines:r,bytes:s,fromLine:i}=n.options;return qi(t,n.options,"tail",o=>T1(o,r,s,i??!1))}},v3={name:"tail",flags:[{flag:"-n",type:"value",valueHint:"number"},{flag:"-c",type:"value",valueHint:"number"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"text",needsFiles:!0}});var F1={};ee(F1,{flagsForFuzzing:()=>$3,wcCommand:()=>I3});function _1(e,t){let n=e,r=n.length,s=t?Array.from(le(e)).length:r,i=0,o=0,a=!1;for(let l=0;l{"use strict";ye();ct();$r();oe();k3={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes print the byte counts","-m, --chars print the character counts","-l, --lines print the newline counts","-w, --words print the word counts"," --help display this help and exit"]},N3={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},I3={name:"wc",async execute(e,t){if(B(e))return U(k3);let n=Ae("wc",e,N3);if(!n.ok)return n.error;let{lines:r,words:s}=n.result.flags,i=n.result.flags.bytes,o=n.result.flags.chars,a=n.result.positional;!r&&!s&&!i&&!o&&(r=s=i=!0);let l=i||o,c=await Ir(t,a,{cmdName:"wc",stopOnError:!1});if(a.length===0){let b=_1(c.files[0].content,o);return{stdout:`${tl(b,r,s,l,"",0)} -`,stderr:"",exitCode:0}}let u=[],f=0,p=0,h=0;for(let{filename:b,content:x}of c.files){let A=_1(x,o);f+=A.lines,p+=A.words,h+=A.third,u.push({filename:b,stats:A})}let d=a.length>1?f:Math.max(...u.map(b=>b.stats.lines)),m=a.length>1?p:Math.max(...u.map(b=>b.stats.words)),g=a.length>1?h:Math.max(...u.map(b=>b.stats.third)),y=a.length>1?3:0;r&&(y=Math.max(y,String(d).length)),s&&(y=Math.max(y,String(m).length)),l&&(y=Math.max(y,String(g).length));let w="";for(let{filename:b,stats:x}of u)w+=`${tl(x,r,s,l,b,y)} -`;return a.length>1&&(w+=`${tl({lines:f,words:p,third:h},r,s,l,"total",y)} -`),{stdout:w,stderr:c.stderr,exitCode:c.exitCode}}};$3={name:"wc",flags:[{flag:"-l",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-m",type:"boolean"}],stdinType:"text",needsFiles:!0}});function Ks(e,t){let n=t?"d":"-",r=[e&256?"r":"-",e&128?"w":"-",e&64?"x":"-",e&32?"r":"-",e&16?"w":"-",e&8?"x":"-",e&4?"r":"-",e&2?"w":"-",e&1?"x":"-"];return n+r.join("")}var nl=v(()=>{"use strict"});var M1={};ee(M1,{flagsForFuzzing:()=>P3,statCommand:()=>R3});var T3,O3,R3,P3,U1=v(()=>{"use strict";ct();nl();oe();T3={name:"stat",summary:"display file or file system status",usage:"stat [OPTION]... FILE...",options:["-c FORMAT use the specified FORMAT instead of the default"," --help display this help and exit"]},O3={format:{short:"c",type:"string"}},R3={name:"stat",async execute(e,t){if(B(e))return U(T3);let n=Ae("stat",e,O3);if(!n.ok)return n.error;let r=n.result.flags.format??null,s=n.result.positional;if(s.length===0)return{stdout:"",stderr:`stat: missing operand -`,exitCode:1};let i="",o="",a=!1;for(let l of s){let c=t.fs.resolvePath(t.cwd,l);try{let u=await t.fs.stat(c);if(r){let f=r,p=u.mode.toString(8),h=Ks(u.mode,u.isDirectory);f=f.replace(/%n/g,l),f=f.replace(/%N/g,`'${l}'`),f=f.replace(/%s/g,String(u.size)),f=f.replace(/%F/g,u.isDirectory?"directory":"regular file"),f=f.replace(/%a/g,p),f=f.replace(/%A/g,h),f=f.replace(/%u/g,"1000"),f=f.replace(/%U/g,"user"),f=f.replace(/%g/g,"1000"),f=f.replace(/%G/g,"group"),i+=`${f} -`}else{let f=u.mode.toString(8).padStart(4,"0"),p=Ks(u.mode,u.isDirectory);i+=` File: ${l} +`}var Fa=O(()=>{"use strict";ye();oe()});var r1={};te(r1,{flagsForFuzzing:()=>$4,headCommand:()=>I4});var N4,I4,$4,s1=O(()=>{"use strict";oe();Fa();N4={name:"head",summary:"output the first part of files",usage:"head [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the first NUM bytes","-n, --lines=NUM print the first NUM lines (default 10)","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},I4={name:"head",async execute(e,t){if(B(e))return U(N4);let n=Ni(e,"head");if(!n.ok)return n.error;let{lines:r,bytes:s}=n.options;return Ii(t,n.options,"head",i=>t1(i,r,s))}},$4={name:"head",flags:[{flag:"-n",type:"value",valueHint:"number"},{flag:"-c",type:"value",valueHint:"number"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"text",needsFiles:!0}});var i1={};te(i1,{flagsForFuzzing:()=>R4,tailCommand:()=>O4});var T4,O4,R4,o1=O(()=>{"use strict";Fa();oe();T4={name:"tail",summary:"output the last part of files",usage:"tail [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the last NUM bytes","-n, --lines=NUM print the last NUM lines (default 10)","-n +NUM print starting from line NUM","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},O4={name:"tail",async execute(e,t){if(B(e))return U(T4);let n=Ni(e,"tail");if(!n.ok)return n.error;let{lines:r,bytes:s,fromLine:i}=n.options;return Ii(t,n.options,"tail",o=>n1(o,r,s,i??!1))}},R4={name:"tail",flags:[{flag:"-n",type:"value",valueHint:"number"},{flag:"-c",type:"value",valueHint:"number"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"text",needsFiles:!0}});var l1={};te(l1,{flagsForFuzzing:()=>F4,wcCommand:()=>_4});function a1(e,t){let n=e,r=n.length,s=t?Array.from(ae(e)).length:r,i=0,o=0,a=!1;for(let l=0;l{"use strict";ye();ct();wr();oe();P4={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes print the byte counts","-m, --chars print the character counts","-l, --lines print the newline counts","-w, --words print the word counts"," --help display this help and exit"]},D4={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},_4={name:"wc",async execute(e,t){if(B(e))return U(P4);let n=Ae("wc",e,D4);if(!n.ok)return n.error;let{lines:r,words:s}=n.result.flags,i=n.result.flags.bytes,o=n.result.flags.chars,a=n.result.positional;!r&&!s&&!i&&!o&&(r=s=i=!0);let l=i||o,c=await yr(t,a,{cmdName:"wc",stopOnError:!1});if(a.length===0){let b=a1(c.files[0].content,o);return{stdout:`${La(b,r,s,l,"",0)} +`,stderr:"",exitCode:0}}let u=[],f=0,p=0,h=0;for(let{filename:b,content:x}of c.files){let A=a1(x,o);f+=A.lines,p+=A.words,h+=A.third,u.push({filename:b,stats:A})}let d=a.length>1?f:Math.max(...u.map(b=>b.stats.lines)),m=a.length>1?p:Math.max(...u.map(b=>b.stats.words)),g=a.length>1?h:Math.max(...u.map(b=>b.stats.third)),y=a.length>1?3:0;r&&(y=Math.max(y,String(d).length)),s&&(y=Math.max(y,String(m).length)),l&&(y=Math.max(y,String(g).length));let w="";for(let{filename:b,stats:x}of u)w+=`${La(x,r,s,l,b,y)} +`;return a.length>1&&(w+=`${La({lines:f,words:p,third:h},r,s,l,"total",y)} +`),{stdout:w,stderr:c.stderr,exitCode:c.exitCode}}};F4={name:"wc",flags:[{flag:"-l",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-m",type:"boolean"}],stdinType:"text",needsFiles:!0}});function Os(e,t){let n=t?"d":"-",r=[e&256?"r":"-",e&128?"w":"-",e&64?"x":"-",e&32?"r":"-",e&16?"w":"-",e&8?"x":"-",e&4?"r":"-",e&2?"w":"-",e&1?"x":"-"];return n+r.join("")}var Ma=O(()=>{"use strict"});var u1={};te(u1,{flagsForFuzzing:()=>B4,statCommand:()=>U4});var L4,M4,U4,B4,f1=O(()=>{"use strict";ct();Ma();oe();L4={name:"stat",summary:"display file or file system status",usage:"stat [OPTION]... FILE...",options:["-c FORMAT use the specified FORMAT instead of the default"," --help display this help and exit"]},M4={format:{short:"c",type:"string"}},U4={name:"stat",async execute(e,t){if(B(e))return U(L4);let n=Ae("stat",e,M4);if(!n.ok)return n.error;let r=n.result.flags.format??null,s=n.result.positional;if(s.length===0)return{stdout:"",stderr:`stat: missing operand +`,exitCode:1};let i="",o="",a=!1;for(let l of s){let c=t.fs.resolvePath(t.cwd,l);try{let u=await t.fs.stat(c);if(r){let f=r,p=u.mode.toString(8),h=Os(u.mode,u.isDirectory);f=f.replace(/%n/g,l),f=f.replace(/%N/g,`'${l}'`),f=f.replace(/%s/g,String(u.size)),f=f.replace(/%F/g,u.isDirectory?"directory":"regular file"),f=f.replace(/%a/g,p),f=f.replace(/%A/g,h),f=f.replace(/%u/g,"1000"),f=f.replace(/%U/g,"user"),f=f.replace(/%g/g,"1000"),f=f.replace(/%G/g,"group"),i+=`${f} +`}else{let f=u.mode.toString(8).padStart(4,"0"),p=Os(u.mode,u.isDirectory);i+=` File: ${l} `,i+=` Size: ${u.size} Blocks: ${Math.ceil(u.size/512)} `,i+=`Access: (${f}/${p}) `,i+=`Modify: ${u.mtime.toISOString()} `}}catch{o+=`stat: cannot stat '${l}': No such file or directory -`,a=!0}}return{stdout:i,stderr:o,exitCode:a?1:0}}},P3={name:"stat",flags:[{flag:"-c",type:"value",valueHint:"format"},{flag:"-L",type:"boolean"}],needsArgs:!0}});var V,D,k,pn,ue,Oe,ip,ar,Zi,rl,cs,Mn,sl,il,Ye,us,je,ol,An,al,Ki,he,ll,Qi,Qs,D3,_3,cl,ul,_,fl,ls,pl,hl,Te,B1,W1,z1,H1,j1,G1,V1,q1,Z1,K1,Q1,X1,Y1,J1,ep,tp,np,rp,sp,Ln,Xs,dl,ml,gl,yl,wl,lr,op=v(()=>{V=class e{static FOLD_CASE=1;static LITERAL=2;static CLASS_NL=4;static DOT_NL=8;static ONE_LINE=16;static NON_GREEDY=32;static PERL_X=64;static UNICODE_GROUPS=128;static WAS_DOLLAR=256;static MATCH_NL=e.CLASS_NL|e.DOT_NL;static PERL=e.CLASS_NL|e.ONE_LINE|e.PERL_X|e.UNICODE_GROUPS;static POSIX=0;static UNANCHORED=0;static ANCHOR_START=1;static ANCHOR_BOTH=2},D=class{static CODES=new Map([["\x07",7],["\b",8],[" ",9],[` -`,10],["\v",11],["\f",12],["\r",13],[" ",32],['"',34],["$",36],["&",38],["(",40],[")",41],["*",42],["+",43],["-",45],[".",46],["0",48],["1",49],["2",50],["3",51],["4",52],["5",53],["6",54],["7",55],["8",56],["9",57],[":",58],["<",60],[">",62],["?",63],["A",65],["B",66],["C",67],["F",70],["P",80],["Q",81],["U",85],["Z",90],["[",91],["\\",92],["]",93],["^",94],["_",95],["a",97],["b",98],["f",102],["i",105],["m",109],["n",110],["r",114],["s",115],["t",116],["v",118],["x",120],["z",122],["{",123],["|",124],["}",125]]);static toUpperCase(t){let n=String.fromCodePoint(t).toUpperCase();if(n.length>1)return t;let r=String.fromCodePoint(n.codePointAt(0)).toLowerCase();return r.length>1||r.codePointAt(0)!==t?t:n.codePointAt(0)}static toLowerCase(t){let n=String.fromCodePoint(t).toLowerCase();if(n.length>1)return t;let r=String.fromCodePoint(n.codePointAt(0)).toUpperCase();return r.length>1||r.codePointAt(0)!==t?t:n.codePointAt(0)}},k=class{SIZE=3;constructor(t){this.data=t}getLo(t){return this.data[t*this.SIZE]}getHi(t){return this.data[t*this.SIZE+1]}getStride(t){return this.data[t*this.SIZE+2]}get(t){let n=t*this.SIZE;return[this.data[n],this.data[n+1],this.data[n+2]]}get length(){return this.data.length/this.SIZE}},pn=class e{static CASE_ORBIT=new Map([[75,107],[107,8490],[8490,75],[83,115],[115,383],[383,83],[181,924],[924,956],[956,181],[197,229],[229,8491],[8491,197],[452,453],[453,454],[454,452],[455,456],[456,457],[457,455],[458,459],[459,460],[460,458],[497,498],[498,499],[499,497],[837,921],[921,953],[953,8126],[8126,837],[914,946],[946,976],[976,914],[917,949],[949,1013],[1013,917],[920,952],[952,977],[977,1012],[1012,920],[922,954],[954,1008],[1008,922],[928,960],[960,982],[982,928],[929,961],[961,1009],[1009,929],[931,962],[962,963],[963,931],[934,966],[966,981],[981,934],[937,969],[969,8486],[8486,937],[1042,1074],[1074,7296],[7296,1042],[1044,1076],[1076,7297],[7297,1044],[1054,1086],[1086,7298],[7298,1054],[1057,1089],[1089,7299],[7299,1057],[1058,1090],[1090,7300],[7300,7301],[7301,1058],[1066,1098],[1098,7302],[7302,1066],[1122,1123],[1123,7303],[7303,1122],[7304,42570],[42570,42571],[42571,7304],[7776,7777],[7777,7835],[7835,7776],[223,7838],[7838,223],[8064,8072],[8072,8064],[8065,8073],[8073,8065],[8066,8074],[8074,8066],[8067,8075],[8075,8067],[8068,8076],[8076,8068],[8069,8077],[8077,8069],[8070,8078],[8078,8070],[8071,8079],[8079,8071],[8080,8088],[8088,8080],[8081,8089],[8089,8081],[8082,8090],[8090,8082],[8083,8091],[8091,8083],[8084,8092],[8092,8084],[8085,8093],[8093,8085],[8086,8094],[8094,8086],[8087,8095],[8095,8087],[8096,8104],[8104,8096],[8097,8105],[8105,8097],[8098,8106],[8106,8098],[8099,8107],[8107,8099],[8100,8108],[8108,8100],[8101,8109],[8109,8101],[8102,8110],[8110,8102],[8103,8111],[8111,8103],[8115,8124],[8124,8115],[8131,8140],[8140,8131],[912,8147],[8147,912],[944,8163],[8163,944],[8179,8188],[8188,8179],[64261,64262],[64262,64261],[66560,66600],[66600,66560],[66561,66601],[66601,66561],[66562,66602],[66602,66562],[66563,66603],[66603,66563],[66564,66604],[66604,66564],[66565,66605],[66605,66565],[66566,66606],[66606,66566],[66567,66607],[66607,66567],[66568,66608],[66608,66568],[66569,66609],[66609,66569],[66570,66610],[66610,66570],[66571,66611],[66611,66571],[66572,66612],[66612,66572],[66573,66613],[66613,66573],[66574,66614],[66614,66574],[66575,66615],[66615,66575],[66576,66616],[66616,66576],[66577,66617],[66617,66577],[66578,66618],[66618,66578],[66579,66619],[66619,66579],[66580,66620],[66620,66580],[66581,66621],[66621,66581],[66582,66622],[66622,66582],[66583,66623],[66623,66583],[66584,66624],[66624,66584],[66585,66625],[66625,66585],[66586,66626],[66626,66586],[66587,66627],[66627,66587],[66588,66628],[66628,66588],[66589,66629],[66629,66589],[66590,66630],[66630,66590],[66591,66631],[66631,66591],[66592,66632],[66632,66592],[66593,66633],[66633,66593],[66594,66634],[66634,66594],[66595,66635],[66635,66595],[66596,66636],[66636,66596],[66597,66637],[66637,66597],[66598,66638],[66638,66598],[66599,66639],[66639,66599],[66736,66776],[66776,66736],[66737,66777],[66777,66737],[66738,66778],[66778,66738],[66739,66779],[66779,66739],[66740,66780],[66780,66740],[66741,66781],[66781,66741],[66742,66782],[66782,66742],[66743,66783],[66783,66743],[66744,66784],[66784,66744],[66745,66785],[66785,66745],[66746,66786],[66786,66746],[66747,66787],[66787,66747],[66748,66788],[66788,66748],[66749,66789],[66789,66749],[66750,66790],[66790,66750],[66751,66791],[66791,66751],[66752,66792],[66792,66752],[66753,66793],[66793,66753],[66754,66794],[66794,66754],[66755,66795],[66795,66755],[66756,66796],[66796,66756],[66757,66797],[66797,66757],[66758,66798],[66798,66758],[66759,66799],[66799,66759],[66760,66800],[66800,66760],[66761,66801],[66801,66761],[66762,66802],[66802,66762],[66763,66803],[66803,66763],[66764,66804],[66804,66764],[66765,66805],[66805,66765],[66766,66806],[66806,66766],[66767,66807],[66807,66767],[66768,66808],[66808,66768],[66769,66809],[66809,66769],[66770,66810],[66810,66770],[66771,66811],[66811,66771],[66928,66967],[66967,66928],[66929,66968],[66968,66929],[66930,66969],[66969,66930],[66931,66970],[66970,66931],[66932,66971],[66971,66932],[66933,66972],[66972,66933],[66934,66973],[66973,66934],[66935,66974],[66974,66935],[66936,66975],[66975,66936],[66937,66976],[66976,66937],[66938,66977],[66977,66938],[66940,66979],[66979,66940],[66941,66980],[66980,66941],[66942,66981],[66981,66942],[66943,66982],[66982,66943],[66944,66983],[66983,66944],[66945,66984],[66984,66945],[66946,66985],[66985,66946],[66947,66986],[66986,66947],[66948,66987],[66987,66948],[66949,66988],[66988,66949],[66950,66989],[66989,66950],[66951,66990],[66990,66951],[66952,66991],[66991,66952],[66953,66992],[66992,66953],[66954,66993],[66993,66954],[66956,66995],[66995,66956],[66957,66996],[66996,66957],[66958,66997],[66997,66958],[66959,66998],[66998,66959],[66960,66999],[66999,66960],[66961,67e3],[67e3,66961],[66962,67001],[67001,66962],[66964,67003],[67003,66964],[66965,67004],[67004,66965],[68736,68800],[68800,68736],[68737,68801],[68801,68737],[68738,68802],[68802,68738],[68739,68803],[68803,68739],[68740,68804],[68804,68740],[68741,68805],[68805,68741],[68742,68806],[68806,68742],[68743,68807],[68807,68743],[68744,68808],[68808,68744],[68745,68809],[68809,68745],[68746,68810],[68810,68746],[68747,68811],[68811,68747],[68748,68812],[68812,68748],[68749,68813],[68813,68749],[68750,68814],[68814,68750],[68751,68815],[68815,68751],[68752,68816],[68816,68752],[68753,68817],[68817,68753],[68754,68818],[68818,68754],[68755,68819],[68819,68755],[68756,68820],[68820,68756],[68757,68821],[68821,68757],[68758,68822],[68822,68758],[68759,68823],[68823,68759],[68760,68824],[68824,68760],[68761,68825],[68825,68761],[68762,68826],[68826,68762],[68763,68827],[68827,68763],[68764,68828],[68828,68764],[68765,68829],[68829,68765],[68766,68830],[68830,68766],[68767,68831],[68831,68767],[68768,68832],[68832,68768],[68769,68833],[68833,68769],[68770,68834],[68834,68770],[68771,68835],[68835,68771],[68772,68836],[68836,68772],[68773,68837],[68837,68773],[68774,68838],[68838,68774],[68775,68839],[68839,68775],[68776,68840],[68840,68776],[68777,68841],[68841,68777],[68778,68842],[68842,68778],[68779,68843],[68843,68779],[68780,68844],[68844,68780],[68781,68845],[68845,68781],[68782,68846],[68846,68782],[68783,68847],[68847,68783],[68784,68848],[68848,68784],[68785,68849],[68849,68785],[68786,68850],[68850,68786],[68944,68976],[68976,68944],[68945,68977],[68977,68945],[68946,68978],[68978,68946],[68947,68979],[68979,68947],[68948,68980],[68980,68948],[68949,68981],[68981,68949],[68950,68982],[68982,68950],[68951,68983],[68983,68951],[68952,68984],[68984,68952],[68953,68985],[68985,68953],[68954,68986],[68986,68954],[68955,68987],[68987,68955],[68956,68988],[68988,68956],[68957,68989],[68989,68957],[68958,68990],[68990,68958],[68959,68991],[68991,68959],[68960,68992],[68992,68960],[68961,68993],[68993,68961],[68962,68994],[68994,68962],[68963,68995],[68995,68963],[68964,68996],[68996,68964],[68965,68997],[68997,68965],[71840,71872],[71872,71840],[71841,71873],[71873,71841],[71842,71874],[71874,71842],[71843,71875],[71875,71843],[71844,71876],[71876,71844],[71845,71877],[71877,71845],[71846,71878],[71878,71846],[71847,71879],[71879,71847],[71848,71880],[71880,71848],[71849,71881],[71881,71849],[71850,71882],[71882,71850],[71851,71883],[71883,71851],[71852,71884],[71884,71852],[71853,71885],[71885,71853],[71854,71886],[71886,71854],[71855,71887],[71887,71855],[71856,71888],[71888,71856],[71857,71889],[71889,71857],[71858,71890],[71890,71858],[71859,71891],[71891,71859],[71860,71892],[71892,71860],[71861,71893],[71893,71861],[71862,71894],[71894,71862],[71863,71895],[71895,71863],[71864,71896],[71896,71864],[71865,71897],[71897,71865],[71866,71898],[71898,71866],[71867,71899],[71899,71867],[71868,71900],[71900,71868],[71869,71901],[71901,71869],[71870,71902],[71902,71870],[71871,71903],[71903,71871],[93760,93792],[93792,93760],[93761,93793],[93793,93761],[93762,93794],[93794,93762],[93763,93795],[93795,93763],[93764,93796],[93796,93764],[93765,93797],[93797,93765],[93766,93798],[93798,93766],[93767,93799],[93799,93767],[93768,93800],[93800,93768],[93769,93801],[93801,93769],[93770,93802],[93802,93770],[93771,93803],[93803,93771],[93772,93804],[93804,93772],[93773,93805],[93805,93773],[93774,93806],[93806,93774],[93775,93807],[93807,93775],[93776,93808],[93808,93776],[93777,93809],[93809,93777],[93778,93810],[93810,93778],[93779,93811],[93811,93779],[93780,93812],[93812,93780],[93781,93813],[93813,93781],[93782,93814],[93814,93782],[93783,93815],[93815,93783],[93784,93816],[93816,93784],[93785,93817],[93817,93785],[93786,93818],[93818,93786],[93787,93819],[93819,93787],[93788,93820],[93820,93788],[93789,93821],[93821,93789],[93790,93822],[93822,93790],[93791,93823],[93823,93791],[125184,125218],[125218,125184],[125185,125219],[125219,125185],[125186,125220],[125220,125186],[125187,125221],[125221,125187],[125188,125222],[125222,125188],[125189,125223],[125223,125189],[125190,125224],[125224,125190],[125191,125225],[125225,125191],[125192,125226],[125226,125192],[125193,125227],[125227,125193],[125194,125228],[125228,125194],[125195,125229],[125229,125195],[125196,125230],[125230,125196],[125197,125231],[125231,125197],[125198,125232],[125232,125198],[125199,125233],[125233,125199],[125200,125234],[125234,125200],[125201,125235],[125235,125201],[125202,125236],[125236,125202],[125203,125237],[125237,125203],[125204,125238],[125238,125204],[125205,125239],[125239,125205],[125206,125240],[125240,125206],[125207,125241],[125241,125207],[125208,125242],[125242,125208],[125209,125243],[125243,125209],[125210,125244],[125244,125210],[125211,125245],[125245,125211],[125212,125246],[125246,125212],[125213,125247],[125247,125213],[125214,125248],[125248,125214],[125215,125249],[125249,125215],[125216,125250],[125250,125216],[125217,125251],[125251,125217]]);static C=new k(new Uint32Array([0,31,1,127,159,1,173,888,715,889,896,7,897,899,1,907,909,2,930,1328,398,1367,1368,1,1419,1420,1,1424,1480,56,1481,1487,1,1515,1518,1,1525,1541,1,1564,1757,193,1806,1807,1,1867,1868,1,1970,1983,1,2043,2044,1,2094,2095,1,2111,2140,29,2141,2143,2,2155,2159,1,2191,2198,1,2274,2436,162,2445,2446,1,2449,2450,1,2473,2481,8,2483,2485,1,2490,2491,1,2501,2502,1,2505,2506,1,2511,2518,1,2520,2523,1,2526,2532,6,2533,2559,26,2560,2564,4,2571,2574,1,2577,2578,1,2601,2609,8,2612,2618,3,2619,2621,2,2627,2630,1,2633,2634,1,2638,2640,1,2642,2648,1,2653,2655,2,2656,2661,1,2679,2688,1,2692,2702,10,2706,2729,23,2737,2740,3,2746,2747,1,2758,2766,4,2767,2769,2,2770,2783,1,2788,2789,1,2802,2808,1,2816,2820,4,2829,2830,1,2833,2834,1,2857,2865,8,2868,2874,6,2875,2885,10,2886,2889,3,2890,2894,4,2895,2900,1,2904,2907,1,2910,2916,6,2917,2936,19,2937,2945,1,2948,2955,7,2956,2957,1,2961,2966,5,2967,2968,1,2971,2973,2,2976,2978,1,2981,2983,1,2987,2989,1,3002,3005,1,3011,3013,1,3017,3022,5,3023,3025,2,3026,3030,1,3032,3045,1,3067,3071,1,3085,3089,4,3113,3130,17,3131,3141,10,3145,3150,5,3151,3156,1,3159,3163,4,3164,3166,2,3167,3172,5,3173,3184,11,3185,3190,1,3213,3217,4,3241,3252,11,3258,3259,1,3269,3273,4,3278,3284,1,3287,3292,1,3295,3300,5,3301,3312,11,3316,3327,1,3341,3345,4,3397,3401,4,3408,3411,1,3428,3429,1,3456,3460,4,3479,3481,1,3506,3516,10,3518,3519,1,3527,3529,1,3531,3534,1,3541,3543,2,3552,3557,1,3568,3569,1,3573,3584,1,3643,3646,1,3676,3712,1,3715,3717,2,3723,3748,25,3750,3774,24,3775,3781,6,3783,3791,8,3802,3803,1,3808,3839,1,3912,3949,37,3950,3952,1,3992,4029,37,4045,4059,14,4060,4095,1,4294,4296,2,4297,4300,1,4302,4303,1,4681,4686,5,4687,4695,8,4697,4702,5,4703,4745,42,4750,4751,1,4785,4790,5,4791,4799,8,4801,4806,5,4807,4823,16,4881,4886,5,4887,4955,68,4956,4989,33,4990,4991,1,5018,5023,1,5110,5111,1,5118,5119,1,5789,5791,1,5881,5887,1,5910,5918,1,5943,5951,1,5972,5983,1,5997,6001,4,6004,6015,1,6110,6111,1,6122,6127,1,6138,6143,1,6158,6170,12,6171,6175,1,6265,6271,1,6315,6319,1,6390,6399,1,6431,6444,13,6445,6447,1,6460,6463,1,6465,6467,1,6510,6511,1,6517,6527,1,6572,6575,1,6602,6607,1,6619,6621,1,6684,6685,1,6751,6781,30,6782,6794,12,6795,6799,1,6810,6815,1,6830,6831,1,6863,6911,1,6989,7156,167,7157,7163,1,7224,7226,1,7242,7244,1,7307,7311,1,7355,7356,1,7368,7375,1,7419,7423,1,7958,7959,1,7966,7967,1,8006,8007,1,8014,8015,1,8024,8030,2,8062,8063,1,8117,8133,16,8148,8149,1,8156,8176,20,8177,8181,4,8191,8203,12,8204,8207,1,8234,8238,1,8288,8303,1,8306,8307,1,8335,8349,14,8350,8351,1,8385,8399,1,8433,8447,1,8588,8591,1,9258,9279,1,9291,9311,1,11124,11125,1,11158,11508,350,11509,11512,1,11558,11560,2,11561,11564,1,11566,11567,1,11624,11630,1,11633,11646,1,11671,11679,1,11687,11743,8,11870,11903,1,11930,12020,90,12021,12031,1,12246,12271,1,12352,12439,87,12440,12544,104,12545,12548,1,12592,12687,95,12774,12782,1,12831,42125,29294,42126,42127,1,42183,42191,1,42540,42559,1,42744,42751,1,42958,42959,1,42962,42964,2,42973,42993,1,43053,43055,1,43066,43071,1,43128,43135,1,43206,43213,1,43226,43231,1,43348,43358,1,43389,43391,1,43470,43482,12,43483,43485,1,43519,43575,56,43576,43583,1,43598,43599,1,43610,43611,1,43715,43738,1,43767,43776,1,43783,43784,1,43791,43792,1,43799,43807,1,43815,43823,8,43884,43887,1,44014,44015,1,44026,44031,1,55204,55215,1,55239,55242,1,55292,63743,1,64110,64111,1,64218,64255,1,64263,64274,1,64280,64284,1,64311,64317,6,64319,64325,3,64451,64466,1,64912,64913,1,64968,64974,1,64976,65007,1,65050,65055,1,65107,65127,20,65132,65135,1,65141,65277,136,65278,65280,1,65471,65473,1,65480,65481,1,65488,65489,1,65496,65497,1,65501,65503,1,65511,65519,8,65520,65531,1,65534,65535,1,65548,65575,27,65595,65598,3,65614,65615,1,65630,65663,1,65787,65791,1,65795,65798,1,65844,65846,1,65935,65949,14,65950,65951,1,65953,65999,1,66046,66175,1,66205,66207,1,66257,66271,1,66300,66303,1,66340,66348,1,66379,66383,1,66427,66431,1,66462,66500,38,66501,66503,1,66518,66559,1,66718,66719,1,66730,66735,1,66772,66775,1,66812,66815,1,66856,66863,1,66916,66926,1,66939,66955,16,66963,66966,3,66978,66994,16,67002,67005,3,67006,67007,1,67060,67071,1,67383,67391,1,67414,67423,1,67432,67455,1,67462,67505,43,67515,67583,1,67590,67591,1,67593,67638,45,67641,67643,1,67645,67646,1,67670,67743,73,67744,67750,1,67760,67807,1,67827,67830,3,67831,67834,1,67868,67870,1,67898,67902,1,67904,67967,1,68024,68027,1,68048,68049,1,68100,68103,3,68104,68107,1,68116,68120,4,68150,68151,1,68155,68158,1,68169,68175,1,68185,68191,1,68256,68287,1,68327,68330,1,68343,68351,1,68406,68408,1,68438,68439,1,68467,68471,1,68498,68504,1,68509,68520,1,68528,68607,1,68681,68735,1,68787,68799,1,68851,68857,1,68904,68911,1,68922,68927,1,68966,68968,1,68998,69005,1,69008,69215,1,69247,69290,43,69294,69295,1,69298,69313,1,69317,69371,1,69416,69423,1,69466,69487,1,69514,69551,1,69580,69599,1,69623,69631,1,69710,69713,1,69750,69758,1,69821,69827,6,69828,69839,1,69865,69871,1,69882,69887,1,69941,69960,19,69961,69967,1,70007,70015,1,70112,70133,21,70134,70143,1,70162,70210,48,70211,70271,1,70279,70281,2,70286,70302,16,70314,70319,1,70379,70383,1,70394,70399,1,70404,70413,9,70414,70417,3,70418,70441,23,70449,70452,3,70458,70469,11,70470,70473,3,70474,70478,4,70479,70481,2,70482,70486,1,70488,70492,1,70500,70501,1,70509,70511,1,70517,70527,1,70538,70540,2,70541,70543,2,70582,70593,11,70595,70596,1,70598,70603,5,70614,70617,3,70618,70624,1,70627,70655,1,70748,70754,6,70755,70783,1,70856,70863,1,70874,71039,1,71094,71095,1,71134,71167,1,71237,71247,1,71258,71263,1,71277,71295,1,71354,71359,1,71370,71375,1,71396,71423,1,71451,71452,1,71468,71471,1,71495,71679,1,71740,71839,1,71923,71934,1,71943,71944,1,71946,71947,1,71956,71959,3,71990,71993,3,71994,72007,13,72008,72015,1,72026,72095,1,72104,72105,1,72152,72153,1,72165,72191,1,72264,72271,1,72355,72367,1,72441,72447,1,72458,72639,1,72674,72687,1,72698,72703,1,72713,72759,46,72774,72783,1,72813,72815,1,72848,72849,1,72872,72887,15,72888,72959,1,72967,72970,3,73015,73017,1,73019,73022,3,73032,73039,1,73050,73055,1,73062,73065,3,73103,73106,3,73113,73119,1,73130,73439,1,73465,73471,1,73489,73531,42,73532,73533,1,73563,73647,1,73649,73663,1,73714,73726,1,74650,74751,1,74863,74869,6,74870,74879,1,75076,77711,1,77811,77823,1,78896,78911,1,78934,78943,1,82939,82943,1,83527,90367,1,90426,92159,1,92729,92735,1,92767,92778,11,92779,92781,1,92863,92874,11,92875,92879,1,92910,92911,1,92918,92927,1,92998,93007,1,93018,93026,8,93048,93052,1,93072,93503,1,93562,93759,1,93851,93951,1,94027,94030,1,94088,94094,1,94112,94175,1,94181,94191,1,94194,94207,1,100344,100351,1,101590,101630,1,101641,110575,1,110580,110588,8,110591,110883,292,110884,110897,1,110899,110927,1,110931,110932,1,110934,110947,1,110952,110959,1,111356,113663,1,113771,113775,1,113789,113791,1,113801,113807,1,113818,113819,1,113824,117759,1,118010,118015,1,118452,118527,1,118574,118575,1,118599,118607,1,118724,118783,1,119030,119039,1,119079,119080,1,119155,119162,1,119275,119295,1,119366,119487,1,119508,119519,1,119540,119551,1,119639,119647,1,119673,119807,1,119893,119965,72,119968,119969,1,119971,119972,1,119975,119976,1,119981,119994,13,119996,120004,8,120070,120075,5,120076,120085,9,120093,120122,29,120127,120133,6,120135,120137,1,120145,120486,341,120487,120780,293,120781,121484,703,121485,121498,1,121504,121520,16,121521,122623,1,122655,122660,1,122667,122879,1,122887,122905,18,122906,122914,8,122917,122923,6,122924,122927,1,122990,123022,1,123024,123135,1,123181,123183,1,123198,123199,1,123210,123213,1,123216,123535,1,123567,123583,1,123642,123646,1,123648,124111,1,124154,124367,1,124411,124414,1,124416,124895,1,124903,124908,5,124911,124927,16,125125,125126,1,125143,125183,1,125260,125263,1,125274,125277,1,125280,126064,1,126133,126208,1,126270,126463,1,126468,126496,28,126499,126501,2,126502,126504,2,126515,126520,5,126522,126524,2,126525,126529,1,126531,126534,1,126536,126540,2,126544,126547,3,126549,126550,1,126552,126560,2,126563,126565,2,126566,126571,5,126579,126589,5,126591,126602,11,126620,126624,1,126628,126634,6,126652,126703,1,126706,126975,1,127020,127023,1,127124,127135,1,127151,127152,1,127168,127184,16,127222,127231,1,127406,127461,1,127491,127503,1,127548,127551,1,127561,127567,1,127570,127583,1,127590,127743,1,128728,128731,1,128749,128751,1,128765,128767,1,128887,128890,1,128986,128991,1,129004,129007,1,129009,129023,1,129036,129039,1,129096,129103,1,129114,129119,1,129160,129167,1,129198,129199,1,129212,129215,1,129218,129279,1,129620,129631,1,129646,129647,1,129661,129663,1,129674,129678,1,129735,129741,1,129757,129758,1,129770,129775,1,129785,129791,1,129939,130042,103,130043,131071,1,173792,173823,1,177978,177983,1,178206,178207,1,183970,183983,1,191457,191471,1,192094,194559,1,195102,196607,1,201547,201551,1,205744,917759,1,918e3,1114111,1]));static Cc=new k(new Uint32Array([0,31,1,127,159,1]));static Cf=new k(new Uint32Array([173,1536,1363,1537,1541,1,1564,1757,193,1807,2192,385,2193,2274,81,6158,8203,2045,8204,8207,1,8234,8238,1,8288,8292,1,8294,8303,1,65279,65529,250,65530,65531,1,69821,69837,16,78896,78911,1,113824,113827,1,119155,119162,1,917505,917536,31,917537,917631,1]));static Co=new k(new Uint32Array([57344,63743,1,983040,1048573,1,1048576,1114109,1]));static Cs=new k(new Uint32Array([55296,57343,1]));static L=new k(new Uint32Array([65,90,1,97,122,1,170,181,11,186,192,6,193,214,1,216,246,1,248,705,1,710,721,1,736,740,1,748,750,2,880,884,1,886,887,1,890,893,1,895,902,7,904,906,1,908,910,2,911,929,1,931,1013,1,1015,1153,1,1162,1327,1,1329,1366,1,1369,1376,7,1377,1416,1,1488,1514,1,1519,1522,1,1568,1610,1,1646,1647,1,1649,1747,1,1749,1765,16,1766,1774,8,1775,1786,11,1787,1788,1,1791,1808,17,1810,1839,1,1869,1957,1,1969,1994,25,1995,2026,1,2036,2037,1,2042,2048,6,2049,2069,1,2074,2084,10,2088,2112,24,2113,2136,1,2144,2154,1,2160,2183,1,2185,2190,1,2208,2249,1,2308,2361,1,2365,2384,19,2392,2401,1,2417,2432,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2493,2510,17,2524,2525,1,2527,2529,1,2544,2545,1,2556,2565,9,2566,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2649,2652,1,2654,2674,20,2675,2676,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2749,2768,19,2784,2785,1,2809,2821,12,2822,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2877,2908,31,2909,2911,2,2912,2913,1,2929,2947,18,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3024,3077,53,3078,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3133,3160,27,3161,3162,1,3165,3168,3,3169,3200,31,3205,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3261,3293,32,3294,3296,2,3297,3313,16,3314,3332,18,3333,3340,1,3342,3344,1,3346,3386,1,3389,3406,17,3412,3414,1,3423,3425,1,3450,3455,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3585,3632,1,3634,3635,1,3648,3654,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3760,1,3762,3763,1,3773,3776,3,3777,3780,1,3782,3804,22,3805,3807,1,3840,3904,64,3905,3911,1,3913,3948,1,3976,3980,1,4096,4138,1,4159,4176,17,4177,4181,1,4186,4189,1,4193,4197,4,4198,4206,8,4207,4208,1,4213,4225,1,4238,4256,18,4257,4293,1,4295,4301,6,4304,4346,1,4348,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4992,5007,1,5024,5109,1,5112,5117,1,5121,5740,1,5743,5759,1,5761,5786,1,5792,5866,1,5873,5880,1,5888,5905,1,5919,5937,1,5952,5969,1,5984,5996,1,5998,6e3,1,6016,6067,1,6103,6108,5,6176,6264,1,6272,6276,1,6279,6312,1,6314,6320,6,6321,6389,1,6400,6430,1,6480,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6656,6678,1,6688,6740,1,6823,6917,94,6918,6963,1,6981,6988,1,7043,7072,1,7086,7087,1,7098,7141,1,7168,7203,1,7245,7247,1,7258,7293,1,7296,7306,1,7312,7354,1,7357,7359,1,7401,7404,1,7406,7411,1,7413,7414,1,7418,7424,6,7425,7615,1,7680,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8124,1,8126,8130,4,8131,8132,1,8134,8140,1,8144,8147,1,8150,8155,1,8160,8172,1,8178,8180,1,8182,8188,1,8305,8319,14,8336,8348,1,8450,8455,5,8458,8467,1,8469,8473,4,8474,8477,1,8484,8490,2,8491,8493,1,8495,8505,1,8508,8511,1,8517,8521,1,8526,8579,53,8580,11264,2684,11265,11492,1,11499,11502,1,11506,11507,1,11520,11557,1,11559,11565,6,11568,11623,1,11631,11648,17,11649,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,11823,12293,470,12294,12337,43,12338,12341,1,12347,12348,1,12353,12438,1,12445,12447,1,12449,12538,1,12540,12543,1,12549,12591,1,12593,12686,1,12704,12735,1,12784,12799,1,13312,19903,1,19968,42124,1,42192,42237,1,42240,42508,1,42512,42527,1,42538,42539,1,42560,42606,1,42623,42653,1,42656,42725,1,42775,42783,1,42786,42888,1,42891,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43009,1,43011,43013,1,43015,43018,1,43020,43042,1,43072,43123,1,43138,43187,1,43250,43255,1,43259,43261,2,43262,43274,12,43275,43301,1,43312,43334,1,43360,43388,1,43396,43442,1,43471,43488,17,43489,43492,1,43494,43503,1,43514,43518,1,43520,43560,1,43584,43586,1,43588,43595,1,43616,43638,1,43642,43646,4,43647,43695,1,43697,43701,4,43702,43705,3,43706,43709,1,43712,43714,2,43739,43741,1,43744,43754,1,43762,43764,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43824,43866,1,43868,43881,1,43888,44002,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64256,64262,1,64275,64279,1,64285,64287,2,64288,64296,1,64298,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64433,1,64467,64829,1,64848,64911,1,64914,64967,1,65008,65019,1,65136,65140,1,65142,65276,1,65313,65338,1,65345,65370,1,65382,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,66176,66204,1,66208,66256,1,66304,66335,1,66349,66368,1,66370,66377,1,66384,66421,1,66432,66461,1,66464,66499,1,66504,66511,1,66560,66717,1,66736,66771,1,66776,66811,1,66816,66855,1,66864,66915,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67456,67461,1,67463,67504,1,67506,67514,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67680,67702,1,67712,67742,1,67808,67826,1,67828,67829,1,67840,67861,1,67872,67897,1,67968,68023,1,68030,68031,1,68096,68112,16,68113,68115,1,68117,68119,1,68121,68149,1,68192,68220,1,68224,68252,1,68288,68295,1,68297,68324,1,68352,68405,1,68416,68437,1,68448,68466,1,68480,68497,1,68608,68680,1,68736,68786,1,68800,68850,1,68864,68899,1,68938,68965,1,68975,68997,1,69248,69289,1,69296,69297,1,69314,69316,1,69376,69404,1,69415,69424,9,69425,69445,1,69488,69505,1,69552,69572,1,69600,69622,1,69635,69687,1,69745,69746,1,69749,69763,14,69764,69807,1,69840,69864,1,69891,69926,1,69956,69959,3,69968,70002,1,70006,70019,13,70020,70066,1,70081,70084,1,70106,70108,2,70144,70161,1,70163,70187,1,70207,70208,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70312,1,70320,70366,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70461,70480,19,70493,70497,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70609,26,70611,70656,45,70657,70708,1,70727,70730,1,70751,70753,1,70784,70831,1,70852,70853,1,70855,71040,185,71041,71086,1,71128,71131,1,71168,71215,1,71236,71296,60,71297,71338,1,71352,71424,72,71425,71450,1,71488,71494,1,71680,71723,1,71840,71903,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71983,1,71999,72001,2,72096,72103,1,72106,72144,1,72161,72163,2,72192,72203,11,72204,72242,1,72250,72272,22,72284,72329,1,72349,72368,19,72369,72440,1,72640,72672,1,72704,72712,1,72714,72750,1,72768,72818,50,72819,72847,1,72960,72966,1,72968,72969,1,72971,73008,1,73030,73056,26,73057,73061,1,73063,73064,1,73066,73097,1,73112,73440,328,73441,73458,1,73474,73476,2,73477,73488,1,73490,73523,1,73648,73728,80,73729,74649,1,74880,75075,1,77712,77808,1,77824,78895,1,78913,78918,1,78944,82938,1,82944,83526,1,90368,90397,1,92160,92728,1,92736,92766,1,92784,92862,1,92880,92909,1,92928,92975,1,92992,92995,1,93027,93047,1,93053,93071,1,93504,93548,1,93760,93823,1,93952,94026,1,94032,94099,67,94100,94111,1,94176,94177,1,94179,94208,29,94209,100343,1,100352,101589,1,101631,101640,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120512,1,120514,120538,1,120540,120570,1,120572,120596,1,120598,120628,1,120630,120654,1,120656,120686,1,120688,120712,1,120714,120744,1,120746,120770,1,120772,120779,1,122624,122654,1,122661,122666,1,122928,122989,1,123136,123180,1,123191,123197,1,123214,123536,322,123537,123565,1,123584,123627,1,124112,124139,1,124368,124397,1,124400,124896,496,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,125184,125251,1,125259,126464,1205,126465,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static foldL=new k(new Uint32Array([837,837,1]));static Ll=new k(new Uint32Array([97,122,1,181,223,42,224,246,1,248,255,1,257,311,2,312,328,2,329,375,2,378,382,2,383,384,1,387,389,2,392,396,4,397,402,5,405,409,4,410,411,1,414,417,3,419,421,2,424,426,2,427,429,2,432,436,4,438,441,3,442,445,3,446,447,1,454,460,3,462,476,2,477,495,2,496,499,3,501,505,4,507,563,2,564,569,1,572,575,3,576,578,2,583,591,2,592,659,1,661,687,1,881,883,2,887,891,4,892,893,1,912,940,28,941,974,1,976,977,1,981,983,1,985,1007,2,1008,1011,1,1013,1019,3,1020,1072,52,1073,1119,1,1121,1153,2,1163,1215,2,1218,1230,2,1231,1327,2,1376,1416,1,4304,4346,1,4349,4351,1,5112,5117,1,7296,7304,1,7306,7424,118,7425,7467,1,7531,7543,1,7545,7578,1,7681,7829,2,7830,7837,1,7839,7935,2,7936,7943,1,7952,7957,1,7968,7975,1,7984,7991,1,8e3,8005,1,8016,8023,1,8032,8039,1,8048,8061,1,8064,8071,1,8080,8087,1,8096,8103,1,8112,8116,1,8118,8119,1,8126,8130,4,8131,8132,1,8134,8135,1,8144,8147,1,8150,8151,1,8160,8167,1,8178,8180,1,8182,8183,1,8458,8462,4,8463,8467,4,8495,8505,5,8508,8509,1,8518,8521,1,8526,8580,54,11312,11359,1,11361,11365,4,11366,11372,2,11377,11379,2,11380,11382,2,11383,11387,1,11393,11491,2,11492,11500,8,11502,11507,5,11520,11557,1,11559,11565,6,42561,42605,2,42625,42651,2,42787,42799,2,42800,42801,1,42803,42865,2,42866,42872,1,42874,42876,2,42879,42887,2,42892,42894,2,42897,42899,2,42900,42901,1,42903,42921,2,42927,42933,6,42935,42947,2,42952,42954,2,42957,42961,4,42963,42971,2,42998,43002,4,43824,43866,1,43872,43880,1,43888,43967,1,64256,64262,1,64275,64279,1,65345,65370,1,66600,66639,1,66776,66811,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,68800,68850,1,68976,68997,1,71872,71903,1,93792,93823,1,119834,119859,1,119886,119892,1,119894,119911,1,119938,119963,1,119990,119993,1,119995,119997,2,119998,120003,1,120005,120015,1,120042,120067,1,120094,120119,1,120146,120171,1,120198,120223,1,120250,120275,1,120302,120327,1,120354,120379,1,120406,120431,1,120458,120485,1,120514,120538,1,120540,120545,1,120572,120596,1,120598,120603,1,120630,120654,1,120656,120661,1,120688,120712,1,120714,120719,1,120746,120770,1,120772,120777,1,120779,122624,1845,122625,122633,1,122635,122654,1,122661,122666,1,125218,125251,1]));static foldLl=new k(new Uint32Array([65,90,1,192,214,1,216,222,1,256,302,2,306,310,2,313,327,2,330,376,2,377,381,2,385,386,1,388,390,2,391,393,2,394,395,1,398,401,1,403,404,1,406,408,1,412,413,1,415,416,1,418,422,2,423,425,2,428,430,2,431,433,2,434,435,1,437,439,2,440,444,4,452,453,1,455,456,1,458,459,1,461,475,2,478,494,2,497,498,1,500,502,2,503,504,1,506,562,2,570,571,1,573,574,1,577,579,2,580,582,1,584,590,2,837,880,43,882,886,4,895,902,7,904,906,1,908,910,2,911,913,2,914,929,1,931,939,1,975,984,9,986,1006,2,1012,1015,3,1017,1018,1,1021,1071,1,1120,1152,2,1162,1216,2,1217,1229,2,1232,1326,2,1329,1366,1,4256,4293,1,4295,4301,6,5024,5109,1,7305,7312,7,7313,7354,1,7357,7359,1,7680,7828,2,7838,7934,2,7944,7951,1,7960,7965,1,7976,7983,1,7992,7999,1,8008,8013,1,8025,8031,2,8040,8047,1,8072,8079,1,8088,8095,1,8104,8111,1,8120,8124,1,8136,8140,1,8152,8155,1,8168,8172,1,8184,8188,1,8486,8490,4,8491,8498,7,8579,11264,2685,11265,11311,1,11360,11362,2,11363,11364,1,11367,11373,2,11374,11376,1,11378,11381,3,11390,11392,1,11394,11490,2,11499,11501,2,11506,42560,31054,42562,42604,2,42624,42650,2,42786,42798,2,42802,42862,2,42873,42877,2,42878,42886,2,42891,42893,2,42896,42898,2,42902,42922,2,42923,42926,1,42928,42932,1,42934,42948,2,42949,42951,1,42953,42955,2,42956,42960,4,42966,42972,2,42997,65313,22316,65314,65338,1,66560,66599,1,66736,66771,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,68736,68786,1,68944,68965,1,71840,71871,1,93760,93791,1,125184,125217,1]));static Lm=new k(new Uint32Array([688,705,1,710,721,1,736,740,1,748,750,2,884,890,6,1369,1600,231,1765,1766,1,2036,2037,1,2042,2074,32,2084,2088,4,2249,2417,168,3654,3782,128,4348,6103,1755,6211,6823,612,7288,7293,1,7468,7530,1,7544,7579,35,7580,7615,1,8305,8319,14,8336,8348,1,11388,11389,1,11631,11823,192,12293,12337,44,12338,12341,1,12347,12445,98,12446,12540,94,12541,12542,1,40981,42232,1251,42233,42237,1,42508,42623,115,42652,42653,1,42775,42783,1,42864,42888,24,42994,42996,1,43e3,43001,1,43471,43494,23,43632,43741,109,43763,43764,1,43868,43871,1,43881,65392,21511,65438,65439,1,67456,67461,1,67463,67504,1,67506,67514,1,68942,68975,33,92992,92995,1,93504,93506,1,93547,93548,1,94099,94111,1,94176,94177,1,94179,110576,16397,110577,110579,1,110581,110587,1,110589,110590,1,122928,122989,1,123191,123197,1,124139,125259,1120]));static Lo=new k(new Uint32Array([170,186,16,443,448,5,449,451,1,660,1488,828,1489,1514,1,1519,1522,1,1568,1599,1,1601,1610,1,1646,1647,1,1649,1747,1,1749,1774,25,1775,1786,11,1787,1788,1,1791,1808,17,1810,1839,1,1869,1957,1,1969,1994,25,1995,2026,1,2048,2069,1,2112,2136,1,2144,2154,1,2160,2183,1,2185,2190,1,2208,2248,1,2308,2361,1,2365,2384,19,2392,2401,1,2418,2432,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2493,2510,17,2524,2525,1,2527,2529,1,2544,2545,1,2556,2565,9,2566,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2649,2652,1,2654,2674,20,2675,2676,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2749,2768,19,2784,2785,1,2809,2821,12,2822,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2877,2908,31,2909,2911,2,2912,2913,1,2929,2947,18,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3024,3077,53,3078,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3133,3160,27,3161,3162,1,3165,3168,3,3169,3200,31,3205,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3261,3293,32,3294,3296,2,3297,3313,16,3314,3332,18,3333,3340,1,3342,3344,1,3346,3386,1,3389,3406,17,3412,3414,1,3423,3425,1,3450,3455,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3585,3632,1,3634,3635,1,3648,3653,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3760,1,3762,3763,1,3773,3776,3,3777,3780,1,3804,3807,1,3840,3904,64,3905,3911,1,3913,3948,1,3976,3980,1,4096,4138,1,4159,4176,17,4177,4181,1,4186,4189,1,4193,4197,4,4198,4206,8,4207,4208,1,4213,4225,1,4238,4352,114,4353,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4992,5007,1,5121,5740,1,5743,5759,1,5761,5786,1,5792,5866,1,5873,5880,1,5888,5905,1,5919,5937,1,5952,5969,1,5984,5996,1,5998,6e3,1,6016,6067,1,6108,6176,68,6177,6210,1,6212,6264,1,6272,6276,1,6279,6312,1,6314,6320,6,6321,6389,1,6400,6430,1,6480,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6656,6678,1,6688,6740,1,6917,6963,1,6981,6988,1,7043,7072,1,7086,7087,1,7098,7141,1,7168,7203,1,7245,7247,1,7258,7287,1,7401,7404,1,7406,7411,1,7413,7414,1,7418,8501,1083,8502,8504,1,11568,11623,1,11648,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,12294,12348,54,12353,12438,1,12447,12449,2,12450,12538,1,12543,12549,6,12550,12591,1,12593,12686,1,12704,12735,1,12784,12799,1,13312,19903,1,19968,40980,1,40982,42124,1,42192,42231,1,42240,42507,1,42512,42527,1,42538,42539,1,42606,42656,50,42657,42725,1,42895,42999,104,43003,43009,1,43011,43013,1,43015,43018,1,43020,43042,1,43072,43123,1,43138,43187,1,43250,43255,1,43259,43261,2,43262,43274,12,43275,43301,1,43312,43334,1,43360,43388,1,43396,43442,1,43488,43492,1,43495,43503,1,43514,43518,1,43520,43560,1,43584,43586,1,43588,43595,1,43616,43631,1,43633,43638,1,43642,43646,4,43647,43695,1,43697,43701,4,43702,43705,3,43706,43709,1,43712,43714,2,43739,43740,1,43744,43754,1,43762,43777,15,43778,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43968,44002,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64285,64287,2,64288,64296,1,64298,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64433,1,64467,64829,1,64848,64911,1,64914,64967,1,65008,65019,1,65136,65140,1,65142,65276,1,65382,65391,1,65393,65437,1,65440,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,66176,66204,1,66208,66256,1,66304,66335,1,66349,66368,1,66370,66377,1,66384,66421,1,66432,66461,1,66464,66499,1,66504,66511,1,66640,66717,1,66816,66855,1,66864,66915,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67680,67702,1,67712,67742,1,67808,67826,1,67828,67829,1,67840,67861,1,67872,67897,1,67968,68023,1,68030,68031,1,68096,68112,16,68113,68115,1,68117,68119,1,68121,68149,1,68192,68220,1,68224,68252,1,68288,68295,1,68297,68324,1,68352,68405,1,68416,68437,1,68448,68466,1,68480,68497,1,68608,68680,1,68864,68899,1,68938,68941,1,68943,69248,305,69249,69289,1,69296,69297,1,69314,69316,1,69376,69404,1,69415,69424,9,69425,69445,1,69488,69505,1,69552,69572,1,69600,69622,1,69635,69687,1,69745,69746,1,69749,69763,14,69764,69807,1,69840,69864,1,69891,69926,1,69956,69959,3,69968,70002,1,70006,70019,13,70020,70066,1,70081,70084,1,70106,70108,2,70144,70161,1,70163,70187,1,70207,70208,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70312,1,70320,70366,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70461,70480,19,70493,70497,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70609,26,70611,70656,45,70657,70708,1,70727,70730,1,70751,70753,1,70784,70831,1,70852,70853,1,70855,71040,185,71041,71086,1,71128,71131,1,71168,71215,1,71236,71296,60,71297,71338,1,71352,71424,72,71425,71450,1,71488,71494,1,71680,71723,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71983,1,71999,72001,2,72096,72103,1,72106,72144,1,72161,72163,2,72192,72203,11,72204,72242,1,72250,72272,22,72284,72329,1,72349,72368,19,72369,72440,1,72640,72672,1,72704,72712,1,72714,72750,1,72768,72818,50,72819,72847,1,72960,72966,1,72968,72969,1,72971,73008,1,73030,73056,26,73057,73061,1,73063,73064,1,73066,73097,1,73112,73440,328,73441,73458,1,73474,73476,2,73477,73488,1,73490,73523,1,73648,73728,80,73729,74649,1,74880,75075,1,77712,77808,1,77824,78895,1,78913,78918,1,78944,82938,1,82944,83526,1,90368,90397,1,92160,92728,1,92736,92766,1,92784,92862,1,92880,92909,1,92928,92975,1,93027,93047,1,93053,93071,1,93507,93546,1,93952,94026,1,94032,94208,176,94209,100343,1,100352,101589,1,101631,101640,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,122634,123136,502,123137,123180,1,123214,123536,322,123537,123565,1,123584,123627,1,124112,124138,1,124368,124397,1,124400,124896,496,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static Lt=new k(new Uint32Array([453,459,3,498,8072,7574,8073,8079,1,8088,8095,1,8104,8111,1,8124,8140,16,8188,8188,1]));static foldLt=new k(new Uint32Array([452,454,2,455,457,2,458,460,2,497,499,2,8064,8071,1,8080,8087,1,8096,8103,1,8115,8131,16,8179,8179,1]));static Lu=new k(new Uint32Array([65,90,1,192,214,1,216,222,1,256,310,2,313,327,2,330,376,2,377,381,2,385,386,1,388,390,2,391,393,2,394,395,1,398,401,1,403,404,1,406,408,1,412,413,1,415,416,1,418,422,2,423,425,2,428,430,2,431,433,2,434,435,1,437,439,2,440,444,4,452,461,3,463,475,2,478,494,2,497,500,3,502,504,1,506,562,2,570,571,1,573,574,1,577,579,2,580,582,1,584,590,2,880,882,2,886,895,9,902,904,2,905,906,1,908,910,2,911,913,2,914,929,1,931,939,1,975,978,3,979,980,1,984,1006,2,1012,1015,3,1017,1018,1,1021,1071,1,1120,1152,2,1162,1216,2,1217,1229,2,1232,1326,2,1329,1366,1,4256,4293,1,4295,4301,6,5024,5109,1,7305,7312,7,7313,7354,1,7357,7359,1,7680,7828,2,7838,7934,2,7944,7951,1,7960,7965,1,7976,7983,1,7992,7999,1,8008,8013,1,8025,8031,2,8040,8047,1,8120,8123,1,8136,8139,1,8152,8155,1,8168,8172,1,8184,8187,1,8450,8455,5,8459,8461,1,8464,8466,1,8469,8473,4,8474,8477,1,8484,8490,2,8491,8493,1,8496,8499,1,8510,8511,1,8517,8579,62,11264,11311,1,11360,11362,2,11363,11364,1,11367,11373,2,11374,11376,1,11378,11381,3,11390,11392,1,11394,11490,2,11499,11501,2,11506,42560,31054,42562,42604,2,42624,42650,2,42786,42798,2,42802,42862,2,42873,42877,2,42878,42886,2,42891,42893,2,42896,42898,2,42902,42922,2,42923,42926,1,42928,42932,1,42934,42948,2,42949,42951,1,42953,42955,2,42956,42960,4,42966,42972,2,42997,65313,22316,65314,65338,1,66560,66599,1,66736,66771,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,68736,68786,1,68944,68965,1,71840,71871,1,93760,93791,1,119808,119833,1,119860,119885,1,119912,119937,1,119964,119966,2,119967,119973,3,119974,119977,3,119978,119980,1,119982,119989,1,120016,120041,1,120068,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120120,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120172,120197,1,120224,120249,1,120276,120301,1,120328,120353,1,120380,120405,1,120432,120457,1,120488,120512,1,120546,120570,1,120604,120628,1,120662,120686,1,120720,120744,1,120778,125184,4406,125185,125217,1]));static Upper=this.Lu;static foldLu=new k(new Uint32Array([97,122,1,181,223,42,224,246,1,248,255,1,257,303,2,307,311,2,314,328,2,331,375,2,378,382,2,383,384,1,387,389,2,392,396,4,402,405,3,409,411,1,414,417,3,419,421,2,424,429,5,432,436,4,438,441,3,445,447,2,453,454,1,456,457,1,459,460,1,462,476,2,477,495,2,498,499,1,501,505,4,507,543,2,547,563,2,572,575,3,576,578,2,583,591,2,592,596,1,598,599,1,601,603,2,604,608,4,609,611,2,612,614,1,616,620,1,623,625,2,626,629,3,637,640,3,642,643,1,647,652,1,658,669,11,670,837,167,881,883,2,887,891,4,892,893,1,940,943,1,945,974,1,976,977,1,981,983,1,985,1007,2,1008,1011,1,1013,1019,3,1072,1119,1,1121,1153,2,1163,1215,2,1218,1230,2,1231,1327,2,1377,1414,1,4304,4346,1,4349,4351,1,5112,5117,1,7296,7304,1,7306,7545,239,7549,7566,17,7681,7829,2,7835,7841,6,7843,7935,2,7936,7943,1,7952,7957,1,7968,7975,1,7984,7991,1,8e3,8005,1,8017,8023,2,8032,8039,1,8048,8061,1,8112,8113,1,8126,8144,18,8145,8160,15,8161,8165,4,8526,8580,54,11312,11359,1,11361,11365,4,11366,11372,2,11379,11382,3,11393,11491,2,11500,11502,2,11507,11520,13,11521,11557,1,11559,11565,6,42561,42605,2,42625,42651,2,42787,42799,2,42803,42863,2,42874,42876,2,42879,42887,2,42892,42897,5,42899,42900,1,42903,42921,2,42933,42947,2,42952,42954,2,42957,42961,4,42967,42971,2,42998,43859,861,43888,43967,1,65345,65370,1,66600,66639,1,66776,66811,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,68800,68850,1,68976,68997,1,71872,71903,1,93792,93823,1,125218,125251,1]));static M=new k(new Uint32Array([768,879,1,1155,1161,1,1425,1469,1,1471,1473,2,1474,1476,2,1477,1479,2,1552,1562,1,1611,1631,1,1648,1750,102,1751,1756,1,1759,1764,1,1767,1768,1,1770,1773,1,1809,1840,31,1841,1866,1,1958,1968,1,2027,2035,1,2045,2070,25,2071,2073,1,2075,2083,1,2085,2087,1,2089,2093,1,2137,2139,1,2199,2207,1,2250,2273,1,2275,2307,1,2362,2364,1,2366,2383,1,2385,2391,1,2402,2403,1,2433,2435,1,2492,2494,2,2495,2500,1,2503,2504,1,2507,2509,1,2519,2530,11,2531,2558,27,2561,2563,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2672,31,2673,2677,4,2689,2691,1,2748,2750,2,2751,2757,1,2759,2761,1,2763,2765,1,2786,2787,1,2810,2815,1,2817,2819,1,2876,2878,2,2879,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2914,2915,1,2946,3006,60,3007,3010,1,3014,3016,1,3018,3021,1,3031,3072,41,3073,3076,1,3132,3134,2,3135,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3170,3171,1,3201,3203,1,3260,3262,2,3263,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3298,3299,1,3315,3328,13,3329,3331,1,3387,3388,1,3390,3396,1,3398,3400,1,3402,3405,1,3415,3426,11,3427,3457,30,3458,3459,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3570,3571,1,3633,3636,3,3637,3642,1,3655,3662,1,3761,3764,3,3765,3772,1,3784,3790,1,3864,3865,1,3893,3897,2,3902,3903,1,3953,3972,1,3974,3975,1,3981,3991,1,3993,4028,1,4038,4139,101,4140,4158,1,4182,4185,1,4190,4192,1,4194,4196,1,4199,4205,1,4209,4212,1,4226,4237,1,4239,4250,11,4251,4253,1,4957,4959,1,5906,5909,1,5938,5940,1,5970,5971,1,6002,6003,1,6068,6099,1,6109,6155,46,6156,6157,1,6159,6277,118,6278,6313,35,6432,6443,1,6448,6459,1,6679,6683,1,6741,6750,1,6752,6780,1,6783,6832,49,6833,6862,1,6912,6916,1,6964,6980,1,7019,7027,1,7040,7042,1,7073,7085,1,7142,7155,1,7204,7223,1,7376,7378,1,7380,7400,1,7405,7412,7,7415,7417,1,7616,7679,1,8400,8432,1,11503,11505,1,11647,11744,97,11745,11775,1,12330,12335,1,12441,12442,1,42607,42610,1,42612,42621,1,42654,42655,1,42736,42737,1,43010,43014,4,43019,43043,24,43044,43047,1,43052,43136,84,43137,43188,51,43189,43205,1,43232,43249,1,43263,43302,39,43303,43309,1,43335,43347,1,43392,43395,1,43443,43456,1,43493,43561,68,43562,43574,1,43587,43596,9,43597,43643,46,43644,43645,1,43696,43698,2,43699,43700,1,43703,43704,1,43710,43711,1,43713,43755,42,43756,43759,1,43765,43766,1,44003,44010,1,44012,44013,1,64286,65024,738,65025,65039,1,65056,65071,1,66045,66272,227,66422,66426,1,68097,68099,1,68101,68102,1,68108,68111,1,68152,68154,1,68159,68325,166,68326,68900,574,68901,68903,1,68969,68973,1,69291,69292,1,69372,69375,1,69446,69456,1,69506,69509,1,69632,69634,1,69688,69702,1,69744,69747,3,69748,69759,11,69760,69762,1,69808,69818,1,69826,69888,62,69889,69890,1,69927,69940,1,69957,69958,1,70003,70016,13,70017,70018,1,70067,70080,1,70089,70092,1,70094,70095,1,70188,70199,1,70206,70209,3,70367,70378,1,70400,70403,1,70459,70460,1,70462,70468,1,70471,70472,1,70475,70477,1,70487,70498,11,70499,70502,3,70503,70508,1,70512,70516,1,70584,70592,1,70594,70597,3,70599,70602,1,70604,70608,1,70610,70625,15,70626,70709,83,70710,70726,1,70750,70832,82,70833,70851,1,71087,71093,1,71096,71104,1,71132,71133,1,71216,71232,1,71339,71351,1,71453,71467,1,71724,71738,1,71984,71989,1,71991,71992,1,71995,71998,1,72e3,72002,2,72003,72145,142,72146,72151,1,72154,72160,1,72164,72193,29,72194,72202,1,72243,72249,1,72251,72254,1,72263,72273,10,72274,72283,1,72330,72345,1,72751,72758,1,72760,72767,1,72850,72871,1,72873,72886,1,73009,73014,1,73018,73020,2,73021,73023,2,73024,73029,1,73031,73098,67,73099,73102,1,73104,73105,1,73107,73111,1,73459,73462,1,73472,73473,1,73475,73524,49,73525,73530,1,73534,73538,1,73562,78912,5350,78919,78933,1,90398,90415,1,92912,92916,1,92976,92982,1,94031,94033,2,94034,94087,1,94095,94098,1,94180,94192,12,94193,113821,19628,113822,118528,4706,118529,118573,1,118576,118598,1,119141,119145,1,119149,119154,1,119163,119170,1,119173,119179,1,119210,119213,1,119362,119364,1,121344,121398,1,121403,121452,1,121461,121476,15,121499,121503,1,121505,121519,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,123023,123184,161,123185,123190,1,123566,123628,62,123629,123631,1,124140,124143,1,124398,124399,1,125136,125142,1,125252,125258,1,917760,917999,1]));static foldM=new k(new Uint32Array([921,953,32,8126,8126,1]));static Mc=new k(new Uint32Array([2307,2363,56,2366,2368,1,2377,2380,1,2382,2383,1,2434,2435,1,2494,2496,1,2503,2504,1,2507,2508,1,2519,2563,44,2622,2624,1,2691,2750,59,2751,2752,1,2761,2763,2,2764,2818,54,2819,2878,59,2880,2887,7,2888,2891,3,2892,2903,11,3006,3007,1,3009,3010,1,3014,3016,1,3018,3020,1,3031,3073,42,3074,3075,1,3137,3140,1,3202,3203,1,3262,3264,2,3265,3268,1,3271,3272,1,3274,3275,1,3285,3286,1,3315,3330,15,3331,3390,59,3391,3392,1,3398,3400,1,3402,3404,1,3415,3458,43,3459,3535,76,3536,3537,1,3544,3551,1,3570,3571,1,3902,3903,1,3967,4139,172,4140,4145,5,4152,4155,3,4156,4182,26,4183,4194,11,4195,4196,1,4199,4205,1,4227,4228,1,4231,4236,1,4239,4250,11,4251,4252,1,5909,5940,31,6070,6078,8,6079,6085,1,6087,6088,1,6435,6438,1,6441,6443,1,6448,6449,1,6451,6456,1,6681,6682,1,6741,6743,2,6753,6755,2,6756,6765,9,6766,6770,1,6916,6965,49,6971,6973,2,6974,6977,1,6979,6980,1,7042,7073,31,7078,7079,1,7082,7143,61,7146,7148,1,7150,7154,4,7155,7204,49,7205,7211,1,7220,7221,1,7393,7415,22,12334,12335,1,43043,43044,1,43047,43136,89,43137,43188,51,43189,43203,1,43346,43347,1,43395,43444,49,43445,43450,5,43451,43454,3,43455,43456,1,43567,43568,1,43571,43572,1,43597,43643,46,43645,43755,110,43758,43759,1,43765,44003,238,44004,44006,2,44007,44009,2,44010,44012,2,69632,69634,2,69762,69808,46,69809,69810,1,69815,69816,1,69932,69957,25,69958,70018,60,70067,70069,1,70079,70080,1,70094,70188,94,70189,70190,1,70194,70195,1,70197,70368,171,70369,70370,1,70402,70403,1,70462,70463,1,70465,70468,1,70471,70472,1,70475,70477,1,70487,70498,11,70499,70584,85,70585,70586,1,70594,70597,3,70599,70602,1,70604,70605,1,70607,70709,102,70710,70711,1,70720,70721,1,70725,70832,107,70833,70834,1,70841,70843,2,70844,70846,1,70849,71087,238,71088,71089,1,71096,71099,1,71102,71216,114,71217,71218,1,71227,71228,1,71230,71340,110,71342,71343,1,71350,71454,104,71456,71457,1,71462,71724,262,71725,71726,1,71736,71984,248,71985,71989,1,71991,71992,1,71997,72e3,3,72002,72145,143,72146,72147,1,72156,72159,1,72164,72249,85,72279,72280,1,72343,72751,408,72766,72873,107,72881,72884,3,73098,73102,1,73107,73108,1,73110,73461,351,73462,73475,13,73524,73525,1,73534,73535,1,73537,90410,16873,90411,90412,1,94033,94087,1,94192,94193,1,119141,119142,1,119149,119154,1]));static Me=new k(new Uint32Array([1160,1161,1,6846,8413,1567,8414,8416,1,8418,8420,1,42608,42610,1]));static Mn=new k(new Uint32Array([768,879,1,1155,1159,1,1425,1469,1,1471,1473,2,1474,1476,2,1477,1479,2,1552,1562,1,1611,1631,1,1648,1750,102,1751,1756,1,1759,1764,1,1767,1768,1,1770,1773,1,1809,1840,31,1841,1866,1,1958,1968,1,2027,2035,1,2045,2070,25,2071,2073,1,2075,2083,1,2085,2087,1,2089,2093,1,2137,2139,1,2199,2207,1,2250,2273,1,2275,2306,1,2362,2364,2,2369,2376,1,2381,2385,4,2386,2391,1,2402,2403,1,2433,2492,59,2497,2500,1,2509,2530,21,2531,2558,27,2561,2562,1,2620,2625,5,2626,2631,5,2632,2635,3,2636,2637,1,2641,2672,31,2673,2677,4,2689,2690,1,2748,2753,5,2754,2757,1,2759,2760,1,2765,2786,21,2787,2810,23,2811,2815,1,2817,2876,59,2879,2881,2,2882,2884,1,2893,2901,8,2902,2914,12,2915,2946,31,3008,3021,13,3072,3076,4,3132,3134,2,3135,3136,1,3142,3144,1,3146,3149,1,3157,3158,1,3170,3171,1,3201,3260,59,3263,3270,7,3276,3277,1,3298,3299,1,3328,3329,1,3387,3388,1,3393,3396,1,3405,3426,21,3427,3457,30,3530,3538,8,3539,3540,1,3542,3633,91,3636,3642,1,3655,3662,1,3761,3764,3,3765,3772,1,3784,3790,1,3864,3865,1,3893,3897,2,3953,3966,1,3968,3972,1,3974,3975,1,3981,3991,1,3993,4028,1,4038,4141,103,4142,4144,1,4146,4151,1,4153,4154,1,4157,4158,1,4184,4185,1,4190,4192,1,4209,4212,1,4226,4229,3,4230,4237,7,4253,4957,704,4958,4959,1,5906,5908,1,5938,5939,1,5970,5971,1,6002,6003,1,6068,6069,1,6071,6077,1,6086,6089,3,6090,6099,1,6109,6155,46,6156,6157,1,6159,6277,118,6278,6313,35,6432,6434,1,6439,6440,1,6450,6457,7,6458,6459,1,6679,6680,1,6683,6742,59,6744,6750,1,6752,6754,2,6757,6764,1,6771,6780,1,6783,6832,49,6833,6845,1,6847,6862,1,6912,6915,1,6964,6966,2,6967,6970,1,6972,6978,6,7019,7027,1,7040,7041,1,7074,7077,1,7080,7081,1,7083,7085,1,7142,7144,2,7145,7149,4,7151,7153,1,7212,7219,1,7222,7223,1,7376,7378,1,7380,7392,1,7394,7400,1,7405,7412,7,7416,7417,1,7616,7679,1,8400,8412,1,8417,8421,4,8422,8432,1,11503,11505,1,11647,11744,97,11745,11775,1,12330,12333,1,12441,12442,1,42607,42612,5,42613,42621,1,42654,42655,1,42736,42737,1,43010,43014,4,43019,43045,26,43046,43052,6,43204,43205,1,43232,43249,1,43263,43302,39,43303,43309,1,43335,43345,1,43392,43394,1,43443,43446,3,43447,43449,1,43452,43453,1,43493,43561,68,43562,43566,1,43569,43570,1,43573,43574,1,43587,43596,9,43644,43696,52,43698,43700,1,43703,43704,1,43710,43711,1,43713,43756,43,43757,43766,9,44005,44008,3,44013,64286,20273,65024,65039,1,65056,65071,1,66045,66272,227,66422,66426,1,68097,68099,1,68101,68102,1,68108,68111,1,68152,68154,1,68159,68325,166,68326,68900,574,68901,68903,1,68969,68973,1,69291,69292,1,69372,69375,1,69446,69456,1,69506,69509,1,69633,69688,55,69689,69702,1,69744,69747,3,69748,69759,11,69760,69761,1,69811,69814,1,69817,69818,1,69826,69888,62,69889,69890,1,69927,69931,1,69933,69940,1,70003,70016,13,70017,70070,53,70071,70078,1,70089,70092,1,70095,70191,96,70192,70193,1,70196,70198,2,70199,70206,7,70209,70367,158,70371,70378,1,70400,70401,1,70459,70460,1,70464,70502,38,70503,70508,1,70512,70516,1,70587,70592,1,70606,70610,2,70625,70626,1,70712,70719,1,70722,70724,1,70726,70750,24,70835,70840,1,70842,70847,5,70848,70850,2,70851,71090,239,71091,71093,1,71100,71101,1,71103,71104,1,71132,71133,1,71219,71226,1,71229,71231,2,71232,71339,107,71341,71344,3,71345,71349,1,71351,71453,102,71455,71458,3,71459,71461,1,71463,71467,1,71727,71735,1,71737,71738,1,71995,71996,1,71998,72003,5,72148,72151,1,72154,72155,1,72160,72193,33,72194,72202,1,72243,72248,1,72251,72254,1,72263,72273,10,72274,72278,1,72281,72283,1,72330,72342,1,72344,72345,1,72752,72758,1,72760,72765,1,72767,72850,83,72851,72871,1,72874,72880,1,72882,72883,1,72885,72886,1,73009,73014,1,73018,73020,2,73021,73023,2,73024,73029,1,73031,73104,73,73105,73109,4,73111,73459,348,73460,73472,12,73473,73526,53,73527,73530,1,73536,73538,2,73562,78912,5350,78919,78933,1,90398,90409,1,90413,90415,1,92912,92916,1,92976,92982,1,94031,94095,64,94096,94098,1,94180,113821,19641,113822,118528,4706,118529,118573,1,118576,118598,1,119143,119145,1,119163,119170,1,119173,119179,1,119210,119213,1,119362,119364,1,121344,121398,1,121403,121452,1,121461,121476,15,121499,121503,1,121505,121519,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,123023,123184,161,123185,123190,1,123566,123628,62,123629,123631,1,124140,124143,1,124398,124399,1,125136,125142,1,125252,125258,1,917760,917999,1]));static foldMn=new k(new Uint32Array([921,953,32,8126,8126,1]));static N=new k(new Uint32Array([48,57,1,178,179,1,185,188,3,189,190,1,1632,1641,1,1776,1785,1,1984,1993,1,2406,2415,1,2534,2543,1,2548,2553,1,2662,2671,1,2790,2799,1,2918,2927,1,2930,2935,1,3046,3058,1,3174,3183,1,3192,3198,1,3302,3311,1,3416,3422,1,3430,3448,1,3558,3567,1,3664,3673,1,3792,3801,1,3872,3891,1,4160,4169,1,4240,4249,1,4969,4988,1,5870,5872,1,6112,6121,1,6128,6137,1,6160,6169,1,6470,6479,1,6608,6618,1,6784,6793,1,6800,6809,1,6992,7001,1,7088,7097,1,7232,7241,1,7248,7257,1,8304,8308,4,8309,8313,1,8320,8329,1,8528,8578,1,8581,8585,1,9312,9371,1,9450,9471,1,10102,10131,1,11517,12295,778,12321,12329,1,12344,12346,1,12690,12693,1,12832,12841,1,12872,12879,1,12881,12895,1,12928,12937,1,12977,12991,1,42528,42537,1,42726,42735,1,43056,43061,1,43216,43225,1,43264,43273,1,43472,43481,1,43504,43513,1,43600,43609,1,44016,44025,1,65296,65305,1,65799,65843,1,65856,65912,1,65930,65931,1,66273,66299,1,66336,66339,1,66369,66378,9,66513,66517,1,66720,66729,1,67672,67679,1,67705,67711,1,67751,67759,1,67835,67839,1,67862,67867,1,68028,68029,1,68032,68047,1,68050,68095,1,68160,68168,1,68221,68222,1,68253,68255,1,68331,68335,1,68440,68447,1,68472,68479,1,68521,68527,1,68858,68863,1,68912,68921,1,68928,68937,1,69216,69246,1,69405,69414,1,69457,69460,1,69573,69579,1,69714,69743,1,69872,69881,1,69942,69951,1,70096,70105,1,70113,70132,1,70384,70393,1,70736,70745,1,70864,70873,1,71248,71257,1,71360,71369,1,71376,71395,1,71472,71483,1,71904,71922,1,72016,72025,1,72688,72697,1,72784,72812,1,73040,73049,1,73120,73129,1,73552,73561,1,73664,73684,1,74752,74862,1,90416,90425,1,92768,92777,1,92864,92873,1,93008,93017,1,93019,93025,1,93552,93561,1,93824,93846,1,118e3,118009,1,119488,119507,1,119520,119539,1,119648,119672,1,120782,120831,1,123200,123209,1,123632,123641,1,124144,124153,1,124401,124410,1,125127,125135,1,125264,125273,1,126065,126123,1,126125,126127,1,126129,126132,1,126209,126253,1,126255,126269,1,127232,127244,1,130032,130041,1]));static Nd=new k(new Uint32Array([48,57,1,1632,1641,1,1776,1785,1,1984,1993,1,2406,2415,1,2534,2543,1,2662,2671,1,2790,2799,1,2918,2927,1,3046,3055,1,3174,3183,1,3302,3311,1,3430,3439,1,3558,3567,1,3664,3673,1,3792,3801,1,3872,3881,1,4160,4169,1,4240,4249,1,6112,6121,1,6160,6169,1,6470,6479,1,6608,6617,1,6784,6793,1,6800,6809,1,6992,7001,1,7088,7097,1,7232,7241,1,7248,7257,1,42528,42537,1,43216,43225,1,43264,43273,1,43472,43481,1,43504,43513,1,43600,43609,1,44016,44025,1,65296,65305,1,66720,66729,1,68912,68921,1,68928,68937,1,69734,69743,1,69872,69881,1,69942,69951,1,70096,70105,1,70384,70393,1,70736,70745,1,70864,70873,1,71248,71257,1,71360,71369,1,71376,71395,1,71472,71481,1,71904,71913,1,72016,72025,1,72688,72697,1,72784,72793,1,73040,73049,1,73120,73129,1,73552,73561,1,90416,90425,1,92768,92777,1,92864,92873,1,93008,93017,1,93552,93561,1,118e3,118009,1,120782,120831,1,123200,123209,1,123632,123641,1,124144,124153,1,124401,124410,1,125264,125273,1,130032,130041,1]));static Nl=new k(new Uint32Array([5870,5872,1,8544,8578,1,8581,8584,1,12295,12321,26,12322,12329,1,12344,12346,1,42726,42735,1,65856,65908,1,66369,66378,9,66513,66517,1,74752,74862,1]));static No=new k(new Uint32Array([178,179,1,185,188,3,189,190,1,2548,2553,1,2930,2935,1,3056,3058,1,3192,3198,1,3416,3422,1,3440,3448,1,3882,3891,1,4969,4988,1,6128,6137,1,6618,8304,1686,8308,8313,1,8320,8329,1,8528,8543,1,8585,9312,727,9313,9371,1,9450,9471,1,10102,10131,1,11517,12690,1173,12691,12693,1,12832,12841,1,12872,12879,1,12881,12895,1,12928,12937,1,12977,12991,1,43056,43061,1,65799,65843,1,65909,65912,1,65930,65931,1,66273,66299,1,66336,66339,1,67672,67679,1,67705,67711,1,67751,67759,1,67835,67839,1,67862,67867,1,68028,68029,1,68032,68047,1,68050,68095,1,68160,68168,1,68221,68222,1,68253,68255,1,68331,68335,1,68440,68447,1,68472,68479,1,68521,68527,1,68858,68863,1,69216,69246,1,69405,69414,1,69457,69460,1,69573,69579,1,69714,69733,1,70113,70132,1,71482,71483,1,71914,71922,1,72794,72812,1,73664,73684,1,93019,93025,1,93824,93846,1,119488,119507,1,119520,119539,1,119648,119672,1,125127,125135,1,126065,126123,1,126125,126127,1,126129,126132,1,126209,126253,1,126255,126269,1,127232,127244,1]));static P=new k(new Uint32Array([33,35,1,37,42,1,44,47,1,58,59,1,63,64,1,91,93,1,95,123,28,125,161,36,167,171,4,182,183,1,187,191,4,894,903,9,1370,1375,1,1417,1418,1,1470,1472,2,1475,1478,3,1523,1524,1,1545,1546,1,1548,1549,1,1563,1565,2,1566,1567,1,1642,1645,1,1748,1792,44,1793,1805,1,2039,2041,1,2096,2110,1,2142,2404,262,2405,2416,11,2557,2678,121,2800,3191,391,3204,3572,368,3663,3674,11,3675,3844,169,3845,3858,1,3860,3898,38,3899,3901,1,3973,4048,75,4049,4052,1,4057,4058,1,4170,4175,1,4347,4960,613,4961,4968,1,5120,5742,622,5787,5788,1,5867,5869,1,5941,5942,1,6100,6102,1,6104,6106,1,6144,6154,1,6468,6469,1,6686,6687,1,6816,6822,1,6824,6829,1,6990,6991,1,7002,7008,1,7037,7039,1,7164,7167,1,7227,7231,1,7294,7295,1,7360,7367,1,7379,8208,829,8209,8231,1,8240,8259,1,8261,8273,1,8275,8286,1,8317,8318,1,8333,8334,1,8968,8971,1,9001,9002,1,10088,10101,1,10181,10182,1,10214,10223,1,10627,10648,1,10712,10715,1,10748,10749,1,11513,11516,1,11518,11519,1,11632,11776,144,11777,11822,1,11824,11855,1,11858,11869,1,12289,12291,1,12296,12305,1,12308,12319,1,12336,12349,13,12448,12539,91,42238,42239,1,42509,42511,1,42611,42622,11,42738,42743,1,43124,43127,1,43214,43215,1,43256,43258,1,43260,43310,50,43311,43359,48,43457,43469,1,43486,43487,1,43612,43615,1,43742,43743,1,43760,43761,1,44011,64830,20819,64831,65040,209,65041,65049,1,65072,65106,1,65108,65121,1,65123,65128,5,65130,65131,1,65281,65283,1,65285,65290,1,65292,65295,1,65306,65307,1,65311,65312,1,65339,65341,1,65343,65371,28,65373,65375,2,65376,65381,1,65792,65794,1,66463,66512,49,66927,67671,744,67871,67903,32,68176,68184,1,68223,68336,113,68337,68342,1,68409,68415,1,68505,68508,1,68974,69293,319,69461,69465,1,69510,69513,1,69703,69709,1,69819,69820,1,69822,69825,1,69952,69955,1,70004,70005,1,70085,70088,1,70093,70107,14,70109,70111,1,70200,70205,1,70313,70612,299,70613,70615,2,70616,70731,115,70732,70735,1,70746,70747,1,70749,70854,105,71105,71127,1,71233,71235,1,71264,71276,1,71353,71484,131,71485,71486,1,71739,72004,265,72005,72006,1,72162,72255,93,72256,72262,1,72346,72348,1,72350,72354,1,72448,72457,1,72673,72769,96,72770,72773,1,72816,72817,1,73463,73464,1,73539,73551,1,73727,74864,1137,74865,74868,1,77809,77810,1,92782,92783,1,92917,92983,66,92984,92987,1,92996,93549,553,93550,93551,1,93847,93850,1,94178,113823,19645,121479,121483,1,124415,125278,863,125279,125279,1]));static Pc=new k(new Uint32Array([95,8255,8160,8256,8276,20,65075,65076,1,65101,65103,1,65343,65343,1]));static Pd=new k(new Uint32Array([45,1418,1373,1470,5120,3650,6150,8208,2058,8209,8213,1,11799,11802,3,11834,11835,1,11840,11869,29,12316,12336,20,12448,65073,52625,65074,65112,38,65123,65293,170,68974,69293,319]));static Pe=new k(new Uint32Array([41,93,52,125,3899,3774,3901,5788,1887,8262,8318,56,8334,8969,635,8971,9002,31,10089,10101,2,10182,10215,33,10217,10223,2,10628,10648,2,10713,10715,2,10749,11811,1062,11813,11817,2,11862,11868,2,12297,12305,2,12309,12315,2,12318,12319,1,64830,65048,218,65078,65092,2,65096,65114,18,65116,65118,2,65289,65341,52,65373,65379,3]));static Pf=new k(new Uint32Array([187,8217,8030,8221,8250,29,11779,11781,2,11786,11789,3,11805,11809,4]));static Pi=new k(new Uint32Array([171,8216,8045,8219,8220,1,8223,8249,26,11778,11780,2,11785,11788,3,11804,11808,4]));static Po=new k(new Uint32Array([33,35,1,37,39,1,42,46,2,47,58,11,59,63,4,64,92,28,161,167,6,182,183,1,191,894,703,903,1370,467,1371,1375,1,1417,1472,55,1475,1478,3,1523,1524,1,1545,1546,1,1548,1549,1,1563,1565,2,1566,1567,1,1642,1645,1,1748,1792,44,1793,1805,1,2039,2041,1,2096,2110,1,2142,2404,262,2405,2416,11,2557,2678,121,2800,3191,391,3204,3572,368,3663,3674,11,3675,3844,169,3845,3858,1,3860,3973,113,4048,4052,1,4057,4058,1,4170,4175,1,4347,4960,613,4961,4968,1,5742,5867,125,5868,5869,1,5941,5942,1,6100,6102,1,6104,6106,1,6144,6149,1,6151,6154,1,6468,6469,1,6686,6687,1,6816,6822,1,6824,6829,1,6990,6991,1,7002,7008,1,7037,7039,1,7164,7167,1,7227,7231,1,7294,7295,1,7360,7367,1,7379,8214,835,8215,8224,9,8225,8231,1,8240,8248,1,8251,8254,1,8257,8259,1,8263,8273,1,8275,8277,2,8278,8286,1,11513,11516,1,11518,11519,1,11632,11776,144,11777,11782,5,11783,11784,1,11787,11790,3,11791,11798,1,11800,11801,1,11803,11806,3,11807,11818,11,11819,11822,1,11824,11833,1,11836,11839,1,11841,11843,2,11844,11855,1,11858,11860,1,12289,12291,1,12349,12539,190,42238,42239,1,42509,42511,1,42611,42622,11,42738,42743,1,43124,43127,1,43214,43215,1,43256,43258,1,43260,43310,50,43311,43359,48,43457,43469,1,43486,43487,1,43612,43615,1,43742,43743,1,43760,43761,1,44011,65040,21029,65041,65046,1,65049,65072,23,65093,65094,1,65097,65100,1,65104,65106,1,65108,65111,1,65119,65121,1,65128,65130,2,65131,65281,150,65282,65283,1,65285,65287,1,65290,65294,2,65295,65306,11,65307,65311,4,65312,65340,28,65377,65380,3,65381,65792,411,65793,65794,1,66463,66512,49,66927,67671,744,67871,67903,32,68176,68184,1,68223,68336,113,68337,68342,1,68409,68415,1,68505,68508,1,69461,69465,1,69510,69513,1,69703,69709,1,69819,69820,1,69822,69825,1,69952,69955,1,70004,70005,1,70085,70088,1,70093,70107,14,70109,70111,1,70200,70205,1,70313,70612,299,70613,70615,2,70616,70731,115,70732,70735,1,70746,70747,1,70749,70854,105,71105,71127,1,71233,71235,1,71264,71276,1,71353,71484,131,71485,71486,1,71739,72004,265,72005,72006,1,72162,72255,93,72256,72262,1,72346,72348,1,72350,72354,1,72448,72457,1,72673,72769,96,72770,72773,1,72816,72817,1,73463,73464,1,73539,73551,1,73727,74864,1137,74865,74868,1,77809,77810,1,92782,92783,1,92917,92983,66,92984,92987,1,92996,93549,553,93550,93551,1,93847,93850,1,94178,113823,19645,121479,121483,1,124415,125278,863,125279,125279,1]));static Ps=new k(new Uint32Array([40,91,51,123,3898,3775,3900,5787,1887,8218,8222,4,8261,8317,56,8333,8968,635,8970,9001,31,10088,10100,2,10181,10214,33,10216,10222,2,10627,10647,2,10712,10714,2,10748,11810,1062,11812,11816,2,11842,11861,19,11863,11867,2,12296,12304,2,12308,12314,2,12317,64831,52514,65047,65077,30,65079,65091,2,65095,65113,18,65115,65117,2,65288,65339,51,65371,65375,4,65378,65378,1]));static S=new k(new Uint32Array([36,43,7,60,62,1,94,96,2,124,126,2,162,166,1,168,169,1,172,174,2,175,177,1,180,184,4,215,247,32,706,709,1,722,735,1,741,747,1,749,751,2,752,767,1,885,900,15,901,1014,113,1154,1421,267,1422,1423,1,1542,1544,1,1547,1550,3,1551,1758,207,1769,1789,20,1790,2038,248,2046,2047,1,2184,2546,362,2547,2554,7,2555,2801,246,2928,3059,131,3060,3066,1,3199,3407,208,3449,3647,198,3841,3843,1,3859,3861,2,3862,3863,1,3866,3871,1,3892,3896,2,4030,4037,1,4039,4044,1,4046,4047,1,4053,4056,1,4254,4255,1,5008,5017,1,5741,6107,366,6464,6622,158,6623,6655,1,7009,7018,1,7028,7036,1,8125,8127,2,8128,8129,1,8141,8143,1,8157,8159,1,8173,8175,1,8189,8190,1,8260,8274,14,8314,8316,1,8330,8332,1,8352,8384,1,8448,8449,1,8451,8454,1,8456,8457,1,8468,8470,2,8471,8472,1,8478,8483,1,8485,8489,2,8494,8506,12,8507,8512,5,8513,8516,1,8522,8525,1,8527,8586,59,8587,8592,5,8593,8967,1,8972,9e3,1,9003,9257,1,9280,9290,1,9372,9449,1,9472,10087,1,10132,10180,1,10183,10213,1,10224,10626,1,10649,10711,1,10716,10747,1,10750,11123,1,11126,11157,1,11159,11263,1,11493,11498,1,11856,11857,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12292,12306,14,12307,12320,13,12342,12343,1,12350,12351,1,12443,12444,1,12688,12689,1,12694,12703,1,12736,12773,1,12783,12800,17,12801,12830,1,12842,12871,1,12880,12896,16,12897,12927,1,12938,12976,1,12992,13311,1,19904,19967,1,42128,42182,1,42752,42774,1,42784,42785,1,42889,42890,1,43048,43051,1,43062,43065,1,43639,43641,1,43867,43882,15,43883,64297,20414,64434,64450,1,64832,64847,1,64975,65020,45,65021,65023,1,65122,65124,2,65125,65126,1,65129,65284,155,65291,65308,17,65309,65310,1,65342,65344,2,65372,65374,2,65504,65510,1,65512,65518,1,65532,65533,1,65847,65855,1,65913,65929,1,65932,65934,1,65936,65948,1,65952,66e3,48,66001,66044,1,67703,67704,1,68296,69006,710,69007,71487,2480,73685,73713,1,92988,92991,1,92997,113820,20823,117760,117999,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119140,1,119146,119148,1,119171,119172,1,119180,119209,1,119214,119274,1,119296,119361,1,119365,119552,187,119553,119638,1,120513,120539,26,120571,120597,26,120629,120655,26,120687,120713,26,120745,120771,26,120832,121343,1,121399,121402,1,121453,121460,1,121462,121475,1,121477,121478,1,123215,123647,432,126124,126128,4,126254,126704,450,126705,126976,271,126977,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127245,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130031,1]));static Sc=new k(new Uint32Array([36,162,126,163,165,1,1423,1547,124,2046,2047,1,2546,2547,1,2555,2801,246,3065,3647,582,6107,8352,2245,8353,8384,1,43064,65020,21956,65129,65284,155,65504,65505,1,65509,65510,1,73693,73696,1,123647,126128,2481]));static Sk=new k(new Uint32Array([94,96,2,168,175,7,180,184,4,706,709,1,722,735,1,741,747,1,749,751,2,752,767,1,885,900,15,901,2184,1283,8125,8127,2,8128,8129,1,8141,8143,1,8157,8159,1,8173,8175,1,8189,8190,1,12443,12444,1,42752,42774,1,42784,42785,1,42889,42890,1,43867,43882,15,43883,64434,20551,64435,64450,1,65342,65344,2,65507,127995,62488,127996,127999,1]));static Sm=new k(new Uint32Array([43,60,17,61,62,1,124,126,2,172,177,5,215,247,32,1014,1542,528,1543,1544,1,8260,8274,14,8314,8316,1,8330,8332,1,8472,8512,40,8513,8516,1,8523,8592,69,8593,8596,1,8602,8603,1,8608,8614,3,8622,8654,32,8655,8658,3,8660,8692,32,8693,8959,1,8992,8993,1,9084,9115,31,9116,9139,1,9180,9185,1,9655,9665,10,9720,9727,1,9839,10176,337,10177,10180,1,10183,10213,1,10224,10239,1,10496,10626,1,10649,10711,1,10716,10747,1,10750,11007,1,11056,11076,1,11079,11084,1,64297,65122,825,65124,65126,1,65291,65308,17,65309,65310,1,65372,65374,2,65506,65513,7,65514,65516,1,69006,69007,1,120513,120539,26,120571,120597,26,120629,120655,26,120687,120713,26,120745,120771,26,126704,126705,1]));static So=new k(new Uint32Array([166,169,3,174,176,2,1154,1421,267,1422,1550,128,1551,1758,207,1769,1789,20,1790,2038,248,2554,2928,374,3059,3064,1,3066,3199,133,3407,3449,42,3841,3843,1,3859,3861,2,3862,3863,1,3866,3871,1,3892,3896,2,4030,4037,1,4039,4044,1,4046,4047,1,4053,4056,1,4254,4255,1,5008,5017,1,5741,6464,723,6622,6655,1,7009,7018,1,7028,7036,1,8448,8449,1,8451,8454,1,8456,8457,1,8468,8470,2,8471,8478,7,8479,8483,1,8485,8489,2,8494,8506,12,8507,8522,15,8524,8525,1,8527,8586,59,8587,8597,10,8598,8601,1,8604,8607,1,8609,8610,1,8612,8613,1,8615,8621,1,8623,8653,1,8656,8657,1,8659,8661,2,8662,8691,1,8960,8967,1,8972,8991,1,8994,9e3,1,9003,9083,1,9085,9114,1,9140,9179,1,9186,9257,1,9280,9290,1,9372,9449,1,9472,9654,1,9656,9664,1,9666,9719,1,9728,9838,1,9840,10087,1,10132,10175,1,10240,10495,1,11008,11055,1,11077,11078,1,11085,11123,1,11126,11157,1,11159,11263,1,11493,11498,1,11856,11857,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12292,12306,14,12307,12320,13,12342,12343,1,12350,12351,1,12688,12689,1,12694,12703,1,12736,12773,1,12783,12800,17,12801,12830,1,12842,12871,1,12880,12896,16,12897,12927,1,12938,12976,1,12992,13311,1,19904,19967,1,42128,42182,1,43048,43051,1,43062,43063,1,43065,43639,574,43640,43641,1,64832,64847,1,64975,65021,46,65022,65023,1,65508,65512,4,65517,65518,1,65532,65533,1,65847,65855,1,65913,65929,1,65932,65934,1,65936,65948,1,65952,66e3,48,66001,66044,1,67703,67704,1,68296,71487,3191,73685,73692,1,73697,73713,1,92988,92991,1,92997,113820,20823,117760,117999,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119140,1,119146,119148,1,119171,119172,1,119180,119209,1,119214,119274,1,119296,119361,1,119365,119552,187,119553,119638,1,120832,121343,1,121399,121402,1,121453,121460,1,121462,121475,1,121477,121478,1,123215,126124,2909,126254,126976,722,126977,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127245,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,127994,1,128e3,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130031,1]));static Z=new k(new Uint32Array([32,160,128,5760,8192,2432,8193,8202,1,8232,8233,1,8239,8287,48,12288,12288,1]));static Zl=new k(new Uint32Array([8232,8232,1]));static Zp=new k(new Uint32Array([8233,8233,1]));static Zs=new k(new Uint32Array([32,160,128,5760,8192,2432,8193,8202,1,8239,8287,48,12288,12288,1]));static Adlam=new k(new Uint32Array([125184,125259,1,125264,125273,1,125278,125279,1]));static Ahom=new k(new Uint32Array([71424,71450,1,71453,71467,1,71472,71494,1]));static Anatolian_Hieroglyphs=new k(new Uint32Array([82944,83526,1]));static Arabic=new k(new Uint32Array([1536,1540,1,1542,1547,1,1549,1562,1,1564,1566,1,1568,1599,1,1601,1610,1,1622,1647,1,1649,1756,1,1758,1791,1,1872,1919,1,2160,2190,1,2192,2193,1,2199,2273,1,2275,2303,1,64336,64450,1,64467,64829,1,64832,64911,1,64914,64967,1,64975,65008,33,65009,65023,1,65136,65140,1,65142,65276,1,69216,69246,1,69314,69316,1,69372,69375,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,126704,126705,1]));static Armenian=new k(new Uint32Array([1329,1366,1,1369,1418,1,1421,1423,1,64275,64279,1]));static Avestan=new k(new Uint32Array([68352,68405,1,68409,68415,1]));static Balinese=new k(new Uint32Array([6912,6988,1,6990,7039,1]));static Bamum=new k(new Uint32Array([42656,42743,1,92160,92728,1]));static Bassa_Vah=new k(new Uint32Array([92880,92909,1,92912,92917,1]));static Batak=new k(new Uint32Array([7104,7155,1,7164,7167,1]));static Bengali=new k(new Uint32Array([2432,2435,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2492,2500,1,2503,2504,1,2507,2510,1,2519,2524,5,2525,2527,2,2528,2531,1,2534,2558,1]));static Bhaiksuki=new k(new Uint32Array([72704,72712,1,72714,72758,1,72760,72773,1,72784,72812,1]));static Bopomofo=new k(new Uint32Array([746,747,1,12549,12591,1,12704,12735,1]));static Brahmi=new k(new Uint32Array([69632,69709,1,69714,69749,1,69759,69759,1]));static Braille=new k(new Uint32Array([10240,10495,1]));static Buginese=new k(new Uint32Array([6656,6683,1,6686,6687,1]));static Buhid=new k(new Uint32Array([5952,5971,1]));static Canadian_Aboriginal=new k(new Uint32Array([5120,5759,1,6320,6389,1,72368,72383,1]));static Carian=new k(new Uint32Array([66208,66256,1]));static Caucasian_Albanian=new k(new Uint32Array([66864,66915,1,66927,66927,1]));static Chakma=new k(new Uint32Array([69888,69940,1,69942,69959,1]));static Cham=new k(new Uint32Array([43520,43574,1,43584,43597,1,43600,43609,1,43612,43615,1]));static Cherokee=new k(new Uint32Array([5024,5109,1,5112,5117,1,43888,43967,1]));static Chorasmian=new k(new Uint32Array([69552,69579,1]));static Common=new k(new Uint32Array([0,64,1,91,96,1,123,169,1,171,185,1,187,191,1,215,247,32,697,735,1,741,745,1,748,767,1,884,894,10,901,903,2,1541,1548,7,1563,1567,4,1600,1757,157,2274,2404,130,2405,3647,1242,4053,4056,1,4347,5867,1520,5868,5869,1,5941,5942,1,6146,6147,1,6149,7379,1230,7393,7401,8,7402,7404,1,7406,7411,1,7413,7415,1,7418,8192,774,8193,8203,1,8206,8292,1,8294,8304,1,8308,8318,1,8320,8334,1,8352,8384,1,8448,8485,1,8487,8489,1,8492,8497,1,8499,8525,1,8527,8543,1,8585,8587,1,8592,9257,1,9280,9290,1,9312,10239,1,10496,11123,1,11126,11157,1,11159,11263,1,11776,11869,1,12272,12292,1,12294,12296,2,12297,12320,1,12336,12343,1,12348,12351,1,12443,12444,1,12448,12539,91,12540,12688,148,12689,12703,1,12736,12773,1,12783,12832,49,12833,12895,1,12927,13007,1,13055,13144,89,13145,13311,1,19904,19967,1,42752,42785,1,42888,42890,1,43056,43065,1,43310,43471,161,43867,43882,15,43883,64830,20947,64831,65040,209,65041,65049,1,65072,65106,1,65108,65126,1,65128,65131,1,65279,65281,2,65282,65312,1,65339,65344,1,65371,65381,1,65392,65438,46,65439,65504,65,65505,65510,1,65512,65518,1,65529,65533,1,65792,65794,1,65799,65843,1,65847,65855,1,65936,65948,1,66e3,66044,1,66273,66299,1,113824,113827,1,117760,118009,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119142,1,119146,119162,1,119171,119172,1,119180,119209,1,119214,119274,1,119488,119507,1,119520,119539,1,119552,119638,1,119648,119672,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120779,1,120782,120831,1,126065,126132,1,126209,126269,1,126976,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127232,127405,1,127462,127487,1,127489,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130041,1,917505,917536,31,917537,917631,1]));static foldCommon=new k(new Uint32Array([924,956,32]));static Coptic=new k(new Uint32Array([994,1007,1,11392,11507,1,11513,11519,1]));static Cuneiform=new k(new Uint32Array([73728,74649,1,74752,74862,1,74864,74868,1,74880,75075,1]));static Cypriot=new k(new Uint32Array([67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3]));static Cypro_Minoan=new k(new Uint32Array([77712,77810,1]));static Cyrillic=new k(new Uint32Array([1024,1156,1,1159,1327,1,7296,7306,1,7467,7544,77,11744,11775,1,42560,42655,1,65070,65071,1,122928,122989,1,123023,123023,1]));static Deseret=new k(new Uint32Array([66560,66639,1]));static Devanagari=new k(new Uint32Array([2304,2384,1,2389,2403,1,2406,2431,1,43232,43263,1,72448,72457,1]));static Dives_Akuru=new k(new Uint32Array([71936,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71989,1,71991,71992,1,71995,72006,1,72016,72025,1]));static Dogra=new k(new Uint32Array([71680,71739,1]));static Duployan=new k(new Uint32Array([113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,113820,113823,1]));static Egyptian_Hieroglyphs=new k(new Uint32Array([77824,78933,1,78944,82938,1]));static Elbasan=new k(new Uint32Array([66816,66855,1]));static Elymaic=new k(new Uint32Array([69600,69622,1]));static Ethiopic=new k(new Uint32Array([4608,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4957,4988,1,4992,5017,1,11648,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,124896,124902,1,124904,124907,1,124909,124910,1,124912,124926,1]));static Garay=new k(new Uint32Array([68928,68965,1,68969,68997,1,69006,69007,1]));static Georgian=new k(new Uint32Array([4256,4293,1,4295,4301,6,4304,4346,1,4348,4351,1,7312,7354,1,7357,7359,1,11520,11557,1,11559,11565,6]));static Glagolitic=new k(new Uint32Array([11264,11359,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1]));static Gothic=new k(new Uint32Array([66352,66378,1]));static Grantha=new k(new Uint32Array([70400,70403,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70460,70468,1,70471,70472,1,70475,70477,1,70480,70487,7,70493,70499,1,70502,70508,1,70512,70516,1]));static Greek=new k(new Uint32Array([880,883,1,885,887,1,890,893,1,895,900,5,902,904,2,905,906,1,908,910,2,911,929,1,931,993,1,1008,1023,1,7462,7466,1,7517,7521,1,7526,7530,1,7615,7936,321,7937,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8132,1,8134,8147,1,8150,8155,1,8157,8175,1,8178,8180,1,8182,8190,1,8486,43877,35391,65856,65934,1,65952,119296,53344,119297,119365,1]));static foldGreek=new k(new Uint32Array([181,837,656]));static Gujarati=new k(new Uint32Array([2689,2691,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2748,2757,1,2759,2761,1,2763,2765,1,2768,2784,16,2785,2787,1,2790,2801,1,2809,2815,1]));static Gunjala_Gondi=new k(new Uint32Array([73056,73061,1,73063,73064,1,73066,73102,1,73104,73105,1,73107,73112,1,73120,73129,1]));static Gurmukhi=new k(new Uint32Array([2561,2563,1,2565,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2649,8,2650,2652,1,2654,2662,8,2663,2678,1]));static Gurung_Khema=new k(new Uint32Array([90368,90425,1]));static Han=new k(new Uint32Array([11904,11929,1,11931,12019,1,12032,12245,1,12293,12295,2,12321,12329,1,12344,12347,1,13312,19903,1,19968,40959,1,63744,64109,1,64112,64217,1,94178,94179,1,94192,94193,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static Hangul=new k(new Uint32Array([4352,4607,1,12334,12335,1,12593,12686,1,12800,12830,1,12896,12926,1,43360,43388,1,44032,55203,1,55216,55238,1,55243,55291,1,65440,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1]));static Hanifi_Rohingya=new k(new Uint32Array([68864,68903,1,68912,68921,1]));static Hanunoo=new k(new Uint32Array([5920,5940,1]));static Hatran=new k(new Uint32Array([67808,67826,1,67828,67829,1,67835,67839,1]));static Hebrew=new k(new Uint32Array([1425,1479,1,1488,1514,1,1519,1524,1,64285,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64335,1]));static Hiragana=new k(new Uint32Array([12353,12438,1,12445,12447,1,110593,110879,1,110898,110928,30,110929,110930,1,127488,127488,1]));static Imperial_Aramaic=new k(new Uint32Array([67648,67669,1,67671,67679,1]));static Inherited=new k(new Uint32Array([768,879,1,1157,1158,1,1611,1621,1,1648,2385,737,2386,2388,1,6832,6862,1,7376,7378,1,7380,7392,1,7394,7400,1,7405,7412,7,7416,7417,1,7616,7679,1,8204,8205,1,8400,8432,1,12330,12333,1,12441,12442,1,65024,65039,1,65056,65069,1,66045,66272,227,70459,118528,48069,118529,118573,1,118576,118598,1,119143,119145,1,119163,119170,1,119173,119179,1,119210,119213,1,917760,917999,1]));static foldInherited=new k(new Uint32Array([921,953,32,8126,8126,1]));static Inscriptional_Pahlavi=new k(new Uint32Array([68448,68466,1,68472,68479,1]));static Inscriptional_Parthian=new k(new Uint32Array([68416,68437,1,68440,68447,1]));static Javanese=new k(new Uint32Array([43392,43469,1,43472,43481,1,43486,43487,1]));static Kaithi=new k(new Uint32Array([69760,69826,1,69837,69837,1]));static Kannada=new k(new Uint32Array([3200,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3260,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3293,3294,1,3296,3299,1,3302,3311,1,3313,3315,1]));static Katakana=new k(new Uint32Array([12449,12538,1,12541,12543,1,12784,12799,1,13008,13054,1,13056,13143,1,65382,65391,1,65393,65437,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110880,288,110881,110882,1,110933,110948,15,110949,110951,1]));static Kawi=new k(new Uint32Array([73472,73488,1,73490,73530,1,73534,73562,1]));static Kayah_Li=new k(new Uint32Array([43264,43309,1,43311,43311,1]));static Kharoshthi=new k(new Uint32Array([68096,68099,1,68101,68102,1,68108,68115,1,68117,68119,1,68121,68149,1,68152,68154,1,68159,68168,1,68176,68184,1]));static Khitan_Small_Script=new k(new Uint32Array([94180,101120,6940,101121,101589,1,101631,101631,1]));static Khmer=new k(new Uint32Array([6016,6109,1,6112,6121,1,6128,6137,1,6624,6655,1]));static Khojki=new k(new Uint32Array([70144,70161,1,70163,70209,1]));static Khudawadi=new k(new Uint32Array([70320,70378,1,70384,70393,1]));static Kirat_Rai=new k(new Uint32Array([93504,93561,1]));static Lao=new k(new Uint32Array([3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3773,1,3776,3780,1,3782,3784,2,3785,3790,1,3792,3801,1,3804,3807,1]));static Latin=new k(new Uint32Array([65,90,1,97,122,1,170,186,16,192,214,1,216,246,1,248,696,1,736,740,1,7424,7461,1,7468,7516,1,7522,7525,1,7531,7543,1,7545,7614,1,7680,7935,1,8305,8319,14,8336,8348,1,8490,8491,1,8498,8526,28,8544,8584,1,11360,11391,1,42786,42887,1,42891,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43007,1,43824,43866,1,43868,43876,1,43878,43881,1,64256,64262,1,65313,65338,1,65345,65370,1,67456,67461,1,67463,67504,1,67506,67514,1,122624,122654,1,122661,122666,1]));static Lepcha=new k(new Uint32Array([7168,7223,1,7227,7241,1,7245,7247,1]));static Limbu=new k(new Uint32Array([6400,6430,1,6432,6443,1,6448,6459,1,6464,6468,4,6469,6479,1]));static Linear_A=new k(new Uint32Array([67072,67382,1,67392,67413,1,67424,67431,1]));static Linear_B=new k(new Uint32Array([65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1]));static Lisu=new k(new Uint32Array([42192,42239,1,73648,73648,1]));static Lycian=new k(new Uint32Array([66176,66204,1]));static Lydian=new k(new Uint32Array([67872,67897,1,67903,67903,1]));static Mahajani=new k(new Uint32Array([69968,70006,1]));static Makasar=new k(new Uint32Array([73440,73464,1]));static Malayalam=new k(new Uint32Array([3328,3340,1,3342,3344,1,3346,3396,1,3398,3400,1,3402,3407,1,3412,3427,1,3430,3455,1]));static Mandaic=new k(new Uint32Array([2112,2139,1,2142,2142,1]));static Manichaean=new k(new Uint32Array([68288,68326,1,68331,68342,1]));static Marchen=new k(new Uint32Array([72816,72847,1,72850,72871,1,72873,72886,1]));static Masaram_Gondi=new k(new Uint32Array([72960,72966,1,72968,72969,1,72971,73014,1,73018,73020,2,73021,73023,2,73024,73031,1,73040,73049,1]));static Medefaidrin=new k(new Uint32Array([93760,93850,1]));static Meetei_Mayek=new k(new Uint32Array([43744,43766,1,43968,44013,1,44016,44025,1]));static Mende_Kikakui=new k(new Uint32Array([124928,125124,1,125127,125142,1]));static Meroitic_Cursive=new k(new Uint32Array([68e3,68023,1,68028,68047,1,68050,68095,1]));static Meroitic_Hieroglyphs=new k(new Uint32Array([67968,67999,1]));static Miao=new k(new Uint32Array([93952,94026,1,94031,94087,1,94095,94111,1]));static Modi=new k(new Uint32Array([71168,71236,1,71248,71257,1]));static Mongolian=new k(new Uint32Array([6144,6145,1,6148,6150,2,6151,6169,1,6176,6264,1,6272,6314,1,71264,71276,1]));static Mro=new k(new Uint32Array([92736,92766,1,92768,92777,1,92782,92783,1]));static Multani=new k(new Uint32Array([70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70313,1]));static Myanmar=new k(new Uint32Array([4096,4255,1,43488,43518,1,43616,43647,1,71376,71395,1]));static Nabataean=new k(new Uint32Array([67712,67742,1,67751,67759,1]));static Nag_Mundari=new k(new Uint32Array([124112,124153,1]));static Nandinagari=new k(new Uint32Array([72096,72103,1,72106,72151,1,72154,72164,1]));static New_Tai_Lue=new k(new Uint32Array([6528,6571,1,6576,6601,1,6608,6618,1,6622,6623,1]));static Newa=new k(new Uint32Array([70656,70747,1,70749,70753,1]));static Nko=new k(new Uint32Array([1984,2042,1,2045,2047,1]));static Nushu=new k(new Uint32Array([94177,110960,16783,110961,111355,1]));static Nyiakeng_Puachue_Hmong=new k(new Uint32Array([123136,123180,1,123184,123197,1,123200,123209,1,123214,123215,1]));static Ogham=new k(new Uint32Array([5760,5788,1]));static Ol_Chiki=new k(new Uint32Array([7248,7295,1]));static Ol_Onal=new k(new Uint32Array([124368,124410,1,124415,124415,1]));static Old_Hungarian=new k(new Uint32Array([68736,68786,1,68800,68850,1,68858,68863,1]));static Old_Italic=new k(new Uint32Array([66304,66339,1,66349,66351,1]));static Old_North_Arabian=new k(new Uint32Array([68224,68255,1]));static Old_Permic=new k(new Uint32Array([66384,66426,1]));static Old_Persian=new k(new Uint32Array([66464,66499,1,66504,66517,1]));static Old_Sogdian=new k(new Uint32Array([69376,69415,1]));static Old_South_Arabian=new k(new Uint32Array([68192,68223,1]));static Old_Turkic=new k(new Uint32Array([68608,68680,1]));static Old_Uyghur=new k(new Uint32Array([69488,69513,1]));static Oriya=new k(new Uint32Array([2817,2819,1,2821,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2876,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2908,2909,1,2911,2915,1,2918,2935,1]));static Osage=new k(new Uint32Array([66736,66771,1,66776,66811,1]));static Osmanya=new k(new Uint32Array([66688,66717,1,66720,66729,1]));static Pahawh_Hmong=new k(new Uint32Array([92928,92997,1,93008,93017,1,93019,93025,1,93027,93047,1,93053,93071,1]));static Palmyrene=new k(new Uint32Array([67680,67711,1]));static Pau_Cin_Hau=new k(new Uint32Array([72384,72440,1]));static Phags_Pa=new k(new Uint32Array([43072,43127,1]));static Phoenician=new k(new Uint32Array([67840,67867,1,67871,67871,1]));static Psalter_Pahlavi=new k(new Uint32Array([68480,68497,1,68505,68508,1,68521,68527,1]));static Rejang=new k(new Uint32Array([43312,43347,1,43359,43359,1]));static Runic=new k(new Uint32Array([5792,5866,1,5870,5880,1]));static Samaritan=new k(new Uint32Array([2048,2093,1,2096,2110,1]));static Saurashtra=new k(new Uint32Array([43136,43205,1,43214,43225,1]));static Sharada=new k(new Uint32Array([70016,70111,1]));static Shavian=new k(new Uint32Array([66640,66687,1]));static Siddham=new k(new Uint32Array([71040,71093,1,71096,71133,1]));static SignWriting=new k(new Uint32Array([120832,121483,1,121499,121503,1,121505,121519,1]));static Sinhala=new k(new Uint32Array([3457,3459,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3558,3567,1,3570,3572,1,70113,70132,1]));static Sogdian=new k(new Uint32Array([69424,69465,1]));static Sora_Sompeng=new k(new Uint32Array([69840,69864,1,69872,69881,1]));static Soyombo=new k(new Uint32Array([72272,72354,1]));static Sundanese=new k(new Uint32Array([7040,7103,1,7360,7367,1]));static Sunuwar=new k(new Uint32Array([72640,72673,1,72688,72697,1]));static Syloti_Nagri=new k(new Uint32Array([43008,43052,1]));static Syriac=new k(new Uint32Array([1792,1805,1,1807,1866,1,1869,1871,1,2144,2154,1]));static Tagalog=new k(new Uint32Array([5888,5909,1,5919,5919,1]));static Tagbanwa=new k(new Uint32Array([5984,5996,1,5998,6e3,1,6002,6003,1]));static Tai_Le=new k(new Uint32Array([6480,6509,1,6512,6516,1]));static Tai_Tham=new k(new Uint32Array([6688,6750,1,6752,6780,1,6783,6793,1,6800,6809,1,6816,6829,1]));static Tai_Viet=new k(new Uint32Array([43648,43714,1,43739,43743,1]));static Takri=new k(new Uint32Array([71296,71353,1,71360,71369,1]));static Tamil=new k(new Uint32Array([2946,2947,1,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3006,3010,1,3014,3016,1,3018,3021,1,3024,3031,7,3046,3066,1,73664,73713,1,73727,73727,1]));static Tangsa=new k(new Uint32Array([92784,92862,1,92864,92873,1]));static Tangut=new k(new Uint32Array([94176,94208,32,94209,100343,1,100352,101119,1,101632,101640,1]));static Telugu=new k(new Uint32Array([3072,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3132,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3160,3162,1,3165,3168,3,3169,3171,1,3174,3183,1,3191,3199,1]));static Thaana=new k(new Uint32Array([1920,1969,1]));static Thai=new k(new Uint32Array([3585,3642,1,3648,3675,1]));static Tibetan=new k(new Uint32Array([3840,3911,1,3913,3948,1,3953,3991,1,3993,4028,1,4030,4044,1,4046,4052,1,4057,4058,1]));static Tifinagh=new k(new Uint32Array([11568,11623,1,11631,11632,1,11647,11647,1]));static Tirhuta=new k(new Uint32Array([70784,70855,1,70864,70873,1]));static Todhri=new k(new Uint32Array([67008,67059,1]));static Toto=new k(new Uint32Array([123536,123566,1]));static Tulu_Tigalari=new k(new Uint32Array([70528,70537,1,70539,70542,3,70544,70581,1,70583,70592,1,70594,70597,3,70599,70602,1,70604,70613,1,70615,70616,1,70625,70626,1]));static Ugaritic=new k(new Uint32Array([66432,66461,1,66463,66463,1]));static Vai=new k(new Uint32Array([42240,42539,1]));static Vithkuqi=new k(new Uint32Array([66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1]));static Wancho=new k(new Uint32Array([123584,123641,1,123647,123647,1]));static Warang_Citi=new k(new Uint32Array([71840,71922,1,71935,71935,1]));static Yezidi=new k(new Uint32Array([69248,69289,1,69291,69293,1,69296,69297,1]));static Yi=new k(new Uint32Array([40960,42124,1,42128,42182,1]));static Zanabazar_Square=new k(new Uint32Array([72192,72263,1]));static CATEGORIES=new Map([["C",e.C],["Cc",e.Cc],["Cf",e.Cf],["Co",e.Co],["Cs",e.Cs],["L",e.L],["Ll",e.Ll],["Lm",e.Lm],["Lo",e.Lo],["Lt",e.Lt],["Lu",e.Lu],["M",e.M],["Mc",e.Mc],["Me",e.Me],["Mn",e.Mn],["N",e.N],["Nd",e.Nd],["Nl",e.Nl],["No",e.No],["P",e.P],["Pc",e.Pc],["Pd",e.Pd],["Pe",e.Pe],["Pf",e.Pf],["Pi",e.Pi],["Po",e.Po],["Ps",e.Ps],["S",e.S],["Sc",e.Sc],["Sk",e.Sk],["Sm",e.Sm],["So",e.So],["Z",e.Z],["Zl",e.Zl],["Zp",e.Zp],["Zs",e.Zs]]);static SCRIPTS=new Map([["Adlam",e.Adlam],["Ahom",e.Ahom],["Anatolian_Hieroglyphs",e.Anatolian_Hieroglyphs],["Arabic",e.Arabic],["Armenian",e.Armenian],["Avestan",e.Avestan],["Balinese",e.Balinese],["Bamum",e.Bamum],["Bassa_Vah",e.Bassa_Vah],["Batak",e.Batak],["Bengali",e.Bengali],["Bhaiksuki",e.Bhaiksuki],["Bopomofo",e.Bopomofo],["Brahmi",e.Brahmi],["Braille",e.Braille],["Buginese",e.Buginese],["Buhid",e.Buhid],["Canadian_Aboriginal",e.Canadian_Aboriginal],["Carian",e.Carian],["Caucasian_Albanian",e.Caucasian_Albanian],["Chakma",e.Chakma],["Cham",e.Cham],["Cherokee",e.Cherokee],["Chorasmian",e.Chorasmian],["Common",e.Common],["Coptic",e.Coptic],["Cuneiform",e.Cuneiform],["Cypriot",e.Cypriot],["Cypro_Minoan",e.Cypro_Minoan],["Cyrillic",e.Cyrillic],["Deseret",e.Deseret],["Devanagari",e.Devanagari],["Dives_Akuru",e.Dives_Akuru],["Dogra",e.Dogra],["Duployan",e.Duployan],["Egyptian_Hieroglyphs",e.Egyptian_Hieroglyphs],["Elbasan",e.Elbasan],["Elymaic",e.Elymaic],["Ethiopic",e.Ethiopic],["Garay",e.Garay],["Georgian",e.Georgian],["Glagolitic",e.Glagolitic],["Gothic",e.Gothic],["Grantha",e.Grantha],["Greek",e.Greek],["Gujarati",e.Gujarati],["Gunjala_Gondi",e.Gunjala_Gondi],["Gurmukhi",e.Gurmukhi],["Gurung_Khema",e.Gurung_Khema],["Han",e.Han],["Hangul",e.Hangul],["Hanifi_Rohingya",e.Hanifi_Rohingya],["Hanunoo",e.Hanunoo],["Hatran",e.Hatran],["Hebrew",e.Hebrew],["Hiragana",e.Hiragana],["Imperial_Aramaic",e.Imperial_Aramaic],["Inherited",e.Inherited],["Inscriptional_Pahlavi",e.Inscriptional_Pahlavi],["Inscriptional_Parthian",e.Inscriptional_Parthian],["Javanese",e.Javanese],["Kaithi",e.Kaithi],["Kannada",e.Kannada],["Katakana",e.Katakana],["Kawi",e.Kawi],["Kayah_Li",e.Kayah_Li],["Kharoshthi",e.Kharoshthi],["Khitan_Small_Script",e.Khitan_Small_Script],["Khmer",e.Khmer],["Khojki",e.Khojki],["Khudawadi",e.Khudawadi],["Kirat_Rai",e.Kirat_Rai],["Lao",e.Lao],["Latin",e.Latin],["Lepcha",e.Lepcha],["Limbu",e.Limbu],["Linear_A",e.Linear_A],["Linear_B",e.Linear_B],["Lisu",e.Lisu],["Lycian",e.Lycian],["Lydian",e.Lydian],["Mahajani",e.Mahajani],["Makasar",e.Makasar],["Malayalam",e.Malayalam],["Mandaic",e.Mandaic],["Manichaean",e.Manichaean],["Marchen",e.Marchen],["Masaram_Gondi",e.Masaram_Gondi],["Medefaidrin",e.Medefaidrin],["Meetei_Mayek",e.Meetei_Mayek],["Mende_Kikakui",e.Mende_Kikakui],["Meroitic_Cursive",e.Meroitic_Cursive],["Meroitic_Hieroglyphs",e.Meroitic_Hieroglyphs],["Miao",e.Miao],["Modi",e.Modi],["Mongolian",e.Mongolian],["Mro",e.Mro],["Multani",e.Multani],["Myanmar",e.Myanmar],["Nabataean",e.Nabataean],["Nag_Mundari",e.Nag_Mundari],["Nandinagari",e.Nandinagari],["New_Tai_Lue",e.New_Tai_Lue],["Newa",e.Newa],["Nko",e.Nko],["Nushu",e.Nushu],["Nyiakeng_Puachue_Hmong",e.Nyiakeng_Puachue_Hmong],["Ogham",e.Ogham],["Ol_Chiki",e.Ol_Chiki],["Ol_Onal",e.Ol_Onal],["Old_Hungarian",e.Old_Hungarian],["Old_Italic",e.Old_Italic],["Old_North_Arabian",e.Old_North_Arabian],["Old_Permic",e.Old_Permic],["Old_Persian",e.Old_Persian],["Old_Sogdian",e.Old_Sogdian],["Old_South_Arabian",e.Old_South_Arabian],["Old_Turkic",e.Old_Turkic],["Old_Uyghur",e.Old_Uyghur],["Oriya",e.Oriya],["Osage",e.Osage],["Osmanya",e.Osmanya],["Pahawh_Hmong",e.Pahawh_Hmong],["Palmyrene",e.Palmyrene],["Pau_Cin_Hau",e.Pau_Cin_Hau],["Phags_Pa",e.Phags_Pa],["Phoenician",e.Phoenician],["Psalter_Pahlavi",e.Psalter_Pahlavi],["Rejang",e.Rejang],["Runic",e.Runic],["Samaritan",e.Samaritan],["Saurashtra",e.Saurashtra],["Sharada",e.Sharada],["Shavian",e.Shavian],["Siddham",e.Siddham],["SignWriting",e.SignWriting],["Sinhala",e.Sinhala],["Sogdian",e.Sogdian],["Sora_Sompeng",e.Sora_Sompeng],["Soyombo",e.Soyombo],["Sundanese",e.Sundanese],["Sunuwar",e.Sunuwar],["Syloti_Nagri",e.Syloti_Nagri],["Syriac",e.Syriac],["Tagalog",e.Tagalog],["Tagbanwa",e.Tagbanwa],["Tai_Le",e.Tai_Le],["Tai_Tham",e.Tai_Tham],["Tai_Viet",e.Tai_Viet],["Takri",e.Takri],["Tamil",e.Tamil],["Tangsa",e.Tangsa],["Tangut",e.Tangut],["Telugu",e.Telugu],["Thaana",e.Thaana],["Thai",e.Thai],["Tibetan",e.Tibetan],["Tifinagh",e.Tifinagh],["Tirhuta",e.Tirhuta],["Todhri",e.Todhri],["Toto",e.Toto],["Tulu_Tigalari",e.Tulu_Tigalari],["Ugaritic",e.Ugaritic],["Vai",e.Vai],["Vithkuqi",e.Vithkuqi],["Wancho",e.Wancho],["Warang_Citi",e.Warang_Citi],["Yezidi",e.Yezidi],["Yi",e.Yi],["Zanabazar_Square",e.Zanabazar_Square]]);static FOLD_CATEGORIES=new Map([["L",e.foldL],["Ll",e.foldLl],["Lt",e.foldLt],["Lu",e.foldLu],["M",e.foldM],["Mn",e.foldMn]]);static FOLD_SCRIPT=new Map([["Common",e.foldCommon],["Greek",e.foldGreek],["Inherited",e.foldInherited]]);static Print=new k(new Uint32Array([33,126,1,161,172,1,174,887,1,890,895,1,900,906,1,908,910,2,911,929,1,931,1327,1,1329,1366,1,1369,1418,1,1421,1423,1,1425,1479,1,1488,1514,1,1519,1524,1,1542,1563,1,1565,1756,1,1758,1805,1,1808,1866,1,1869,1969,1,1984,2042,1,2045,2093,1,2096,2110,1,2112,2139,1,2142,2144,2,2145,2154,1,2160,2190,1,2199,2273,1,2275,2435,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2492,2500,1,2503,2504,1,2507,2510,1,2519,2524,5,2525,2527,2,2528,2531,1,2534,2558,1,2561,2563,1,2565,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2649,8,2650,2652,1,2654,2662,8,2663,2678,1,2689,2691,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2748,2757,1,2759,2761,1,2763,2765,1,2768,2784,16,2785,2787,1,2790,2801,1,2809,2815,1,2817,2819,1,2821,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2876,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2908,2909,1,2911,2915,1,2918,2935,1,2946,2947,1,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3006,3010,1,3014,3016,1,3018,3021,1,3024,3031,7,3046,3066,1,3072,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3132,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3160,3162,1,3165,3168,3,3169,3171,1,3174,3183,1,3191,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3260,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3293,3294,1,3296,3299,1,3302,3311,1,3313,3315,1,3328,3340,1,3342,3344,1,3346,3396,1,3398,3400,1,3402,3407,1,3412,3427,1,3430,3455,1,3457,3459,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3558,3567,1,3570,3572,1,3585,3642,1,3647,3675,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3773,1,3776,3780,1,3782,3784,2,3785,3790,1,3792,3801,1,3804,3807,1,3840,3911,1,3913,3948,1,3953,3991,1,3993,4028,1,4030,4044,1,4046,4058,1,4096,4293,1,4295,4301,6,4304,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4957,4988,1,4992,5017,1,5024,5109,1,5112,5117,1,5120,5759,1,5761,5788,1,5792,5880,1,5888,5909,1,5919,5942,1,5952,5971,1,5984,5996,1,5998,6e3,1,6002,6003,1,6016,6109,1,6112,6121,1,6128,6137,1,6144,6157,1,6159,6169,1,6176,6264,1,6272,6314,1,6320,6389,1,6400,6430,1,6432,6443,1,6448,6459,1,6464,6468,4,6469,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6608,6618,1,6622,6683,1,6686,6750,1,6752,6780,1,6783,6793,1,6800,6809,1,6816,6829,1,6832,6862,1,6912,6988,1,6990,7155,1,7164,7223,1,7227,7241,1,7245,7306,1,7312,7354,1,7357,7367,1,7376,7418,1,7424,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8132,1,8134,8147,1,8150,8155,1,8157,8175,1,8178,8180,1,8182,8190,1,8208,8231,1,8240,8286,1,8304,8305,1,8308,8334,1,8336,8348,1,8352,8384,1,8400,8432,1,8448,8587,1,8592,9257,1,9280,9290,1,9312,11123,1,11126,11157,1,11159,11507,1,11513,11557,1,11559,11565,6,11568,11623,1,11631,11632,1,11647,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,11744,11869,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12289,12351,1,12353,12438,1,12441,12543,1,12549,12591,1,12593,12686,1,12688,12773,1,12783,12830,1,12832,42124,1,42128,42182,1,42192,42539,1,42560,42743,1,42752,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43052,1,43056,43065,1,43072,43127,1,43136,43205,1,43214,43225,1,43232,43347,1,43359,43388,1,43392,43469,1,43471,43481,1,43486,43518,1,43520,43574,1,43584,43597,1,43600,43609,1,43612,43714,1,43739,43766,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43824,43883,1,43888,44013,1,44016,44025,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64256,64262,1,64275,64279,1,64285,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64450,1,64467,64911,1,64914,64967,1,64975,65008,33,65009,65049,1,65056,65106,1,65108,65126,1,65128,65131,1,65136,65140,1,65142,65276,1,65281,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65504,65510,1,65512,65518,1,65532,65533,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,65792,65794,1,65799,65843,1,65847,65934,1,65936,65948,1,65952,66e3,48,66001,66045,1,66176,66204,1,66208,66256,1,66272,66299,1,66304,66339,1,66349,66378,1,66384,66426,1,66432,66461,1,66463,66499,1,66504,66517,1,66560,66717,1,66720,66729,1,66736,66771,1,66776,66811,1,66816,66855,1,66864,66915,1,66927,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67456,67461,1,67463,67504,1,67506,67514,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67671,67742,1,67751,67759,1,67808,67826,1,67828,67829,1,67835,67867,1,67871,67897,1,67903,67968,65,67969,68023,1,68028,68047,1,68050,68099,1,68101,68102,1,68108,68115,1,68117,68119,1,68121,68149,1,68152,68154,1,68159,68168,1,68176,68184,1,68192,68255,1,68288,68326,1,68331,68342,1,68352,68405,1,68409,68437,1,68440,68466,1,68472,68497,1,68505,68508,1,68521,68527,1,68608,68680,1,68736,68786,1,68800,68850,1,68858,68903,1,68912,68921,1,68928,68965,1,68969,68997,1,69006,69007,1,69216,69246,1,69248,69289,1,69291,69293,1,69296,69297,1,69314,69316,1,69372,69415,1,69424,69465,1,69488,69513,1,69552,69579,1,69600,69622,1,69632,69709,1,69714,69749,1,69759,69820,1,69822,69826,1,69840,69864,1,69872,69881,1,69888,69940,1,69942,69959,1,69968,70006,1,70016,70111,1,70113,70132,1,70144,70161,1,70163,70209,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70313,1,70320,70378,1,70384,70393,1,70400,70403,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70459,70468,1,70471,70472,1,70475,70477,1,70480,70487,7,70493,70499,1,70502,70508,1,70512,70516,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70592,1,70594,70597,3,70599,70602,1,70604,70613,1,70615,70616,1,70625,70626,1,70656,70747,1,70749,70753,1,70784,70855,1,70864,70873,1,71040,71093,1,71096,71133,1,71168,71236,1,71248,71257,1,71264,71276,1,71296,71353,1,71360,71369,1,71376,71395,1,71424,71450,1,71453,71467,1,71472,71494,1,71680,71739,1,71840,71922,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71989,1,71991,71992,1,71995,72006,1,72016,72025,1,72096,72103,1,72106,72151,1,72154,72164,1,72192,72263,1,72272,72354,1,72368,72440,1,72448,72457,1,72640,72673,1,72688,72697,1,72704,72712,1,72714,72758,1,72760,72773,1,72784,72812,1,72816,72847,1,72850,72871,1,72873,72886,1,72960,72966,1,72968,72969,1,72971,73014,1,73018,73020,2,73021,73023,2,73024,73031,1,73040,73049,1,73056,73061,1,73063,73064,1,73066,73102,1,73104,73105,1,73107,73112,1,73120,73129,1,73440,73464,1,73472,73488,1,73490,73530,1,73534,73562,1,73648,73664,16,73665,73713,1,73727,74649,1,74752,74862,1,74864,74868,1,74880,75075,1,77712,77810,1,77824,78895,1,78912,78933,1,78944,82938,1,82944,83526,1,90368,90425,1,92160,92728,1,92736,92766,1,92768,92777,1,92782,92862,1,92864,92873,1,92880,92909,1,92912,92917,1,92928,92997,1,93008,93017,1,93019,93025,1,93027,93047,1,93053,93071,1,93504,93561,1,93760,93850,1,93952,94026,1,94031,94087,1,94095,94111,1,94176,94180,1,94192,94193,1,94208,100343,1,100352,101589,1,101631,101640,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,113820,113823,1,117760,118009,1,118016,118451,1,118528,118573,1,118576,118598,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119154,1,119163,119274,1,119296,119365,1,119488,119507,1,119520,119539,1,119552,119638,1,119648,119672,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120779,1,120782,121483,1,121499,121503,1,121505,121519,1,122624,122654,1,122661,122666,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,122928,122989,1,123023,123136,113,123137,123180,1,123184,123197,1,123200,123209,1,123214,123215,1,123536,123566,1,123584,123641,1,123647,124112,465,124113,124153,1,124368,124410,1,124415,124896,481,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,125127,125142,1,125184,125259,1,125264,125273,1,125278,125279,1,126065,126132,1,126209,126269,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,126704,126705,1,126976,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127232,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130041,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1,917760,917999,1]))},ue=class{static MAX_RUNE=1114111;static MAX_ASCII=127;static MAX_LATIN1=255;static MAX_BMP=65535;static MIN_FOLD=65;static MAX_FOLD=125251;static is32(t,n){let r=0,s=t.length;for(;rs)continue;let i=t.getLo(r);if(n0&&n>=t.getLo(0)&&this.is32(t,n)}static isUpper(t){if(t<=this.MAX_LATIN1){let n=String.fromCodePoint(t);return n.toUpperCase()===n&&n.toLowerCase()!==n}return this.is(pn.Upper,t)}static isPrint(t){return t<=this.MAX_LATIN1?t>=32&&t=161&&t!==173:this.is(pn.Print,t)}static simpleFold(t){if(pn.CASE_ORBIT.has(t))return pn.CASE_ORBIT.get(t);let n=D.toLowerCase(t);return n!==t?n:D.toUpperCase(t)}static equalsIgnoreCase(t,n){if(t<0||n<0||t===n)return!0;if(t<=this.MAX_ASCII&&n<=this.MAX_ASCII)return D.CODES.get("A")<=t&&t<=D.CODES.get("Z")&&(t|=32),D.CODES.get("A")<=n&&n<=D.CODES.get("Z")&&(n|=32),t===n;for(let r=this.simpleFold(t);r!==t;r=this.simpleFold(r))if(r===n)return!0;return!1}},Oe=class{static METACHARACTERS="\\.+*?()|[]{}^$";static EMPTY_BEGIN_LINE=1;static EMPTY_END_LINE=2;static EMPTY_BEGIN_TEXT=4;static EMPTY_END_TEXT=8;static EMPTY_WORD_BOUNDARY=16;static EMPTY_NO_WORD_BOUNDARY=32;static EMPTY_ALL=-1;static emptyInts(){return[]}static isalnum(t){return D.CODES.get("0")<=t&&t<=D.CODES.get("9")||D.CODES.get("a")<=t&&t<=D.CODES.get("z")||D.CODES.get("A")<=t&&t<=D.CODES.get("Z")}static unhex(t){return D.CODES.get("0")<=t&&t<=D.CODES.get("9")?t-D.CODES.get("0"):D.CODES.get("a")<=t&&t<=D.CODES.get("f")?t-D.CODES.get("a")+10:D.CODES.get("A")<=t&&t<=D.CODES.get("F")?t-D.CODES.get("A")+10:-1}static escapeRune(t){let n="";if(ue.isPrint(t))this.METACHARACTERS.indexOf(String.fromCodePoint(t))>=0&&(n+="\\"),n+=String.fromCodePoint(t);else switch(t){case D.CODES.get('"'):n+='\\"';break;case D.CODES.get("\\"):n+="\\\\";break;case D.CODES.get(" "):n+="\\t";break;case D.CODES.get(` +`,a=!0}}return{stdout:i,stderr:o,exitCode:a?1:0}}},B4={name:"stat",flags:[{flag:"-c",type:"value",valueHint:"format"},{flag:"-L",type:"boolean"}],needsArgs:!0}});var V,D,k,on,ue,Te,O1,Jn,$i,Ua,Kr,Tn,Ba,Wa,Ye,Qr,je,za,mn,Ha,Ti,he,ja,Oi,Rs,W4,z4,Ga,Va,_,qa,Zr,Za,Ka,$e,p1,h1,d1,m1,g1,y1,w1,b1,x1,E1,A1,S1,C1,v1,k1,N1,I1,$1,T1,$n,Ps,Qa,Xa,Ya,Ja,el,er,R1=O(()=>{V=class e{static FOLD_CASE=1;static LITERAL=2;static CLASS_NL=4;static DOT_NL=8;static ONE_LINE=16;static NON_GREEDY=32;static PERL_X=64;static UNICODE_GROUPS=128;static WAS_DOLLAR=256;static MATCH_NL=e.CLASS_NL|e.DOT_NL;static PERL=e.CLASS_NL|e.ONE_LINE|e.PERL_X|e.UNICODE_GROUPS;static POSIX=0;static UNANCHORED=0;static ANCHOR_START=1;static ANCHOR_BOTH=2},D=class{static CODES=new Map([["\x07",7],["\b",8],[" ",9],[` +`,10],["\v",11],["\f",12],["\r",13],[" ",32],['"',34],["$",36],["&",38],["(",40],[")",41],["*",42],["+",43],["-",45],[".",46],["0",48],["1",49],["2",50],["3",51],["4",52],["5",53],["6",54],["7",55],["8",56],["9",57],[":",58],["<",60],[">",62],["?",63],["A",65],["B",66],["C",67],["F",70],["P",80],["Q",81],["U",85],["Z",90],["[",91],["\\",92],["]",93],["^",94],["_",95],["a",97],["b",98],["f",102],["i",105],["m",109],["n",110],["r",114],["s",115],["t",116],["v",118],["x",120],["z",122],["{",123],["|",124],["}",125]]);static toUpperCase(t){let n=String.fromCodePoint(t).toUpperCase();if(n.length>1)return t;let r=String.fromCodePoint(n.codePointAt(0)).toLowerCase();return r.length>1||r.codePointAt(0)!==t?t:n.codePointAt(0)}static toLowerCase(t){let n=String.fromCodePoint(t).toLowerCase();if(n.length>1)return t;let r=String.fromCodePoint(n.codePointAt(0)).toUpperCase();return r.length>1||r.codePointAt(0)!==t?t:n.codePointAt(0)}},k=class{SIZE=3;constructor(t){this.data=t}getLo(t){return this.data[t*this.SIZE]}getHi(t){return this.data[t*this.SIZE+1]}getStride(t){return this.data[t*this.SIZE+2]}get(t){let n=t*this.SIZE;return[this.data[n],this.data[n+1],this.data[n+2]]}get length(){return this.data.length/this.SIZE}},on=class e{static CASE_ORBIT=new Map([[75,107],[107,8490],[8490,75],[83,115],[115,383],[383,83],[181,924],[924,956],[956,181],[197,229],[229,8491],[8491,197],[452,453],[453,454],[454,452],[455,456],[456,457],[457,455],[458,459],[459,460],[460,458],[497,498],[498,499],[499,497],[837,921],[921,953],[953,8126],[8126,837],[914,946],[946,976],[976,914],[917,949],[949,1013],[1013,917],[920,952],[952,977],[977,1012],[1012,920],[922,954],[954,1008],[1008,922],[928,960],[960,982],[982,928],[929,961],[961,1009],[1009,929],[931,962],[962,963],[963,931],[934,966],[966,981],[981,934],[937,969],[969,8486],[8486,937],[1042,1074],[1074,7296],[7296,1042],[1044,1076],[1076,7297],[7297,1044],[1054,1086],[1086,7298],[7298,1054],[1057,1089],[1089,7299],[7299,1057],[1058,1090],[1090,7300],[7300,7301],[7301,1058],[1066,1098],[1098,7302],[7302,1066],[1122,1123],[1123,7303],[7303,1122],[7304,42570],[42570,42571],[42571,7304],[7776,7777],[7777,7835],[7835,7776],[223,7838],[7838,223],[8064,8072],[8072,8064],[8065,8073],[8073,8065],[8066,8074],[8074,8066],[8067,8075],[8075,8067],[8068,8076],[8076,8068],[8069,8077],[8077,8069],[8070,8078],[8078,8070],[8071,8079],[8079,8071],[8080,8088],[8088,8080],[8081,8089],[8089,8081],[8082,8090],[8090,8082],[8083,8091],[8091,8083],[8084,8092],[8092,8084],[8085,8093],[8093,8085],[8086,8094],[8094,8086],[8087,8095],[8095,8087],[8096,8104],[8104,8096],[8097,8105],[8105,8097],[8098,8106],[8106,8098],[8099,8107],[8107,8099],[8100,8108],[8108,8100],[8101,8109],[8109,8101],[8102,8110],[8110,8102],[8103,8111],[8111,8103],[8115,8124],[8124,8115],[8131,8140],[8140,8131],[912,8147],[8147,912],[944,8163],[8163,944],[8179,8188],[8188,8179],[64261,64262],[64262,64261],[66560,66600],[66600,66560],[66561,66601],[66601,66561],[66562,66602],[66602,66562],[66563,66603],[66603,66563],[66564,66604],[66604,66564],[66565,66605],[66605,66565],[66566,66606],[66606,66566],[66567,66607],[66607,66567],[66568,66608],[66608,66568],[66569,66609],[66609,66569],[66570,66610],[66610,66570],[66571,66611],[66611,66571],[66572,66612],[66612,66572],[66573,66613],[66613,66573],[66574,66614],[66614,66574],[66575,66615],[66615,66575],[66576,66616],[66616,66576],[66577,66617],[66617,66577],[66578,66618],[66618,66578],[66579,66619],[66619,66579],[66580,66620],[66620,66580],[66581,66621],[66621,66581],[66582,66622],[66622,66582],[66583,66623],[66623,66583],[66584,66624],[66624,66584],[66585,66625],[66625,66585],[66586,66626],[66626,66586],[66587,66627],[66627,66587],[66588,66628],[66628,66588],[66589,66629],[66629,66589],[66590,66630],[66630,66590],[66591,66631],[66631,66591],[66592,66632],[66632,66592],[66593,66633],[66633,66593],[66594,66634],[66634,66594],[66595,66635],[66635,66595],[66596,66636],[66636,66596],[66597,66637],[66637,66597],[66598,66638],[66638,66598],[66599,66639],[66639,66599],[66736,66776],[66776,66736],[66737,66777],[66777,66737],[66738,66778],[66778,66738],[66739,66779],[66779,66739],[66740,66780],[66780,66740],[66741,66781],[66781,66741],[66742,66782],[66782,66742],[66743,66783],[66783,66743],[66744,66784],[66784,66744],[66745,66785],[66785,66745],[66746,66786],[66786,66746],[66747,66787],[66787,66747],[66748,66788],[66788,66748],[66749,66789],[66789,66749],[66750,66790],[66790,66750],[66751,66791],[66791,66751],[66752,66792],[66792,66752],[66753,66793],[66793,66753],[66754,66794],[66794,66754],[66755,66795],[66795,66755],[66756,66796],[66796,66756],[66757,66797],[66797,66757],[66758,66798],[66798,66758],[66759,66799],[66799,66759],[66760,66800],[66800,66760],[66761,66801],[66801,66761],[66762,66802],[66802,66762],[66763,66803],[66803,66763],[66764,66804],[66804,66764],[66765,66805],[66805,66765],[66766,66806],[66806,66766],[66767,66807],[66807,66767],[66768,66808],[66808,66768],[66769,66809],[66809,66769],[66770,66810],[66810,66770],[66771,66811],[66811,66771],[66928,66967],[66967,66928],[66929,66968],[66968,66929],[66930,66969],[66969,66930],[66931,66970],[66970,66931],[66932,66971],[66971,66932],[66933,66972],[66972,66933],[66934,66973],[66973,66934],[66935,66974],[66974,66935],[66936,66975],[66975,66936],[66937,66976],[66976,66937],[66938,66977],[66977,66938],[66940,66979],[66979,66940],[66941,66980],[66980,66941],[66942,66981],[66981,66942],[66943,66982],[66982,66943],[66944,66983],[66983,66944],[66945,66984],[66984,66945],[66946,66985],[66985,66946],[66947,66986],[66986,66947],[66948,66987],[66987,66948],[66949,66988],[66988,66949],[66950,66989],[66989,66950],[66951,66990],[66990,66951],[66952,66991],[66991,66952],[66953,66992],[66992,66953],[66954,66993],[66993,66954],[66956,66995],[66995,66956],[66957,66996],[66996,66957],[66958,66997],[66997,66958],[66959,66998],[66998,66959],[66960,66999],[66999,66960],[66961,67e3],[67e3,66961],[66962,67001],[67001,66962],[66964,67003],[67003,66964],[66965,67004],[67004,66965],[68736,68800],[68800,68736],[68737,68801],[68801,68737],[68738,68802],[68802,68738],[68739,68803],[68803,68739],[68740,68804],[68804,68740],[68741,68805],[68805,68741],[68742,68806],[68806,68742],[68743,68807],[68807,68743],[68744,68808],[68808,68744],[68745,68809],[68809,68745],[68746,68810],[68810,68746],[68747,68811],[68811,68747],[68748,68812],[68812,68748],[68749,68813],[68813,68749],[68750,68814],[68814,68750],[68751,68815],[68815,68751],[68752,68816],[68816,68752],[68753,68817],[68817,68753],[68754,68818],[68818,68754],[68755,68819],[68819,68755],[68756,68820],[68820,68756],[68757,68821],[68821,68757],[68758,68822],[68822,68758],[68759,68823],[68823,68759],[68760,68824],[68824,68760],[68761,68825],[68825,68761],[68762,68826],[68826,68762],[68763,68827],[68827,68763],[68764,68828],[68828,68764],[68765,68829],[68829,68765],[68766,68830],[68830,68766],[68767,68831],[68831,68767],[68768,68832],[68832,68768],[68769,68833],[68833,68769],[68770,68834],[68834,68770],[68771,68835],[68835,68771],[68772,68836],[68836,68772],[68773,68837],[68837,68773],[68774,68838],[68838,68774],[68775,68839],[68839,68775],[68776,68840],[68840,68776],[68777,68841],[68841,68777],[68778,68842],[68842,68778],[68779,68843],[68843,68779],[68780,68844],[68844,68780],[68781,68845],[68845,68781],[68782,68846],[68846,68782],[68783,68847],[68847,68783],[68784,68848],[68848,68784],[68785,68849],[68849,68785],[68786,68850],[68850,68786],[68944,68976],[68976,68944],[68945,68977],[68977,68945],[68946,68978],[68978,68946],[68947,68979],[68979,68947],[68948,68980],[68980,68948],[68949,68981],[68981,68949],[68950,68982],[68982,68950],[68951,68983],[68983,68951],[68952,68984],[68984,68952],[68953,68985],[68985,68953],[68954,68986],[68986,68954],[68955,68987],[68987,68955],[68956,68988],[68988,68956],[68957,68989],[68989,68957],[68958,68990],[68990,68958],[68959,68991],[68991,68959],[68960,68992],[68992,68960],[68961,68993],[68993,68961],[68962,68994],[68994,68962],[68963,68995],[68995,68963],[68964,68996],[68996,68964],[68965,68997],[68997,68965],[71840,71872],[71872,71840],[71841,71873],[71873,71841],[71842,71874],[71874,71842],[71843,71875],[71875,71843],[71844,71876],[71876,71844],[71845,71877],[71877,71845],[71846,71878],[71878,71846],[71847,71879],[71879,71847],[71848,71880],[71880,71848],[71849,71881],[71881,71849],[71850,71882],[71882,71850],[71851,71883],[71883,71851],[71852,71884],[71884,71852],[71853,71885],[71885,71853],[71854,71886],[71886,71854],[71855,71887],[71887,71855],[71856,71888],[71888,71856],[71857,71889],[71889,71857],[71858,71890],[71890,71858],[71859,71891],[71891,71859],[71860,71892],[71892,71860],[71861,71893],[71893,71861],[71862,71894],[71894,71862],[71863,71895],[71895,71863],[71864,71896],[71896,71864],[71865,71897],[71897,71865],[71866,71898],[71898,71866],[71867,71899],[71899,71867],[71868,71900],[71900,71868],[71869,71901],[71901,71869],[71870,71902],[71902,71870],[71871,71903],[71903,71871],[93760,93792],[93792,93760],[93761,93793],[93793,93761],[93762,93794],[93794,93762],[93763,93795],[93795,93763],[93764,93796],[93796,93764],[93765,93797],[93797,93765],[93766,93798],[93798,93766],[93767,93799],[93799,93767],[93768,93800],[93800,93768],[93769,93801],[93801,93769],[93770,93802],[93802,93770],[93771,93803],[93803,93771],[93772,93804],[93804,93772],[93773,93805],[93805,93773],[93774,93806],[93806,93774],[93775,93807],[93807,93775],[93776,93808],[93808,93776],[93777,93809],[93809,93777],[93778,93810],[93810,93778],[93779,93811],[93811,93779],[93780,93812],[93812,93780],[93781,93813],[93813,93781],[93782,93814],[93814,93782],[93783,93815],[93815,93783],[93784,93816],[93816,93784],[93785,93817],[93817,93785],[93786,93818],[93818,93786],[93787,93819],[93819,93787],[93788,93820],[93820,93788],[93789,93821],[93821,93789],[93790,93822],[93822,93790],[93791,93823],[93823,93791],[125184,125218],[125218,125184],[125185,125219],[125219,125185],[125186,125220],[125220,125186],[125187,125221],[125221,125187],[125188,125222],[125222,125188],[125189,125223],[125223,125189],[125190,125224],[125224,125190],[125191,125225],[125225,125191],[125192,125226],[125226,125192],[125193,125227],[125227,125193],[125194,125228],[125228,125194],[125195,125229],[125229,125195],[125196,125230],[125230,125196],[125197,125231],[125231,125197],[125198,125232],[125232,125198],[125199,125233],[125233,125199],[125200,125234],[125234,125200],[125201,125235],[125235,125201],[125202,125236],[125236,125202],[125203,125237],[125237,125203],[125204,125238],[125238,125204],[125205,125239],[125239,125205],[125206,125240],[125240,125206],[125207,125241],[125241,125207],[125208,125242],[125242,125208],[125209,125243],[125243,125209],[125210,125244],[125244,125210],[125211,125245],[125245,125211],[125212,125246],[125246,125212],[125213,125247],[125247,125213],[125214,125248],[125248,125214],[125215,125249],[125249,125215],[125216,125250],[125250,125216],[125217,125251],[125251,125217]]);static C=new k(new Uint32Array([0,31,1,127,159,1,173,888,715,889,896,7,897,899,1,907,909,2,930,1328,398,1367,1368,1,1419,1420,1,1424,1480,56,1481,1487,1,1515,1518,1,1525,1541,1,1564,1757,193,1806,1807,1,1867,1868,1,1970,1983,1,2043,2044,1,2094,2095,1,2111,2140,29,2141,2143,2,2155,2159,1,2191,2198,1,2274,2436,162,2445,2446,1,2449,2450,1,2473,2481,8,2483,2485,1,2490,2491,1,2501,2502,1,2505,2506,1,2511,2518,1,2520,2523,1,2526,2532,6,2533,2559,26,2560,2564,4,2571,2574,1,2577,2578,1,2601,2609,8,2612,2618,3,2619,2621,2,2627,2630,1,2633,2634,1,2638,2640,1,2642,2648,1,2653,2655,2,2656,2661,1,2679,2688,1,2692,2702,10,2706,2729,23,2737,2740,3,2746,2747,1,2758,2766,4,2767,2769,2,2770,2783,1,2788,2789,1,2802,2808,1,2816,2820,4,2829,2830,1,2833,2834,1,2857,2865,8,2868,2874,6,2875,2885,10,2886,2889,3,2890,2894,4,2895,2900,1,2904,2907,1,2910,2916,6,2917,2936,19,2937,2945,1,2948,2955,7,2956,2957,1,2961,2966,5,2967,2968,1,2971,2973,2,2976,2978,1,2981,2983,1,2987,2989,1,3002,3005,1,3011,3013,1,3017,3022,5,3023,3025,2,3026,3030,1,3032,3045,1,3067,3071,1,3085,3089,4,3113,3130,17,3131,3141,10,3145,3150,5,3151,3156,1,3159,3163,4,3164,3166,2,3167,3172,5,3173,3184,11,3185,3190,1,3213,3217,4,3241,3252,11,3258,3259,1,3269,3273,4,3278,3284,1,3287,3292,1,3295,3300,5,3301,3312,11,3316,3327,1,3341,3345,4,3397,3401,4,3408,3411,1,3428,3429,1,3456,3460,4,3479,3481,1,3506,3516,10,3518,3519,1,3527,3529,1,3531,3534,1,3541,3543,2,3552,3557,1,3568,3569,1,3573,3584,1,3643,3646,1,3676,3712,1,3715,3717,2,3723,3748,25,3750,3774,24,3775,3781,6,3783,3791,8,3802,3803,1,3808,3839,1,3912,3949,37,3950,3952,1,3992,4029,37,4045,4059,14,4060,4095,1,4294,4296,2,4297,4300,1,4302,4303,1,4681,4686,5,4687,4695,8,4697,4702,5,4703,4745,42,4750,4751,1,4785,4790,5,4791,4799,8,4801,4806,5,4807,4823,16,4881,4886,5,4887,4955,68,4956,4989,33,4990,4991,1,5018,5023,1,5110,5111,1,5118,5119,1,5789,5791,1,5881,5887,1,5910,5918,1,5943,5951,1,5972,5983,1,5997,6001,4,6004,6015,1,6110,6111,1,6122,6127,1,6138,6143,1,6158,6170,12,6171,6175,1,6265,6271,1,6315,6319,1,6390,6399,1,6431,6444,13,6445,6447,1,6460,6463,1,6465,6467,1,6510,6511,1,6517,6527,1,6572,6575,1,6602,6607,1,6619,6621,1,6684,6685,1,6751,6781,30,6782,6794,12,6795,6799,1,6810,6815,1,6830,6831,1,6863,6911,1,6989,7156,167,7157,7163,1,7224,7226,1,7242,7244,1,7307,7311,1,7355,7356,1,7368,7375,1,7419,7423,1,7958,7959,1,7966,7967,1,8006,8007,1,8014,8015,1,8024,8030,2,8062,8063,1,8117,8133,16,8148,8149,1,8156,8176,20,8177,8181,4,8191,8203,12,8204,8207,1,8234,8238,1,8288,8303,1,8306,8307,1,8335,8349,14,8350,8351,1,8385,8399,1,8433,8447,1,8588,8591,1,9258,9279,1,9291,9311,1,11124,11125,1,11158,11508,350,11509,11512,1,11558,11560,2,11561,11564,1,11566,11567,1,11624,11630,1,11633,11646,1,11671,11679,1,11687,11743,8,11870,11903,1,11930,12020,90,12021,12031,1,12246,12271,1,12352,12439,87,12440,12544,104,12545,12548,1,12592,12687,95,12774,12782,1,12831,42125,29294,42126,42127,1,42183,42191,1,42540,42559,1,42744,42751,1,42958,42959,1,42962,42964,2,42973,42993,1,43053,43055,1,43066,43071,1,43128,43135,1,43206,43213,1,43226,43231,1,43348,43358,1,43389,43391,1,43470,43482,12,43483,43485,1,43519,43575,56,43576,43583,1,43598,43599,1,43610,43611,1,43715,43738,1,43767,43776,1,43783,43784,1,43791,43792,1,43799,43807,1,43815,43823,8,43884,43887,1,44014,44015,1,44026,44031,1,55204,55215,1,55239,55242,1,55292,63743,1,64110,64111,1,64218,64255,1,64263,64274,1,64280,64284,1,64311,64317,6,64319,64325,3,64451,64466,1,64912,64913,1,64968,64974,1,64976,65007,1,65050,65055,1,65107,65127,20,65132,65135,1,65141,65277,136,65278,65280,1,65471,65473,1,65480,65481,1,65488,65489,1,65496,65497,1,65501,65503,1,65511,65519,8,65520,65531,1,65534,65535,1,65548,65575,27,65595,65598,3,65614,65615,1,65630,65663,1,65787,65791,1,65795,65798,1,65844,65846,1,65935,65949,14,65950,65951,1,65953,65999,1,66046,66175,1,66205,66207,1,66257,66271,1,66300,66303,1,66340,66348,1,66379,66383,1,66427,66431,1,66462,66500,38,66501,66503,1,66518,66559,1,66718,66719,1,66730,66735,1,66772,66775,1,66812,66815,1,66856,66863,1,66916,66926,1,66939,66955,16,66963,66966,3,66978,66994,16,67002,67005,3,67006,67007,1,67060,67071,1,67383,67391,1,67414,67423,1,67432,67455,1,67462,67505,43,67515,67583,1,67590,67591,1,67593,67638,45,67641,67643,1,67645,67646,1,67670,67743,73,67744,67750,1,67760,67807,1,67827,67830,3,67831,67834,1,67868,67870,1,67898,67902,1,67904,67967,1,68024,68027,1,68048,68049,1,68100,68103,3,68104,68107,1,68116,68120,4,68150,68151,1,68155,68158,1,68169,68175,1,68185,68191,1,68256,68287,1,68327,68330,1,68343,68351,1,68406,68408,1,68438,68439,1,68467,68471,1,68498,68504,1,68509,68520,1,68528,68607,1,68681,68735,1,68787,68799,1,68851,68857,1,68904,68911,1,68922,68927,1,68966,68968,1,68998,69005,1,69008,69215,1,69247,69290,43,69294,69295,1,69298,69313,1,69317,69371,1,69416,69423,1,69466,69487,1,69514,69551,1,69580,69599,1,69623,69631,1,69710,69713,1,69750,69758,1,69821,69827,6,69828,69839,1,69865,69871,1,69882,69887,1,69941,69960,19,69961,69967,1,70007,70015,1,70112,70133,21,70134,70143,1,70162,70210,48,70211,70271,1,70279,70281,2,70286,70302,16,70314,70319,1,70379,70383,1,70394,70399,1,70404,70413,9,70414,70417,3,70418,70441,23,70449,70452,3,70458,70469,11,70470,70473,3,70474,70478,4,70479,70481,2,70482,70486,1,70488,70492,1,70500,70501,1,70509,70511,1,70517,70527,1,70538,70540,2,70541,70543,2,70582,70593,11,70595,70596,1,70598,70603,5,70614,70617,3,70618,70624,1,70627,70655,1,70748,70754,6,70755,70783,1,70856,70863,1,70874,71039,1,71094,71095,1,71134,71167,1,71237,71247,1,71258,71263,1,71277,71295,1,71354,71359,1,71370,71375,1,71396,71423,1,71451,71452,1,71468,71471,1,71495,71679,1,71740,71839,1,71923,71934,1,71943,71944,1,71946,71947,1,71956,71959,3,71990,71993,3,71994,72007,13,72008,72015,1,72026,72095,1,72104,72105,1,72152,72153,1,72165,72191,1,72264,72271,1,72355,72367,1,72441,72447,1,72458,72639,1,72674,72687,1,72698,72703,1,72713,72759,46,72774,72783,1,72813,72815,1,72848,72849,1,72872,72887,15,72888,72959,1,72967,72970,3,73015,73017,1,73019,73022,3,73032,73039,1,73050,73055,1,73062,73065,3,73103,73106,3,73113,73119,1,73130,73439,1,73465,73471,1,73489,73531,42,73532,73533,1,73563,73647,1,73649,73663,1,73714,73726,1,74650,74751,1,74863,74869,6,74870,74879,1,75076,77711,1,77811,77823,1,78896,78911,1,78934,78943,1,82939,82943,1,83527,90367,1,90426,92159,1,92729,92735,1,92767,92778,11,92779,92781,1,92863,92874,11,92875,92879,1,92910,92911,1,92918,92927,1,92998,93007,1,93018,93026,8,93048,93052,1,93072,93503,1,93562,93759,1,93851,93951,1,94027,94030,1,94088,94094,1,94112,94175,1,94181,94191,1,94194,94207,1,100344,100351,1,101590,101630,1,101641,110575,1,110580,110588,8,110591,110883,292,110884,110897,1,110899,110927,1,110931,110932,1,110934,110947,1,110952,110959,1,111356,113663,1,113771,113775,1,113789,113791,1,113801,113807,1,113818,113819,1,113824,117759,1,118010,118015,1,118452,118527,1,118574,118575,1,118599,118607,1,118724,118783,1,119030,119039,1,119079,119080,1,119155,119162,1,119275,119295,1,119366,119487,1,119508,119519,1,119540,119551,1,119639,119647,1,119673,119807,1,119893,119965,72,119968,119969,1,119971,119972,1,119975,119976,1,119981,119994,13,119996,120004,8,120070,120075,5,120076,120085,9,120093,120122,29,120127,120133,6,120135,120137,1,120145,120486,341,120487,120780,293,120781,121484,703,121485,121498,1,121504,121520,16,121521,122623,1,122655,122660,1,122667,122879,1,122887,122905,18,122906,122914,8,122917,122923,6,122924,122927,1,122990,123022,1,123024,123135,1,123181,123183,1,123198,123199,1,123210,123213,1,123216,123535,1,123567,123583,1,123642,123646,1,123648,124111,1,124154,124367,1,124411,124414,1,124416,124895,1,124903,124908,5,124911,124927,16,125125,125126,1,125143,125183,1,125260,125263,1,125274,125277,1,125280,126064,1,126133,126208,1,126270,126463,1,126468,126496,28,126499,126501,2,126502,126504,2,126515,126520,5,126522,126524,2,126525,126529,1,126531,126534,1,126536,126540,2,126544,126547,3,126549,126550,1,126552,126560,2,126563,126565,2,126566,126571,5,126579,126589,5,126591,126602,11,126620,126624,1,126628,126634,6,126652,126703,1,126706,126975,1,127020,127023,1,127124,127135,1,127151,127152,1,127168,127184,16,127222,127231,1,127406,127461,1,127491,127503,1,127548,127551,1,127561,127567,1,127570,127583,1,127590,127743,1,128728,128731,1,128749,128751,1,128765,128767,1,128887,128890,1,128986,128991,1,129004,129007,1,129009,129023,1,129036,129039,1,129096,129103,1,129114,129119,1,129160,129167,1,129198,129199,1,129212,129215,1,129218,129279,1,129620,129631,1,129646,129647,1,129661,129663,1,129674,129678,1,129735,129741,1,129757,129758,1,129770,129775,1,129785,129791,1,129939,130042,103,130043,131071,1,173792,173823,1,177978,177983,1,178206,178207,1,183970,183983,1,191457,191471,1,192094,194559,1,195102,196607,1,201547,201551,1,205744,917759,1,918e3,1114111,1]));static Cc=new k(new Uint32Array([0,31,1,127,159,1]));static Cf=new k(new Uint32Array([173,1536,1363,1537,1541,1,1564,1757,193,1807,2192,385,2193,2274,81,6158,8203,2045,8204,8207,1,8234,8238,1,8288,8292,1,8294,8303,1,65279,65529,250,65530,65531,1,69821,69837,16,78896,78911,1,113824,113827,1,119155,119162,1,917505,917536,31,917537,917631,1]));static Co=new k(new Uint32Array([57344,63743,1,983040,1048573,1,1048576,1114109,1]));static Cs=new k(new Uint32Array([55296,57343,1]));static L=new k(new Uint32Array([65,90,1,97,122,1,170,181,11,186,192,6,193,214,1,216,246,1,248,705,1,710,721,1,736,740,1,748,750,2,880,884,1,886,887,1,890,893,1,895,902,7,904,906,1,908,910,2,911,929,1,931,1013,1,1015,1153,1,1162,1327,1,1329,1366,1,1369,1376,7,1377,1416,1,1488,1514,1,1519,1522,1,1568,1610,1,1646,1647,1,1649,1747,1,1749,1765,16,1766,1774,8,1775,1786,11,1787,1788,1,1791,1808,17,1810,1839,1,1869,1957,1,1969,1994,25,1995,2026,1,2036,2037,1,2042,2048,6,2049,2069,1,2074,2084,10,2088,2112,24,2113,2136,1,2144,2154,1,2160,2183,1,2185,2190,1,2208,2249,1,2308,2361,1,2365,2384,19,2392,2401,1,2417,2432,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2493,2510,17,2524,2525,1,2527,2529,1,2544,2545,1,2556,2565,9,2566,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2649,2652,1,2654,2674,20,2675,2676,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2749,2768,19,2784,2785,1,2809,2821,12,2822,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2877,2908,31,2909,2911,2,2912,2913,1,2929,2947,18,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3024,3077,53,3078,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3133,3160,27,3161,3162,1,3165,3168,3,3169,3200,31,3205,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3261,3293,32,3294,3296,2,3297,3313,16,3314,3332,18,3333,3340,1,3342,3344,1,3346,3386,1,3389,3406,17,3412,3414,1,3423,3425,1,3450,3455,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3585,3632,1,3634,3635,1,3648,3654,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3760,1,3762,3763,1,3773,3776,3,3777,3780,1,3782,3804,22,3805,3807,1,3840,3904,64,3905,3911,1,3913,3948,1,3976,3980,1,4096,4138,1,4159,4176,17,4177,4181,1,4186,4189,1,4193,4197,4,4198,4206,8,4207,4208,1,4213,4225,1,4238,4256,18,4257,4293,1,4295,4301,6,4304,4346,1,4348,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4992,5007,1,5024,5109,1,5112,5117,1,5121,5740,1,5743,5759,1,5761,5786,1,5792,5866,1,5873,5880,1,5888,5905,1,5919,5937,1,5952,5969,1,5984,5996,1,5998,6e3,1,6016,6067,1,6103,6108,5,6176,6264,1,6272,6276,1,6279,6312,1,6314,6320,6,6321,6389,1,6400,6430,1,6480,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6656,6678,1,6688,6740,1,6823,6917,94,6918,6963,1,6981,6988,1,7043,7072,1,7086,7087,1,7098,7141,1,7168,7203,1,7245,7247,1,7258,7293,1,7296,7306,1,7312,7354,1,7357,7359,1,7401,7404,1,7406,7411,1,7413,7414,1,7418,7424,6,7425,7615,1,7680,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8124,1,8126,8130,4,8131,8132,1,8134,8140,1,8144,8147,1,8150,8155,1,8160,8172,1,8178,8180,1,8182,8188,1,8305,8319,14,8336,8348,1,8450,8455,5,8458,8467,1,8469,8473,4,8474,8477,1,8484,8490,2,8491,8493,1,8495,8505,1,8508,8511,1,8517,8521,1,8526,8579,53,8580,11264,2684,11265,11492,1,11499,11502,1,11506,11507,1,11520,11557,1,11559,11565,6,11568,11623,1,11631,11648,17,11649,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,11823,12293,470,12294,12337,43,12338,12341,1,12347,12348,1,12353,12438,1,12445,12447,1,12449,12538,1,12540,12543,1,12549,12591,1,12593,12686,1,12704,12735,1,12784,12799,1,13312,19903,1,19968,42124,1,42192,42237,1,42240,42508,1,42512,42527,1,42538,42539,1,42560,42606,1,42623,42653,1,42656,42725,1,42775,42783,1,42786,42888,1,42891,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43009,1,43011,43013,1,43015,43018,1,43020,43042,1,43072,43123,1,43138,43187,1,43250,43255,1,43259,43261,2,43262,43274,12,43275,43301,1,43312,43334,1,43360,43388,1,43396,43442,1,43471,43488,17,43489,43492,1,43494,43503,1,43514,43518,1,43520,43560,1,43584,43586,1,43588,43595,1,43616,43638,1,43642,43646,4,43647,43695,1,43697,43701,4,43702,43705,3,43706,43709,1,43712,43714,2,43739,43741,1,43744,43754,1,43762,43764,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43824,43866,1,43868,43881,1,43888,44002,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64256,64262,1,64275,64279,1,64285,64287,2,64288,64296,1,64298,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64433,1,64467,64829,1,64848,64911,1,64914,64967,1,65008,65019,1,65136,65140,1,65142,65276,1,65313,65338,1,65345,65370,1,65382,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,66176,66204,1,66208,66256,1,66304,66335,1,66349,66368,1,66370,66377,1,66384,66421,1,66432,66461,1,66464,66499,1,66504,66511,1,66560,66717,1,66736,66771,1,66776,66811,1,66816,66855,1,66864,66915,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67456,67461,1,67463,67504,1,67506,67514,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67680,67702,1,67712,67742,1,67808,67826,1,67828,67829,1,67840,67861,1,67872,67897,1,67968,68023,1,68030,68031,1,68096,68112,16,68113,68115,1,68117,68119,1,68121,68149,1,68192,68220,1,68224,68252,1,68288,68295,1,68297,68324,1,68352,68405,1,68416,68437,1,68448,68466,1,68480,68497,1,68608,68680,1,68736,68786,1,68800,68850,1,68864,68899,1,68938,68965,1,68975,68997,1,69248,69289,1,69296,69297,1,69314,69316,1,69376,69404,1,69415,69424,9,69425,69445,1,69488,69505,1,69552,69572,1,69600,69622,1,69635,69687,1,69745,69746,1,69749,69763,14,69764,69807,1,69840,69864,1,69891,69926,1,69956,69959,3,69968,70002,1,70006,70019,13,70020,70066,1,70081,70084,1,70106,70108,2,70144,70161,1,70163,70187,1,70207,70208,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70312,1,70320,70366,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70461,70480,19,70493,70497,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70609,26,70611,70656,45,70657,70708,1,70727,70730,1,70751,70753,1,70784,70831,1,70852,70853,1,70855,71040,185,71041,71086,1,71128,71131,1,71168,71215,1,71236,71296,60,71297,71338,1,71352,71424,72,71425,71450,1,71488,71494,1,71680,71723,1,71840,71903,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71983,1,71999,72001,2,72096,72103,1,72106,72144,1,72161,72163,2,72192,72203,11,72204,72242,1,72250,72272,22,72284,72329,1,72349,72368,19,72369,72440,1,72640,72672,1,72704,72712,1,72714,72750,1,72768,72818,50,72819,72847,1,72960,72966,1,72968,72969,1,72971,73008,1,73030,73056,26,73057,73061,1,73063,73064,1,73066,73097,1,73112,73440,328,73441,73458,1,73474,73476,2,73477,73488,1,73490,73523,1,73648,73728,80,73729,74649,1,74880,75075,1,77712,77808,1,77824,78895,1,78913,78918,1,78944,82938,1,82944,83526,1,90368,90397,1,92160,92728,1,92736,92766,1,92784,92862,1,92880,92909,1,92928,92975,1,92992,92995,1,93027,93047,1,93053,93071,1,93504,93548,1,93760,93823,1,93952,94026,1,94032,94099,67,94100,94111,1,94176,94177,1,94179,94208,29,94209,100343,1,100352,101589,1,101631,101640,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120512,1,120514,120538,1,120540,120570,1,120572,120596,1,120598,120628,1,120630,120654,1,120656,120686,1,120688,120712,1,120714,120744,1,120746,120770,1,120772,120779,1,122624,122654,1,122661,122666,1,122928,122989,1,123136,123180,1,123191,123197,1,123214,123536,322,123537,123565,1,123584,123627,1,124112,124139,1,124368,124397,1,124400,124896,496,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,125184,125251,1,125259,126464,1205,126465,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static foldL=new k(new Uint32Array([837,837,1]));static Ll=new k(new Uint32Array([97,122,1,181,223,42,224,246,1,248,255,1,257,311,2,312,328,2,329,375,2,378,382,2,383,384,1,387,389,2,392,396,4,397,402,5,405,409,4,410,411,1,414,417,3,419,421,2,424,426,2,427,429,2,432,436,4,438,441,3,442,445,3,446,447,1,454,460,3,462,476,2,477,495,2,496,499,3,501,505,4,507,563,2,564,569,1,572,575,3,576,578,2,583,591,2,592,659,1,661,687,1,881,883,2,887,891,4,892,893,1,912,940,28,941,974,1,976,977,1,981,983,1,985,1007,2,1008,1011,1,1013,1019,3,1020,1072,52,1073,1119,1,1121,1153,2,1163,1215,2,1218,1230,2,1231,1327,2,1376,1416,1,4304,4346,1,4349,4351,1,5112,5117,1,7296,7304,1,7306,7424,118,7425,7467,1,7531,7543,1,7545,7578,1,7681,7829,2,7830,7837,1,7839,7935,2,7936,7943,1,7952,7957,1,7968,7975,1,7984,7991,1,8e3,8005,1,8016,8023,1,8032,8039,1,8048,8061,1,8064,8071,1,8080,8087,1,8096,8103,1,8112,8116,1,8118,8119,1,8126,8130,4,8131,8132,1,8134,8135,1,8144,8147,1,8150,8151,1,8160,8167,1,8178,8180,1,8182,8183,1,8458,8462,4,8463,8467,4,8495,8505,5,8508,8509,1,8518,8521,1,8526,8580,54,11312,11359,1,11361,11365,4,11366,11372,2,11377,11379,2,11380,11382,2,11383,11387,1,11393,11491,2,11492,11500,8,11502,11507,5,11520,11557,1,11559,11565,6,42561,42605,2,42625,42651,2,42787,42799,2,42800,42801,1,42803,42865,2,42866,42872,1,42874,42876,2,42879,42887,2,42892,42894,2,42897,42899,2,42900,42901,1,42903,42921,2,42927,42933,6,42935,42947,2,42952,42954,2,42957,42961,4,42963,42971,2,42998,43002,4,43824,43866,1,43872,43880,1,43888,43967,1,64256,64262,1,64275,64279,1,65345,65370,1,66600,66639,1,66776,66811,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,68800,68850,1,68976,68997,1,71872,71903,1,93792,93823,1,119834,119859,1,119886,119892,1,119894,119911,1,119938,119963,1,119990,119993,1,119995,119997,2,119998,120003,1,120005,120015,1,120042,120067,1,120094,120119,1,120146,120171,1,120198,120223,1,120250,120275,1,120302,120327,1,120354,120379,1,120406,120431,1,120458,120485,1,120514,120538,1,120540,120545,1,120572,120596,1,120598,120603,1,120630,120654,1,120656,120661,1,120688,120712,1,120714,120719,1,120746,120770,1,120772,120777,1,120779,122624,1845,122625,122633,1,122635,122654,1,122661,122666,1,125218,125251,1]));static foldLl=new k(new Uint32Array([65,90,1,192,214,1,216,222,1,256,302,2,306,310,2,313,327,2,330,376,2,377,381,2,385,386,1,388,390,2,391,393,2,394,395,1,398,401,1,403,404,1,406,408,1,412,413,1,415,416,1,418,422,2,423,425,2,428,430,2,431,433,2,434,435,1,437,439,2,440,444,4,452,453,1,455,456,1,458,459,1,461,475,2,478,494,2,497,498,1,500,502,2,503,504,1,506,562,2,570,571,1,573,574,1,577,579,2,580,582,1,584,590,2,837,880,43,882,886,4,895,902,7,904,906,1,908,910,2,911,913,2,914,929,1,931,939,1,975,984,9,986,1006,2,1012,1015,3,1017,1018,1,1021,1071,1,1120,1152,2,1162,1216,2,1217,1229,2,1232,1326,2,1329,1366,1,4256,4293,1,4295,4301,6,5024,5109,1,7305,7312,7,7313,7354,1,7357,7359,1,7680,7828,2,7838,7934,2,7944,7951,1,7960,7965,1,7976,7983,1,7992,7999,1,8008,8013,1,8025,8031,2,8040,8047,1,8072,8079,1,8088,8095,1,8104,8111,1,8120,8124,1,8136,8140,1,8152,8155,1,8168,8172,1,8184,8188,1,8486,8490,4,8491,8498,7,8579,11264,2685,11265,11311,1,11360,11362,2,11363,11364,1,11367,11373,2,11374,11376,1,11378,11381,3,11390,11392,1,11394,11490,2,11499,11501,2,11506,42560,31054,42562,42604,2,42624,42650,2,42786,42798,2,42802,42862,2,42873,42877,2,42878,42886,2,42891,42893,2,42896,42898,2,42902,42922,2,42923,42926,1,42928,42932,1,42934,42948,2,42949,42951,1,42953,42955,2,42956,42960,4,42966,42972,2,42997,65313,22316,65314,65338,1,66560,66599,1,66736,66771,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,68736,68786,1,68944,68965,1,71840,71871,1,93760,93791,1,125184,125217,1]));static Lm=new k(new Uint32Array([688,705,1,710,721,1,736,740,1,748,750,2,884,890,6,1369,1600,231,1765,1766,1,2036,2037,1,2042,2074,32,2084,2088,4,2249,2417,168,3654,3782,128,4348,6103,1755,6211,6823,612,7288,7293,1,7468,7530,1,7544,7579,35,7580,7615,1,8305,8319,14,8336,8348,1,11388,11389,1,11631,11823,192,12293,12337,44,12338,12341,1,12347,12445,98,12446,12540,94,12541,12542,1,40981,42232,1251,42233,42237,1,42508,42623,115,42652,42653,1,42775,42783,1,42864,42888,24,42994,42996,1,43e3,43001,1,43471,43494,23,43632,43741,109,43763,43764,1,43868,43871,1,43881,65392,21511,65438,65439,1,67456,67461,1,67463,67504,1,67506,67514,1,68942,68975,33,92992,92995,1,93504,93506,1,93547,93548,1,94099,94111,1,94176,94177,1,94179,110576,16397,110577,110579,1,110581,110587,1,110589,110590,1,122928,122989,1,123191,123197,1,124139,125259,1120]));static Lo=new k(new Uint32Array([170,186,16,443,448,5,449,451,1,660,1488,828,1489,1514,1,1519,1522,1,1568,1599,1,1601,1610,1,1646,1647,1,1649,1747,1,1749,1774,25,1775,1786,11,1787,1788,1,1791,1808,17,1810,1839,1,1869,1957,1,1969,1994,25,1995,2026,1,2048,2069,1,2112,2136,1,2144,2154,1,2160,2183,1,2185,2190,1,2208,2248,1,2308,2361,1,2365,2384,19,2392,2401,1,2418,2432,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2493,2510,17,2524,2525,1,2527,2529,1,2544,2545,1,2556,2565,9,2566,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2649,2652,1,2654,2674,20,2675,2676,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2749,2768,19,2784,2785,1,2809,2821,12,2822,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2877,2908,31,2909,2911,2,2912,2913,1,2929,2947,18,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3024,3077,53,3078,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3133,3160,27,3161,3162,1,3165,3168,3,3169,3200,31,3205,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3261,3293,32,3294,3296,2,3297,3313,16,3314,3332,18,3333,3340,1,3342,3344,1,3346,3386,1,3389,3406,17,3412,3414,1,3423,3425,1,3450,3455,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3585,3632,1,3634,3635,1,3648,3653,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3760,1,3762,3763,1,3773,3776,3,3777,3780,1,3804,3807,1,3840,3904,64,3905,3911,1,3913,3948,1,3976,3980,1,4096,4138,1,4159,4176,17,4177,4181,1,4186,4189,1,4193,4197,4,4198,4206,8,4207,4208,1,4213,4225,1,4238,4352,114,4353,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4992,5007,1,5121,5740,1,5743,5759,1,5761,5786,1,5792,5866,1,5873,5880,1,5888,5905,1,5919,5937,1,5952,5969,1,5984,5996,1,5998,6e3,1,6016,6067,1,6108,6176,68,6177,6210,1,6212,6264,1,6272,6276,1,6279,6312,1,6314,6320,6,6321,6389,1,6400,6430,1,6480,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6656,6678,1,6688,6740,1,6917,6963,1,6981,6988,1,7043,7072,1,7086,7087,1,7098,7141,1,7168,7203,1,7245,7247,1,7258,7287,1,7401,7404,1,7406,7411,1,7413,7414,1,7418,8501,1083,8502,8504,1,11568,11623,1,11648,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,12294,12348,54,12353,12438,1,12447,12449,2,12450,12538,1,12543,12549,6,12550,12591,1,12593,12686,1,12704,12735,1,12784,12799,1,13312,19903,1,19968,40980,1,40982,42124,1,42192,42231,1,42240,42507,1,42512,42527,1,42538,42539,1,42606,42656,50,42657,42725,1,42895,42999,104,43003,43009,1,43011,43013,1,43015,43018,1,43020,43042,1,43072,43123,1,43138,43187,1,43250,43255,1,43259,43261,2,43262,43274,12,43275,43301,1,43312,43334,1,43360,43388,1,43396,43442,1,43488,43492,1,43495,43503,1,43514,43518,1,43520,43560,1,43584,43586,1,43588,43595,1,43616,43631,1,43633,43638,1,43642,43646,4,43647,43695,1,43697,43701,4,43702,43705,3,43706,43709,1,43712,43714,2,43739,43740,1,43744,43754,1,43762,43777,15,43778,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43968,44002,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64285,64287,2,64288,64296,1,64298,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64433,1,64467,64829,1,64848,64911,1,64914,64967,1,65008,65019,1,65136,65140,1,65142,65276,1,65382,65391,1,65393,65437,1,65440,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,66176,66204,1,66208,66256,1,66304,66335,1,66349,66368,1,66370,66377,1,66384,66421,1,66432,66461,1,66464,66499,1,66504,66511,1,66640,66717,1,66816,66855,1,66864,66915,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67680,67702,1,67712,67742,1,67808,67826,1,67828,67829,1,67840,67861,1,67872,67897,1,67968,68023,1,68030,68031,1,68096,68112,16,68113,68115,1,68117,68119,1,68121,68149,1,68192,68220,1,68224,68252,1,68288,68295,1,68297,68324,1,68352,68405,1,68416,68437,1,68448,68466,1,68480,68497,1,68608,68680,1,68864,68899,1,68938,68941,1,68943,69248,305,69249,69289,1,69296,69297,1,69314,69316,1,69376,69404,1,69415,69424,9,69425,69445,1,69488,69505,1,69552,69572,1,69600,69622,1,69635,69687,1,69745,69746,1,69749,69763,14,69764,69807,1,69840,69864,1,69891,69926,1,69956,69959,3,69968,70002,1,70006,70019,13,70020,70066,1,70081,70084,1,70106,70108,2,70144,70161,1,70163,70187,1,70207,70208,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70312,1,70320,70366,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70461,70480,19,70493,70497,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70609,26,70611,70656,45,70657,70708,1,70727,70730,1,70751,70753,1,70784,70831,1,70852,70853,1,70855,71040,185,71041,71086,1,71128,71131,1,71168,71215,1,71236,71296,60,71297,71338,1,71352,71424,72,71425,71450,1,71488,71494,1,71680,71723,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71983,1,71999,72001,2,72096,72103,1,72106,72144,1,72161,72163,2,72192,72203,11,72204,72242,1,72250,72272,22,72284,72329,1,72349,72368,19,72369,72440,1,72640,72672,1,72704,72712,1,72714,72750,1,72768,72818,50,72819,72847,1,72960,72966,1,72968,72969,1,72971,73008,1,73030,73056,26,73057,73061,1,73063,73064,1,73066,73097,1,73112,73440,328,73441,73458,1,73474,73476,2,73477,73488,1,73490,73523,1,73648,73728,80,73729,74649,1,74880,75075,1,77712,77808,1,77824,78895,1,78913,78918,1,78944,82938,1,82944,83526,1,90368,90397,1,92160,92728,1,92736,92766,1,92784,92862,1,92880,92909,1,92928,92975,1,93027,93047,1,93053,93071,1,93507,93546,1,93952,94026,1,94032,94208,176,94209,100343,1,100352,101589,1,101631,101640,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,122634,123136,502,123137,123180,1,123214,123536,322,123537,123565,1,123584,123627,1,124112,124138,1,124368,124397,1,124400,124896,496,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static Lt=new k(new Uint32Array([453,459,3,498,8072,7574,8073,8079,1,8088,8095,1,8104,8111,1,8124,8140,16,8188,8188,1]));static foldLt=new k(new Uint32Array([452,454,2,455,457,2,458,460,2,497,499,2,8064,8071,1,8080,8087,1,8096,8103,1,8115,8131,16,8179,8179,1]));static Lu=new k(new Uint32Array([65,90,1,192,214,1,216,222,1,256,310,2,313,327,2,330,376,2,377,381,2,385,386,1,388,390,2,391,393,2,394,395,1,398,401,1,403,404,1,406,408,1,412,413,1,415,416,1,418,422,2,423,425,2,428,430,2,431,433,2,434,435,1,437,439,2,440,444,4,452,461,3,463,475,2,478,494,2,497,500,3,502,504,1,506,562,2,570,571,1,573,574,1,577,579,2,580,582,1,584,590,2,880,882,2,886,895,9,902,904,2,905,906,1,908,910,2,911,913,2,914,929,1,931,939,1,975,978,3,979,980,1,984,1006,2,1012,1015,3,1017,1018,1,1021,1071,1,1120,1152,2,1162,1216,2,1217,1229,2,1232,1326,2,1329,1366,1,4256,4293,1,4295,4301,6,5024,5109,1,7305,7312,7,7313,7354,1,7357,7359,1,7680,7828,2,7838,7934,2,7944,7951,1,7960,7965,1,7976,7983,1,7992,7999,1,8008,8013,1,8025,8031,2,8040,8047,1,8120,8123,1,8136,8139,1,8152,8155,1,8168,8172,1,8184,8187,1,8450,8455,5,8459,8461,1,8464,8466,1,8469,8473,4,8474,8477,1,8484,8490,2,8491,8493,1,8496,8499,1,8510,8511,1,8517,8579,62,11264,11311,1,11360,11362,2,11363,11364,1,11367,11373,2,11374,11376,1,11378,11381,3,11390,11392,1,11394,11490,2,11499,11501,2,11506,42560,31054,42562,42604,2,42624,42650,2,42786,42798,2,42802,42862,2,42873,42877,2,42878,42886,2,42891,42893,2,42896,42898,2,42902,42922,2,42923,42926,1,42928,42932,1,42934,42948,2,42949,42951,1,42953,42955,2,42956,42960,4,42966,42972,2,42997,65313,22316,65314,65338,1,66560,66599,1,66736,66771,1,66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,68736,68786,1,68944,68965,1,71840,71871,1,93760,93791,1,119808,119833,1,119860,119885,1,119912,119937,1,119964,119966,2,119967,119973,3,119974,119977,3,119978,119980,1,119982,119989,1,120016,120041,1,120068,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120120,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120172,120197,1,120224,120249,1,120276,120301,1,120328,120353,1,120380,120405,1,120432,120457,1,120488,120512,1,120546,120570,1,120604,120628,1,120662,120686,1,120720,120744,1,120778,125184,4406,125185,125217,1]));static Upper=this.Lu;static foldLu=new k(new Uint32Array([97,122,1,181,223,42,224,246,1,248,255,1,257,303,2,307,311,2,314,328,2,331,375,2,378,382,2,383,384,1,387,389,2,392,396,4,402,405,3,409,411,1,414,417,3,419,421,2,424,429,5,432,436,4,438,441,3,445,447,2,453,454,1,456,457,1,459,460,1,462,476,2,477,495,2,498,499,1,501,505,4,507,543,2,547,563,2,572,575,3,576,578,2,583,591,2,592,596,1,598,599,1,601,603,2,604,608,4,609,611,2,612,614,1,616,620,1,623,625,2,626,629,3,637,640,3,642,643,1,647,652,1,658,669,11,670,837,167,881,883,2,887,891,4,892,893,1,940,943,1,945,974,1,976,977,1,981,983,1,985,1007,2,1008,1011,1,1013,1019,3,1072,1119,1,1121,1153,2,1163,1215,2,1218,1230,2,1231,1327,2,1377,1414,1,4304,4346,1,4349,4351,1,5112,5117,1,7296,7304,1,7306,7545,239,7549,7566,17,7681,7829,2,7835,7841,6,7843,7935,2,7936,7943,1,7952,7957,1,7968,7975,1,7984,7991,1,8e3,8005,1,8017,8023,2,8032,8039,1,8048,8061,1,8112,8113,1,8126,8144,18,8145,8160,15,8161,8165,4,8526,8580,54,11312,11359,1,11361,11365,4,11366,11372,2,11379,11382,3,11393,11491,2,11500,11502,2,11507,11520,13,11521,11557,1,11559,11565,6,42561,42605,2,42625,42651,2,42787,42799,2,42803,42863,2,42874,42876,2,42879,42887,2,42892,42897,5,42899,42900,1,42903,42921,2,42933,42947,2,42952,42954,2,42957,42961,4,42967,42971,2,42998,43859,861,43888,43967,1,65345,65370,1,66600,66639,1,66776,66811,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,68800,68850,1,68976,68997,1,71872,71903,1,93792,93823,1,125218,125251,1]));static M=new k(new Uint32Array([768,879,1,1155,1161,1,1425,1469,1,1471,1473,2,1474,1476,2,1477,1479,2,1552,1562,1,1611,1631,1,1648,1750,102,1751,1756,1,1759,1764,1,1767,1768,1,1770,1773,1,1809,1840,31,1841,1866,1,1958,1968,1,2027,2035,1,2045,2070,25,2071,2073,1,2075,2083,1,2085,2087,1,2089,2093,1,2137,2139,1,2199,2207,1,2250,2273,1,2275,2307,1,2362,2364,1,2366,2383,1,2385,2391,1,2402,2403,1,2433,2435,1,2492,2494,2,2495,2500,1,2503,2504,1,2507,2509,1,2519,2530,11,2531,2558,27,2561,2563,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2672,31,2673,2677,4,2689,2691,1,2748,2750,2,2751,2757,1,2759,2761,1,2763,2765,1,2786,2787,1,2810,2815,1,2817,2819,1,2876,2878,2,2879,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2914,2915,1,2946,3006,60,3007,3010,1,3014,3016,1,3018,3021,1,3031,3072,41,3073,3076,1,3132,3134,2,3135,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3170,3171,1,3201,3203,1,3260,3262,2,3263,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3298,3299,1,3315,3328,13,3329,3331,1,3387,3388,1,3390,3396,1,3398,3400,1,3402,3405,1,3415,3426,11,3427,3457,30,3458,3459,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3570,3571,1,3633,3636,3,3637,3642,1,3655,3662,1,3761,3764,3,3765,3772,1,3784,3790,1,3864,3865,1,3893,3897,2,3902,3903,1,3953,3972,1,3974,3975,1,3981,3991,1,3993,4028,1,4038,4139,101,4140,4158,1,4182,4185,1,4190,4192,1,4194,4196,1,4199,4205,1,4209,4212,1,4226,4237,1,4239,4250,11,4251,4253,1,4957,4959,1,5906,5909,1,5938,5940,1,5970,5971,1,6002,6003,1,6068,6099,1,6109,6155,46,6156,6157,1,6159,6277,118,6278,6313,35,6432,6443,1,6448,6459,1,6679,6683,1,6741,6750,1,6752,6780,1,6783,6832,49,6833,6862,1,6912,6916,1,6964,6980,1,7019,7027,1,7040,7042,1,7073,7085,1,7142,7155,1,7204,7223,1,7376,7378,1,7380,7400,1,7405,7412,7,7415,7417,1,7616,7679,1,8400,8432,1,11503,11505,1,11647,11744,97,11745,11775,1,12330,12335,1,12441,12442,1,42607,42610,1,42612,42621,1,42654,42655,1,42736,42737,1,43010,43014,4,43019,43043,24,43044,43047,1,43052,43136,84,43137,43188,51,43189,43205,1,43232,43249,1,43263,43302,39,43303,43309,1,43335,43347,1,43392,43395,1,43443,43456,1,43493,43561,68,43562,43574,1,43587,43596,9,43597,43643,46,43644,43645,1,43696,43698,2,43699,43700,1,43703,43704,1,43710,43711,1,43713,43755,42,43756,43759,1,43765,43766,1,44003,44010,1,44012,44013,1,64286,65024,738,65025,65039,1,65056,65071,1,66045,66272,227,66422,66426,1,68097,68099,1,68101,68102,1,68108,68111,1,68152,68154,1,68159,68325,166,68326,68900,574,68901,68903,1,68969,68973,1,69291,69292,1,69372,69375,1,69446,69456,1,69506,69509,1,69632,69634,1,69688,69702,1,69744,69747,3,69748,69759,11,69760,69762,1,69808,69818,1,69826,69888,62,69889,69890,1,69927,69940,1,69957,69958,1,70003,70016,13,70017,70018,1,70067,70080,1,70089,70092,1,70094,70095,1,70188,70199,1,70206,70209,3,70367,70378,1,70400,70403,1,70459,70460,1,70462,70468,1,70471,70472,1,70475,70477,1,70487,70498,11,70499,70502,3,70503,70508,1,70512,70516,1,70584,70592,1,70594,70597,3,70599,70602,1,70604,70608,1,70610,70625,15,70626,70709,83,70710,70726,1,70750,70832,82,70833,70851,1,71087,71093,1,71096,71104,1,71132,71133,1,71216,71232,1,71339,71351,1,71453,71467,1,71724,71738,1,71984,71989,1,71991,71992,1,71995,71998,1,72e3,72002,2,72003,72145,142,72146,72151,1,72154,72160,1,72164,72193,29,72194,72202,1,72243,72249,1,72251,72254,1,72263,72273,10,72274,72283,1,72330,72345,1,72751,72758,1,72760,72767,1,72850,72871,1,72873,72886,1,73009,73014,1,73018,73020,2,73021,73023,2,73024,73029,1,73031,73098,67,73099,73102,1,73104,73105,1,73107,73111,1,73459,73462,1,73472,73473,1,73475,73524,49,73525,73530,1,73534,73538,1,73562,78912,5350,78919,78933,1,90398,90415,1,92912,92916,1,92976,92982,1,94031,94033,2,94034,94087,1,94095,94098,1,94180,94192,12,94193,113821,19628,113822,118528,4706,118529,118573,1,118576,118598,1,119141,119145,1,119149,119154,1,119163,119170,1,119173,119179,1,119210,119213,1,119362,119364,1,121344,121398,1,121403,121452,1,121461,121476,15,121499,121503,1,121505,121519,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,123023,123184,161,123185,123190,1,123566,123628,62,123629,123631,1,124140,124143,1,124398,124399,1,125136,125142,1,125252,125258,1,917760,917999,1]));static foldM=new k(new Uint32Array([921,953,32,8126,8126,1]));static Mc=new k(new Uint32Array([2307,2363,56,2366,2368,1,2377,2380,1,2382,2383,1,2434,2435,1,2494,2496,1,2503,2504,1,2507,2508,1,2519,2563,44,2622,2624,1,2691,2750,59,2751,2752,1,2761,2763,2,2764,2818,54,2819,2878,59,2880,2887,7,2888,2891,3,2892,2903,11,3006,3007,1,3009,3010,1,3014,3016,1,3018,3020,1,3031,3073,42,3074,3075,1,3137,3140,1,3202,3203,1,3262,3264,2,3265,3268,1,3271,3272,1,3274,3275,1,3285,3286,1,3315,3330,15,3331,3390,59,3391,3392,1,3398,3400,1,3402,3404,1,3415,3458,43,3459,3535,76,3536,3537,1,3544,3551,1,3570,3571,1,3902,3903,1,3967,4139,172,4140,4145,5,4152,4155,3,4156,4182,26,4183,4194,11,4195,4196,1,4199,4205,1,4227,4228,1,4231,4236,1,4239,4250,11,4251,4252,1,5909,5940,31,6070,6078,8,6079,6085,1,6087,6088,1,6435,6438,1,6441,6443,1,6448,6449,1,6451,6456,1,6681,6682,1,6741,6743,2,6753,6755,2,6756,6765,9,6766,6770,1,6916,6965,49,6971,6973,2,6974,6977,1,6979,6980,1,7042,7073,31,7078,7079,1,7082,7143,61,7146,7148,1,7150,7154,4,7155,7204,49,7205,7211,1,7220,7221,1,7393,7415,22,12334,12335,1,43043,43044,1,43047,43136,89,43137,43188,51,43189,43203,1,43346,43347,1,43395,43444,49,43445,43450,5,43451,43454,3,43455,43456,1,43567,43568,1,43571,43572,1,43597,43643,46,43645,43755,110,43758,43759,1,43765,44003,238,44004,44006,2,44007,44009,2,44010,44012,2,69632,69634,2,69762,69808,46,69809,69810,1,69815,69816,1,69932,69957,25,69958,70018,60,70067,70069,1,70079,70080,1,70094,70188,94,70189,70190,1,70194,70195,1,70197,70368,171,70369,70370,1,70402,70403,1,70462,70463,1,70465,70468,1,70471,70472,1,70475,70477,1,70487,70498,11,70499,70584,85,70585,70586,1,70594,70597,3,70599,70602,1,70604,70605,1,70607,70709,102,70710,70711,1,70720,70721,1,70725,70832,107,70833,70834,1,70841,70843,2,70844,70846,1,70849,71087,238,71088,71089,1,71096,71099,1,71102,71216,114,71217,71218,1,71227,71228,1,71230,71340,110,71342,71343,1,71350,71454,104,71456,71457,1,71462,71724,262,71725,71726,1,71736,71984,248,71985,71989,1,71991,71992,1,71997,72e3,3,72002,72145,143,72146,72147,1,72156,72159,1,72164,72249,85,72279,72280,1,72343,72751,408,72766,72873,107,72881,72884,3,73098,73102,1,73107,73108,1,73110,73461,351,73462,73475,13,73524,73525,1,73534,73535,1,73537,90410,16873,90411,90412,1,94033,94087,1,94192,94193,1,119141,119142,1,119149,119154,1]));static Me=new k(new Uint32Array([1160,1161,1,6846,8413,1567,8414,8416,1,8418,8420,1,42608,42610,1]));static Mn=new k(new Uint32Array([768,879,1,1155,1159,1,1425,1469,1,1471,1473,2,1474,1476,2,1477,1479,2,1552,1562,1,1611,1631,1,1648,1750,102,1751,1756,1,1759,1764,1,1767,1768,1,1770,1773,1,1809,1840,31,1841,1866,1,1958,1968,1,2027,2035,1,2045,2070,25,2071,2073,1,2075,2083,1,2085,2087,1,2089,2093,1,2137,2139,1,2199,2207,1,2250,2273,1,2275,2306,1,2362,2364,2,2369,2376,1,2381,2385,4,2386,2391,1,2402,2403,1,2433,2492,59,2497,2500,1,2509,2530,21,2531,2558,27,2561,2562,1,2620,2625,5,2626,2631,5,2632,2635,3,2636,2637,1,2641,2672,31,2673,2677,4,2689,2690,1,2748,2753,5,2754,2757,1,2759,2760,1,2765,2786,21,2787,2810,23,2811,2815,1,2817,2876,59,2879,2881,2,2882,2884,1,2893,2901,8,2902,2914,12,2915,2946,31,3008,3021,13,3072,3076,4,3132,3134,2,3135,3136,1,3142,3144,1,3146,3149,1,3157,3158,1,3170,3171,1,3201,3260,59,3263,3270,7,3276,3277,1,3298,3299,1,3328,3329,1,3387,3388,1,3393,3396,1,3405,3426,21,3427,3457,30,3530,3538,8,3539,3540,1,3542,3633,91,3636,3642,1,3655,3662,1,3761,3764,3,3765,3772,1,3784,3790,1,3864,3865,1,3893,3897,2,3953,3966,1,3968,3972,1,3974,3975,1,3981,3991,1,3993,4028,1,4038,4141,103,4142,4144,1,4146,4151,1,4153,4154,1,4157,4158,1,4184,4185,1,4190,4192,1,4209,4212,1,4226,4229,3,4230,4237,7,4253,4957,704,4958,4959,1,5906,5908,1,5938,5939,1,5970,5971,1,6002,6003,1,6068,6069,1,6071,6077,1,6086,6089,3,6090,6099,1,6109,6155,46,6156,6157,1,6159,6277,118,6278,6313,35,6432,6434,1,6439,6440,1,6450,6457,7,6458,6459,1,6679,6680,1,6683,6742,59,6744,6750,1,6752,6754,2,6757,6764,1,6771,6780,1,6783,6832,49,6833,6845,1,6847,6862,1,6912,6915,1,6964,6966,2,6967,6970,1,6972,6978,6,7019,7027,1,7040,7041,1,7074,7077,1,7080,7081,1,7083,7085,1,7142,7144,2,7145,7149,4,7151,7153,1,7212,7219,1,7222,7223,1,7376,7378,1,7380,7392,1,7394,7400,1,7405,7412,7,7416,7417,1,7616,7679,1,8400,8412,1,8417,8421,4,8422,8432,1,11503,11505,1,11647,11744,97,11745,11775,1,12330,12333,1,12441,12442,1,42607,42612,5,42613,42621,1,42654,42655,1,42736,42737,1,43010,43014,4,43019,43045,26,43046,43052,6,43204,43205,1,43232,43249,1,43263,43302,39,43303,43309,1,43335,43345,1,43392,43394,1,43443,43446,3,43447,43449,1,43452,43453,1,43493,43561,68,43562,43566,1,43569,43570,1,43573,43574,1,43587,43596,9,43644,43696,52,43698,43700,1,43703,43704,1,43710,43711,1,43713,43756,43,43757,43766,9,44005,44008,3,44013,64286,20273,65024,65039,1,65056,65071,1,66045,66272,227,66422,66426,1,68097,68099,1,68101,68102,1,68108,68111,1,68152,68154,1,68159,68325,166,68326,68900,574,68901,68903,1,68969,68973,1,69291,69292,1,69372,69375,1,69446,69456,1,69506,69509,1,69633,69688,55,69689,69702,1,69744,69747,3,69748,69759,11,69760,69761,1,69811,69814,1,69817,69818,1,69826,69888,62,69889,69890,1,69927,69931,1,69933,69940,1,70003,70016,13,70017,70070,53,70071,70078,1,70089,70092,1,70095,70191,96,70192,70193,1,70196,70198,2,70199,70206,7,70209,70367,158,70371,70378,1,70400,70401,1,70459,70460,1,70464,70502,38,70503,70508,1,70512,70516,1,70587,70592,1,70606,70610,2,70625,70626,1,70712,70719,1,70722,70724,1,70726,70750,24,70835,70840,1,70842,70847,5,70848,70850,2,70851,71090,239,71091,71093,1,71100,71101,1,71103,71104,1,71132,71133,1,71219,71226,1,71229,71231,2,71232,71339,107,71341,71344,3,71345,71349,1,71351,71453,102,71455,71458,3,71459,71461,1,71463,71467,1,71727,71735,1,71737,71738,1,71995,71996,1,71998,72003,5,72148,72151,1,72154,72155,1,72160,72193,33,72194,72202,1,72243,72248,1,72251,72254,1,72263,72273,10,72274,72278,1,72281,72283,1,72330,72342,1,72344,72345,1,72752,72758,1,72760,72765,1,72767,72850,83,72851,72871,1,72874,72880,1,72882,72883,1,72885,72886,1,73009,73014,1,73018,73020,2,73021,73023,2,73024,73029,1,73031,73104,73,73105,73109,4,73111,73459,348,73460,73472,12,73473,73526,53,73527,73530,1,73536,73538,2,73562,78912,5350,78919,78933,1,90398,90409,1,90413,90415,1,92912,92916,1,92976,92982,1,94031,94095,64,94096,94098,1,94180,113821,19641,113822,118528,4706,118529,118573,1,118576,118598,1,119143,119145,1,119163,119170,1,119173,119179,1,119210,119213,1,119362,119364,1,121344,121398,1,121403,121452,1,121461,121476,15,121499,121503,1,121505,121519,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,123023,123184,161,123185,123190,1,123566,123628,62,123629,123631,1,124140,124143,1,124398,124399,1,125136,125142,1,125252,125258,1,917760,917999,1]));static foldMn=new k(new Uint32Array([921,953,32,8126,8126,1]));static N=new k(new Uint32Array([48,57,1,178,179,1,185,188,3,189,190,1,1632,1641,1,1776,1785,1,1984,1993,1,2406,2415,1,2534,2543,1,2548,2553,1,2662,2671,1,2790,2799,1,2918,2927,1,2930,2935,1,3046,3058,1,3174,3183,1,3192,3198,1,3302,3311,1,3416,3422,1,3430,3448,1,3558,3567,1,3664,3673,1,3792,3801,1,3872,3891,1,4160,4169,1,4240,4249,1,4969,4988,1,5870,5872,1,6112,6121,1,6128,6137,1,6160,6169,1,6470,6479,1,6608,6618,1,6784,6793,1,6800,6809,1,6992,7001,1,7088,7097,1,7232,7241,1,7248,7257,1,8304,8308,4,8309,8313,1,8320,8329,1,8528,8578,1,8581,8585,1,9312,9371,1,9450,9471,1,10102,10131,1,11517,12295,778,12321,12329,1,12344,12346,1,12690,12693,1,12832,12841,1,12872,12879,1,12881,12895,1,12928,12937,1,12977,12991,1,42528,42537,1,42726,42735,1,43056,43061,1,43216,43225,1,43264,43273,1,43472,43481,1,43504,43513,1,43600,43609,1,44016,44025,1,65296,65305,1,65799,65843,1,65856,65912,1,65930,65931,1,66273,66299,1,66336,66339,1,66369,66378,9,66513,66517,1,66720,66729,1,67672,67679,1,67705,67711,1,67751,67759,1,67835,67839,1,67862,67867,1,68028,68029,1,68032,68047,1,68050,68095,1,68160,68168,1,68221,68222,1,68253,68255,1,68331,68335,1,68440,68447,1,68472,68479,1,68521,68527,1,68858,68863,1,68912,68921,1,68928,68937,1,69216,69246,1,69405,69414,1,69457,69460,1,69573,69579,1,69714,69743,1,69872,69881,1,69942,69951,1,70096,70105,1,70113,70132,1,70384,70393,1,70736,70745,1,70864,70873,1,71248,71257,1,71360,71369,1,71376,71395,1,71472,71483,1,71904,71922,1,72016,72025,1,72688,72697,1,72784,72812,1,73040,73049,1,73120,73129,1,73552,73561,1,73664,73684,1,74752,74862,1,90416,90425,1,92768,92777,1,92864,92873,1,93008,93017,1,93019,93025,1,93552,93561,1,93824,93846,1,118e3,118009,1,119488,119507,1,119520,119539,1,119648,119672,1,120782,120831,1,123200,123209,1,123632,123641,1,124144,124153,1,124401,124410,1,125127,125135,1,125264,125273,1,126065,126123,1,126125,126127,1,126129,126132,1,126209,126253,1,126255,126269,1,127232,127244,1,130032,130041,1]));static Nd=new k(new Uint32Array([48,57,1,1632,1641,1,1776,1785,1,1984,1993,1,2406,2415,1,2534,2543,1,2662,2671,1,2790,2799,1,2918,2927,1,3046,3055,1,3174,3183,1,3302,3311,1,3430,3439,1,3558,3567,1,3664,3673,1,3792,3801,1,3872,3881,1,4160,4169,1,4240,4249,1,6112,6121,1,6160,6169,1,6470,6479,1,6608,6617,1,6784,6793,1,6800,6809,1,6992,7001,1,7088,7097,1,7232,7241,1,7248,7257,1,42528,42537,1,43216,43225,1,43264,43273,1,43472,43481,1,43504,43513,1,43600,43609,1,44016,44025,1,65296,65305,1,66720,66729,1,68912,68921,1,68928,68937,1,69734,69743,1,69872,69881,1,69942,69951,1,70096,70105,1,70384,70393,1,70736,70745,1,70864,70873,1,71248,71257,1,71360,71369,1,71376,71395,1,71472,71481,1,71904,71913,1,72016,72025,1,72688,72697,1,72784,72793,1,73040,73049,1,73120,73129,1,73552,73561,1,90416,90425,1,92768,92777,1,92864,92873,1,93008,93017,1,93552,93561,1,118e3,118009,1,120782,120831,1,123200,123209,1,123632,123641,1,124144,124153,1,124401,124410,1,125264,125273,1,130032,130041,1]));static Nl=new k(new Uint32Array([5870,5872,1,8544,8578,1,8581,8584,1,12295,12321,26,12322,12329,1,12344,12346,1,42726,42735,1,65856,65908,1,66369,66378,9,66513,66517,1,74752,74862,1]));static No=new k(new Uint32Array([178,179,1,185,188,3,189,190,1,2548,2553,1,2930,2935,1,3056,3058,1,3192,3198,1,3416,3422,1,3440,3448,1,3882,3891,1,4969,4988,1,6128,6137,1,6618,8304,1686,8308,8313,1,8320,8329,1,8528,8543,1,8585,9312,727,9313,9371,1,9450,9471,1,10102,10131,1,11517,12690,1173,12691,12693,1,12832,12841,1,12872,12879,1,12881,12895,1,12928,12937,1,12977,12991,1,43056,43061,1,65799,65843,1,65909,65912,1,65930,65931,1,66273,66299,1,66336,66339,1,67672,67679,1,67705,67711,1,67751,67759,1,67835,67839,1,67862,67867,1,68028,68029,1,68032,68047,1,68050,68095,1,68160,68168,1,68221,68222,1,68253,68255,1,68331,68335,1,68440,68447,1,68472,68479,1,68521,68527,1,68858,68863,1,69216,69246,1,69405,69414,1,69457,69460,1,69573,69579,1,69714,69733,1,70113,70132,1,71482,71483,1,71914,71922,1,72794,72812,1,73664,73684,1,93019,93025,1,93824,93846,1,119488,119507,1,119520,119539,1,119648,119672,1,125127,125135,1,126065,126123,1,126125,126127,1,126129,126132,1,126209,126253,1,126255,126269,1,127232,127244,1]));static P=new k(new Uint32Array([33,35,1,37,42,1,44,47,1,58,59,1,63,64,1,91,93,1,95,123,28,125,161,36,167,171,4,182,183,1,187,191,4,894,903,9,1370,1375,1,1417,1418,1,1470,1472,2,1475,1478,3,1523,1524,1,1545,1546,1,1548,1549,1,1563,1565,2,1566,1567,1,1642,1645,1,1748,1792,44,1793,1805,1,2039,2041,1,2096,2110,1,2142,2404,262,2405,2416,11,2557,2678,121,2800,3191,391,3204,3572,368,3663,3674,11,3675,3844,169,3845,3858,1,3860,3898,38,3899,3901,1,3973,4048,75,4049,4052,1,4057,4058,1,4170,4175,1,4347,4960,613,4961,4968,1,5120,5742,622,5787,5788,1,5867,5869,1,5941,5942,1,6100,6102,1,6104,6106,1,6144,6154,1,6468,6469,1,6686,6687,1,6816,6822,1,6824,6829,1,6990,6991,1,7002,7008,1,7037,7039,1,7164,7167,1,7227,7231,1,7294,7295,1,7360,7367,1,7379,8208,829,8209,8231,1,8240,8259,1,8261,8273,1,8275,8286,1,8317,8318,1,8333,8334,1,8968,8971,1,9001,9002,1,10088,10101,1,10181,10182,1,10214,10223,1,10627,10648,1,10712,10715,1,10748,10749,1,11513,11516,1,11518,11519,1,11632,11776,144,11777,11822,1,11824,11855,1,11858,11869,1,12289,12291,1,12296,12305,1,12308,12319,1,12336,12349,13,12448,12539,91,42238,42239,1,42509,42511,1,42611,42622,11,42738,42743,1,43124,43127,1,43214,43215,1,43256,43258,1,43260,43310,50,43311,43359,48,43457,43469,1,43486,43487,1,43612,43615,1,43742,43743,1,43760,43761,1,44011,64830,20819,64831,65040,209,65041,65049,1,65072,65106,1,65108,65121,1,65123,65128,5,65130,65131,1,65281,65283,1,65285,65290,1,65292,65295,1,65306,65307,1,65311,65312,1,65339,65341,1,65343,65371,28,65373,65375,2,65376,65381,1,65792,65794,1,66463,66512,49,66927,67671,744,67871,67903,32,68176,68184,1,68223,68336,113,68337,68342,1,68409,68415,1,68505,68508,1,68974,69293,319,69461,69465,1,69510,69513,1,69703,69709,1,69819,69820,1,69822,69825,1,69952,69955,1,70004,70005,1,70085,70088,1,70093,70107,14,70109,70111,1,70200,70205,1,70313,70612,299,70613,70615,2,70616,70731,115,70732,70735,1,70746,70747,1,70749,70854,105,71105,71127,1,71233,71235,1,71264,71276,1,71353,71484,131,71485,71486,1,71739,72004,265,72005,72006,1,72162,72255,93,72256,72262,1,72346,72348,1,72350,72354,1,72448,72457,1,72673,72769,96,72770,72773,1,72816,72817,1,73463,73464,1,73539,73551,1,73727,74864,1137,74865,74868,1,77809,77810,1,92782,92783,1,92917,92983,66,92984,92987,1,92996,93549,553,93550,93551,1,93847,93850,1,94178,113823,19645,121479,121483,1,124415,125278,863,125279,125279,1]));static Pc=new k(new Uint32Array([95,8255,8160,8256,8276,20,65075,65076,1,65101,65103,1,65343,65343,1]));static Pd=new k(new Uint32Array([45,1418,1373,1470,5120,3650,6150,8208,2058,8209,8213,1,11799,11802,3,11834,11835,1,11840,11869,29,12316,12336,20,12448,65073,52625,65074,65112,38,65123,65293,170,68974,69293,319]));static Pe=new k(new Uint32Array([41,93,52,125,3899,3774,3901,5788,1887,8262,8318,56,8334,8969,635,8971,9002,31,10089,10101,2,10182,10215,33,10217,10223,2,10628,10648,2,10713,10715,2,10749,11811,1062,11813,11817,2,11862,11868,2,12297,12305,2,12309,12315,2,12318,12319,1,64830,65048,218,65078,65092,2,65096,65114,18,65116,65118,2,65289,65341,52,65373,65379,3]));static Pf=new k(new Uint32Array([187,8217,8030,8221,8250,29,11779,11781,2,11786,11789,3,11805,11809,4]));static Pi=new k(new Uint32Array([171,8216,8045,8219,8220,1,8223,8249,26,11778,11780,2,11785,11788,3,11804,11808,4]));static Po=new k(new Uint32Array([33,35,1,37,39,1,42,46,2,47,58,11,59,63,4,64,92,28,161,167,6,182,183,1,191,894,703,903,1370,467,1371,1375,1,1417,1472,55,1475,1478,3,1523,1524,1,1545,1546,1,1548,1549,1,1563,1565,2,1566,1567,1,1642,1645,1,1748,1792,44,1793,1805,1,2039,2041,1,2096,2110,1,2142,2404,262,2405,2416,11,2557,2678,121,2800,3191,391,3204,3572,368,3663,3674,11,3675,3844,169,3845,3858,1,3860,3973,113,4048,4052,1,4057,4058,1,4170,4175,1,4347,4960,613,4961,4968,1,5742,5867,125,5868,5869,1,5941,5942,1,6100,6102,1,6104,6106,1,6144,6149,1,6151,6154,1,6468,6469,1,6686,6687,1,6816,6822,1,6824,6829,1,6990,6991,1,7002,7008,1,7037,7039,1,7164,7167,1,7227,7231,1,7294,7295,1,7360,7367,1,7379,8214,835,8215,8224,9,8225,8231,1,8240,8248,1,8251,8254,1,8257,8259,1,8263,8273,1,8275,8277,2,8278,8286,1,11513,11516,1,11518,11519,1,11632,11776,144,11777,11782,5,11783,11784,1,11787,11790,3,11791,11798,1,11800,11801,1,11803,11806,3,11807,11818,11,11819,11822,1,11824,11833,1,11836,11839,1,11841,11843,2,11844,11855,1,11858,11860,1,12289,12291,1,12349,12539,190,42238,42239,1,42509,42511,1,42611,42622,11,42738,42743,1,43124,43127,1,43214,43215,1,43256,43258,1,43260,43310,50,43311,43359,48,43457,43469,1,43486,43487,1,43612,43615,1,43742,43743,1,43760,43761,1,44011,65040,21029,65041,65046,1,65049,65072,23,65093,65094,1,65097,65100,1,65104,65106,1,65108,65111,1,65119,65121,1,65128,65130,2,65131,65281,150,65282,65283,1,65285,65287,1,65290,65294,2,65295,65306,11,65307,65311,4,65312,65340,28,65377,65380,3,65381,65792,411,65793,65794,1,66463,66512,49,66927,67671,744,67871,67903,32,68176,68184,1,68223,68336,113,68337,68342,1,68409,68415,1,68505,68508,1,69461,69465,1,69510,69513,1,69703,69709,1,69819,69820,1,69822,69825,1,69952,69955,1,70004,70005,1,70085,70088,1,70093,70107,14,70109,70111,1,70200,70205,1,70313,70612,299,70613,70615,2,70616,70731,115,70732,70735,1,70746,70747,1,70749,70854,105,71105,71127,1,71233,71235,1,71264,71276,1,71353,71484,131,71485,71486,1,71739,72004,265,72005,72006,1,72162,72255,93,72256,72262,1,72346,72348,1,72350,72354,1,72448,72457,1,72673,72769,96,72770,72773,1,72816,72817,1,73463,73464,1,73539,73551,1,73727,74864,1137,74865,74868,1,77809,77810,1,92782,92783,1,92917,92983,66,92984,92987,1,92996,93549,553,93550,93551,1,93847,93850,1,94178,113823,19645,121479,121483,1,124415,125278,863,125279,125279,1]));static Ps=new k(new Uint32Array([40,91,51,123,3898,3775,3900,5787,1887,8218,8222,4,8261,8317,56,8333,8968,635,8970,9001,31,10088,10100,2,10181,10214,33,10216,10222,2,10627,10647,2,10712,10714,2,10748,11810,1062,11812,11816,2,11842,11861,19,11863,11867,2,12296,12304,2,12308,12314,2,12317,64831,52514,65047,65077,30,65079,65091,2,65095,65113,18,65115,65117,2,65288,65339,51,65371,65375,4,65378,65378,1]));static S=new k(new Uint32Array([36,43,7,60,62,1,94,96,2,124,126,2,162,166,1,168,169,1,172,174,2,175,177,1,180,184,4,215,247,32,706,709,1,722,735,1,741,747,1,749,751,2,752,767,1,885,900,15,901,1014,113,1154,1421,267,1422,1423,1,1542,1544,1,1547,1550,3,1551,1758,207,1769,1789,20,1790,2038,248,2046,2047,1,2184,2546,362,2547,2554,7,2555,2801,246,2928,3059,131,3060,3066,1,3199,3407,208,3449,3647,198,3841,3843,1,3859,3861,2,3862,3863,1,3866,3871,1,3892,3896,2,4030,4037,1,4039,4044,1,4046,4047,1,4053,4056,1,4254,4255,1,5008,5017,1,5741,6107,366,6464,6622,158,6623,6655,1,7009,7018,1,7028,7036,1,8125,8127,2,8128,8129,1,8141,8143,1,8157,8159,1,8173,8175,1,8189,8190,1,8260,8274,14,8314,8316,1,8330,8332,1,8352,8384,1,8448,8449,1,8451,8454,1,8456,8457,1,8468,8470,2,8471,8472,1,8478,8483,1,8485,8489,2,8494,8506,12,8507,8512,5,8513,8516,1,8522,8525,1,8527,8586,59,8587,8592,5,8593,8967,1,8972,9e3,1,9003,9257,1,9280,9290,1,9372,9449,1,9472,10087,1,10132,10180,1,10183,10213,1,10224,10626,1,10649,10711,1,10716,10747,1,10750,11123,1,11126,11157,1,11159,11263,1,11493,11498,1,11856,11857,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12292,12306,14,12307,12320,13,12342,12343,1,12350,12351,1,12443,12444,1,12688,12689,1,12694,12703,1,12736,12773,1,12783,12800,17,12801,12830,1,12842,12871,1,12880,12896,16,12897,12927,1,12938,12976,1,12992,13311,1,19904,19967,1,42128,42182,1,42752,42774,1,42784,42785,1,42889,42890,1,43048,43051,1,43062,43065,1,43639,43641,1,43867,43882,15,43883,64297,20414,64434,64450,1,64832,64847,1,64975,65020,45,65021,65023,1,65122,65124,2,65125,65126,1,65129,65284,155,65291,65308,17,65309,65310,1,65342,65344,2,65372,65374,2,65504,65510,1,65512,65518,1,65532,65533,1,65847,65855,1,65913,65929,1,65932,65934,1,65936,65948,1,65952,66e3,48,66001,66044,1,67703,67704,1,68296,69006,710,69007,71487,2480,73685,73713,1,92988,92991,1,92997,113820,20823,117760,117999,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119140,1,119146,119148,1,119171,119172,1,119180,119209,1,119214,119274,1,119296,119361,1,119365,119552,187,119553,119638,1,120513,120539,26,120571,120597,26,120629,120655,26,120687,120713,26,120745,120771,26,120832,121343,1,121399,121402,1,121453,121460,1,121462,121475,1,121477,121478,1,123215,123647,432,126124,126128,4,126254,126704,450,126705,126976,271,126977,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127245,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130031,1]));static Sc=new k(new Uint32Array([36,162,126,163,165,1,1423,1547,124,2046,2047,1,2546,2547,1,2555,2801,246,3065,3647,582,6107,8352,2245,8353,8384,1,43064,65020,21956,65129,65284,155,65504,65505,1,65509,65510,1,73693,73696,1,123647,126128,2481]));static Sk=new k(new Uint32Array([94,96,2,168,175,7,180,184,4,706,709,1,722,735,1,741,747,1,749,751,2,752,767,1,885,900,15,901,2184,1283,8125,8127,2,8128,8129,1,8141,8143,1,8157,8159,1,8173,8175,1,8189,8190,1,12443,12444,1,42752,42774,1,42784,42785,1,42889,42890,1,43867,43882,15,43883,64434,20551,64435,64450,1,65342,65344,2,65507,127995,62488,127996,127999,1]));static Sm=new k(new Uint32Array([43,60,17,61,62,1,124,126,2,172,177,5,215,247,32,1014,1542,528,1543,1544,1,8260,8274,14,8314,8316,1,8330,8332,1,8472,8512,40,8513,8516,1,8523,8592,69,8593,8596,1,8602,8603,1,8608,8614,3,8622,8654,32,8655,8658,3,8660,8692,32,8693,8959,1,8992,8993,1,9084,9115,31,9116,9139,1,9180,9185,1,9655,9665,10,9720,9727,1,9839,10176,337,10177,10180,1,10183,10213,1,10224,10239,1,10496,10626,1,10649,10711,1,10716,10747,1,10750,11007,1,11056,11076,1,11079,11084,1,64297,65122,825,65124,65126,1,65291,65308,17,65309,65310,1,65372,65374,2,65506,65513,7,65514,65516,1,69006,69007,1,120513,120539,26,120571,120597,26,120629,120655,26,120687,120713,26,120745,120771,26,126704,126705,1]));static So=new k(new Uint32Array([166,169,3,174,176,2,1154,1421,267,1422,1550,128,1551,1758,207,1769,1789,20,1790,2038,248,2554,2928,374,3059,3064,1,3066,3199,133,3407,3449,42,3841,3843,1,3859,3861,2,3862,3863,1,3866,3871,1,3892,3896,2,4030,4037,1,4039,4044,1,4046,4047,1,4053,4056,1,4254,4255,1,5008,5017,1,5741,6464,723,6622,6655,1,7009,7018,1,7028,7036,1,8448,8449,1,8451,8454,1,8456,8457,1,8468,8470,2,8471,8478,7,8479,8483,1,8485,8489,2,8494,8506,12,8507,8522,15,8524,8525,1,8527,8586,59,8587,8597,10,8598,8601,1,8604,8607,1,8609,8610,1,8612,8613,1,8615,8621,1,8623,8653,1,8656,8657,1,8659,8661,2,8662,8691,1,8960,8967,1,8972,8991,1,8994,9e3,1,9003,9083,1,9085,9114,1,9140,9179,1,9186,9257,1,9280,9290,1,9372,9449,1,9472,9654,1,9656,9664,1,9666,9719,1,9728,9838,1,9840,10087,1,10132,10175,1,10240,10495,1,11008,11055,1,11077,11078,1,11085,11123,1,11126,11157,1,11159,11263,1,11493,11498,1,11856,11857,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12292,12306,14,12307,12320,13,12342,12343,1,12350,12351,1,12688,12689,1,12694,12703,1,12736,12773,1,12783,12800,17,12801,12830,1,12842,12871,1,12880,12896,16,12897,12927,1,12938,12976,1,12992,13311,1,19904,19967,1,42128,42182,1,43048,43051,1,43062,43063,1,43065,43639,574,43640,43641,1,64832,64847,1,64975,65021,46,65022,65023,1,65508,65512,4,65517,65518,1,65532,65533,1,65847,65855,1,65913,65929,1,65932,65934,1,65936,65948,1,65952,66e3,48,66001,66044,1,67703,67704,1,68296,71487,3191,73685,73692,1,73697,73713,1,92988,92991,1,92997,113820,20823,117760,117999,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119140,1,119146,119148,1,119171,119172,1,119180,119209,1,119214,119274,1,119296,119361,1,119365,119552,187,119553,119638,1,120832,121343,1,121399,121402,1,121453,121460,1,121462,121475,1,121477,121478,1,123215,126124,2909,126254,126976,722,126977,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127245,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,127994,1,128e3,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130031,1]));static Z=new k(new Uint32Array([32,160,128,5760,8192,2432,8193,8202,1,8232,8233,1,8239,8287,48,12288,12288,1]));static Zl=new k(new Uint32Array([8232,8232,1]));static Zp=new k(new Uint32Array([8233,8233,1]));static Zs=new k(new Uint32Array([32,160,128,5760,8192,2432,8193,8202,1,8239,8287,48,12288,12288,1]));static Adlam=new k(new Uint32Array([125184,125259,1,125264,125273,1,125278,125279,1]));static Ahom=new k(new Uint32Array([71424,71450,1,71453,71467,1,71472,71494,1]));static Anatolian_Hieroglyphs=new k(new Uint32Array([82944,83526,1]));static Arabic=new k(new Uint32Array([1536,1540,1,1542,1547,1,1549,1562,1,1564,1566,1,1568,1599,1,1601,1610,1,1622,1647,1,1649,1756,1,1758,1791,1,1872,1919,1,2160,2190,1,2192,2193,1,2199,2273,1,2275,2303,1,64336,64450,1,64467,64829,1,64832,64911,1,64914,64967,1,64975,65008,33,65009,65023,1,65136,65140,1,65142,65276,1,69216,69246,1,69314,69316,1,69372,69375,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,126704,126705,1]));static Armenian=new k(new Uint32Array([1329,1366,1,1369,1418,1,1421,1423,1,64275,64279,1]));static Avestan=new k(new Uint32Array([68352,68405,1,68409,68415,1]));static Balinese=new k(new Uint32Array([6912,6988,1,6990,7039,1]));static Bamum=new k(new Uint32Array([42656,42743,1,92160,92728,1]));static Bassa_Vah=new k(new Uint32Array([92880,92909,1,92912,92917,1]));static Batak=new k(new Uint32Array([7104,7155,1,7164,7167,1]));static Bengali=new k(new Uint32Array([2432,2435,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2492,2500,1,2503,2504,1,2507,2510,1,2519,2524,5,2525,2527,2,2528,2531,1,2534,2558,1]));static Bhaiksuki=new k(new Uint32Array([72704,72712,1,72714,72758,1,72760,72773,1,72784,72812,1]));static Bopomofo=new k(new Uint32Array([746,747,1,12549,12591,1,12704,12735,1]));static Brahmi=new k(new Uint32Array([69632,69709,1,69714,69749,1,69759,69759,1]));static Braille=new k(new Uint32Array([10240,10495,1]));static Buginese=new k(new Uint32Array([6656,6683,1,6686,6687,1]));static Buhid=new k(new Uint32Array([5952,5971,1]));static Canadian_Aboriginal=new k(new Uint32Array([5120,5759,1,6320,6389,1,72368,72383,1]));static Carian=new k(new Uint32Array([66208,66256,1]));static Caucasian_Albanian=new k(new Uint32Array([66864,66915,1,66927,66927,1]));static Chakma=new k(new Uint32Array([69888,69940,1,69942,69959,1]));static Cham=new k(new Uint32Array([43520,43574,1,43584,43597,1,43600,43609,1,43612,43615,1]));static Cherokee=new k(new Uint32Array([5024,5109,1,5112,5117,1,43888,43967,1]));static Chorasmian=new k(new Uint32Array([69552,69579,1]));static Common=new k(new Uint32Array([0,64,1,91,96,1,123,169,1,171,185,1,187,191,1,215,247,32,697,735,1,741,745,1,748,767,1,884,894,10,901,903,2,1541,1548,7,1563,1567,4,1600,1757,157,2274,2404,130,2405,3647,1242,4053,4056,1,4347,5867,1520,5868,5869,1,5941,5942,1,6146,6147,1,6149,7379,1230,7393,7401,8,7402,7404,1,7406,7411,1,7413,7415,1,7418,8192,774,8193,8203,1,8206,8292,1,8294,8304,1,8308,8318,1,8320,8334,1,8352,8384,1,8448,8485,1,8487,8489,1,8492,8497,1,8499,8525,1,8527,8543,1,8585,8587,1,8592,9257,1,9280,9290,1,9312,10239,1,10496,11123,1,11126,11157,1,11159,11263,1,11776,11869,1,12272,12292,1,12294,12296,2,12297,12320,1,12336,12343,1,12348,12351,1,12443,12444,1,12448,12539,91,12540,12688,148,12689,12703,1,12736,12773,1,12783,12832,49,12833,12895,1,12927,13007,1,13055,13144,89,13145,13311,1,19904,19967,1,42752,42785,1,42888,42890,1,43056,43065,1,43310,43471,161,43867,43882,15,43883,64830,20947,64831,65040,209,65041,65049,1,65072,65106,1,65108,65126,1,65128,65131,1,65279,65281,2,65282,65312,1,65339,65344,1,65371,65381,1,65392,65438,46,65439,65504,65,65505,65510,1,65512,65518,1,65529,65533,1,65792,65794,1,65799,65843,1,65847,65855,1,65936,65948,1,66e3,66044,1,66273,66299,1,113824,113827,1,117760,118009,1,118016,118451,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119142,1,119146,119162,1,119171,119172,1,119180,119209,1,119214,119274,1,119488,119507,1,119520,119539,1,119552,119638,1,119648,119672,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120779,1,120782,120831,1,126065,126132,1,126209,126269,1,126976,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127232,127405,1,127462,127487,1,127489,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130041,1,917505,917536,31,917537,917631,1]));static foldCommon=new k(new Uint32Array([924,956,32]));static Coptic=new k(new Uint32Array([994,1007,1,11392,11507,1,11513,11519,1]));static Cuneiform=new k(new Uint32Array([73728,74649,1,74752,74862,1,74864,74868,1,74880,75075,1]));static Cypriot=new k(new Uint32Array([67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3]));static Cypro_Minoan=new k(new Uint32Array([77712,77810,1]));static Cyrillic=new k(new Uint32Array([1024,1156,1,1159,1327,1,7296,7306,1,7467,7544,77,11744,11775,1,42560,42655,1,65070,65071,1,122928,122989,1,123023,123023,1]));static Deseret=new k(new Uint32Array([66560,66639,1]));static Devanagari=new k(new Uint32Array([2304,2384,1,2389,2403,1,2406,2431,1,43232,43263,1,72448,72457,1]));static Dives_Akuru=new k(new Uint32Array([71936,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71989,1,71991,71992,1,71995,72006,1,72016,72025,1]));static Dogra=new k(new Uint32Array([71680,71739,1]));static Duployan=new k(new Uint32Array([113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,113820,113823,1]));static Egyptian_Hieroglyphs=new k(new Uint32Array([77824,78933,1,78944,82938,1]));static Elbasan=new k(new Uint32Array([66816,66855,1]));static Elymaic=new k(new Uint32Array([69600,69622,1]));static Ethiopic=new k(new Uint32Array([4608,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4957,4988,1,4992,5017,1,11648,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,124896,124902,1,124904,124907,1,124909,124910,1,124912,124926,1]));static Garay=new k(new Uint32Array([68928,68965,1,68969,68997,1,69006,69007,1]));static Georgian=new k(new Uint32Array([4256,4293,1,4295,4301,6,4304,4346,1,4348,4351,1,7312,7354,1,7357,7359,1,11520,11557,1,11559,11565,6]));static Glagolitic=new k(new Uint32Array([11264,11359,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1]));static Gothic=new k(new Uint32Array([66352,66378,1]));static Grantha=new k(new Uint32Array([70400,70403,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70460,70468,1,70471,70472,1,70475,70477,1,70480,70487,7,70493,70499,1,70502,70508,1,70512,70516,1]));static Greek=new k(new Uint32Array([880,883,1,885,887,1,890,893,1,895,900,5,902,904,2,905,906,1,908,910,2,911,929,1,931,993,1,1008,1023,1,7462,7466,1,7517,7521,1,7526,7530,1,7615,7936,321,7937,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8132,1,8134,8147,1,8150,8155,1,8157,8175,1,8178,8180,1,8182,8190,1,8486,43877,35391,65856,65934,1,65952,119296,53344,119297,119365,1]));static foldGreek=new k(new Uint32Array([181,837,656]));static Gujarati=new k(new Uint32Array([2689,2691,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2748,2757,1,2759,2761,1,2763,2765,1,2768,2784,16,2785,2787,1,2790,2801,1,2809,2815,1]));static Gunjala_Gondi=new k(new Uint32Array([73056,73061,1,73063,73064,1,73066,73102,1,73104,73105,1,73107,73112,1,73120,73129,1]));static Gurmukhi=new k(new Uint32Array([2561,2563,1,2565,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2649,8,2650,2652,1,2654,2662,8,2663,2678,1]));static Gurung_Khema=new k(new Uint32Array([90368,90425,1]));static Han=new k(new Uint32Array([11904,11929,1,11931,12019,1,12032,12245,1,12293,12295,2,12321,12329,1,12344,12347,1,13312,19903,1,19968,40959,1,63744,64109,1,64112,64217,1,94178,94179,1,94192,94193,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1]));static Hangul=new k(new Uint32Array([4352,4607,1,12334,12335,1,12593,12686,1,12800,12830,1,12896,12926,1,43360,43388,1,44032,55203,1,55216,55238,1,55243,55291,1,65440,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1]));static Hanifi_Rohingya=new k(new Uint32Array([68864,68903,1,68912,68921,1]));static Hanunoo=new k(new Uint32Array([5920,5940,1]));static Hatran=new k(new Uint32Array([67808,67826,1,67828,67829,1,67835,67839,1]));static Hebrew=new k(new Uint32Array([1425,1479,1,1488,1514,1,1519,1524,1,64285,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64335,1]));static Hiragana=new k(new Uint32Array([12353,12438,1,12445,12447,1,110593,110879,1,110898,110928,30,110929,110930,1,127488,127488,1]));static Imperial_Aramaic=new k(new Uint32Array([67648,67669,1,67671,67679,1]));static Inherited=new k(new Uint32Array([768,879,1,1157,1158,1,1611,1621,1,1648,2385,737,2386,2388,1,6832,6862,1,7376,7378,1,7380,7392,1,7394,7400,1,7405,7412,7,7416,7417,1,7616,7679,1,8204,8205,1,8400,8432,1,12330,12333,1,12441,12442,1,65024,65039,1,65056,65069,1,66045,66272,227,70459,118528,48069,118529,118573,1,118576,118598,1,119143,119145,1,119163,119170,1,119173,119179,1,119210,119213,1,917760,917999,1]));static foldInherited=new k(new Uint32Array([921,953,32,8126,8126,1]));static Inscriptional_Pahlavi=new k(new Uint32Array([68448,68466,1,68472,68479,1]));static Inscriptional_Parthian=new k(new Uint32Array([68416,68437,1,68440,68447,1]));static Javanese=new k(new Uint32Array([43392,43469,1,43472,43481,1,43486,43487,1]));static Kaithi=new k(new Uint32Array([69760,69826,1,69837,69837,1]));static Kannada=new k(new Uint32Array([3200,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3260,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3293,3294,1,3296,3299,1,3302,3311,1,3313,3315,1]));static Katakana=new k(new Uint32Array([12449,12538,1,12541,12543,1,12784,12799,1,13008,13054,1,13056,13143,1,65382,65391,1,65393,65437,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110880,288,110881,110882,1,110933,110948,15,110949,110951,1]));static Kawi=new k(new Uint32Array([73472,73488,1,73490,73530,1,73534,73562,1]));static Kayah_Li=new k(new Uint32Array([43264,43309,1,43311,43311,1]));static Kharoshthi=new k(new Uint32Array([68096,68099,1,68101,68102,1,68108,68115,1,68117,68119,1,68121,68149,1,68152,68154,1,68159,68168,1,68176,68184,1]));static Khitan_Small_Script=new k(new Uint32Array([94180,101120,6940,101121,101589,1,101631,101631,1]));static Khmer=new k(new Uint32Array([6016,6109,1,6112,6121,1,6128,6137,1,6624,6655,1]));static Khojki=new k(new Uint32Array([70144,70161,1,70163,70209,1]));static Khudawadi=new k(new Uint32Array([70320,70378,1,70384,70393,1]));static Kirat_Rai=new k(new Uint32Array([93504,93561,1]));static Lao=new k(new Uint32Array([3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3773,1,3776,3780,1,3782,3784,2,3785,3790,1,3792,3801,1,3804,3807,1]));static Latin=new k(new Uint32Array([65,90,1,97,122,1,170,186,16,192,214,1,216,246,1,248,696,1,736,740,1,7424,7461,1,7468,7516,1,7522,7525,1,7531,7543,1,7545,7614,1,7680,7935,1,8305,8319,14,8336,8348,1,8490,8491,1,8498,8526,28,8544,8584,1,11360,11391,1,42786,42887,1,42891,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43007,1,43824,43866,1,43868,43876,1,43878,43881,1,64256,64262,1,65313,65338,1,65345,65370,1,67456,67461,1,67463,67504,1,67506,67514,1,122624,122654,1,122661,122666,1]));static Lepcha=new k(new Uint32Array([7168,7223,1,7227,7241,1,7245,7247,1]));static Limbu=new k(new Uint32Array([6400,6430,1,6432,6443,1,6448,6459,1,6464,6468,4,6469,6479,1]));static Linear_A=new k(new Uint32Array([67072,67382,1,67392,67413,1,67424,67431,1]));static Linear_B=new k(new Uint32Array([65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1]));static Lisu=new k(new Uint32Array([42192,42239,1,73648,73648,1]));static Lycian=new k(new Uint32Array([66176,66204,1]));static Lydian=new k(new Uint32Array([67872,67897,1,67903,67903,1]));static Mahajani=new k(new Uint32Array([69968,70006,1]));static Makasar=new k(new Uint32Array([73440,73464,1]));static Malayalam=new k(new Uint32Array([3328,3340,1,3342,3344,1,3346,3396,1,3398,3400,1,3402,3407,1,3412,3427,1,3430,3455,1]));static Mandaic=new k(new Uint32Array([2112,2139,1,2142,2142,1]));static Manichaean=new k(new Uint32Array([68288,68326,1,68331,68342,1]));static Marchen=new k(new Uint32Array([72816,72847,1,72850,72871,1,72873,72886,1]));static Masaram_Gondi=new k(new Uint32Array([72960,72966,1,72968,72969,1,72971,73014,1,73018,73020,2,73021,73023,2,73024,73031,1,73040,73049,1]));static Medefaidrin=new k(new Uint32Array([93760,93850,1]));static Meetei_Mayek=new k(new Uint32Array([43744,43766,1,43968,44013,1,44016,44025,1]));static Mende_Kikakui=new k(new Uint32Array([124928,125124,1,125127,125142,1]));static Meroitic_Cursive=new k(new Uint32Array([68e3,68023,1,68028,68047,1,68050,68095,1]));static Meroitic_Hieroglyphs=new k(new Uint32Array([67968,67999,1]));static Miao=new k(new Uint32Array([93952,94026,1,94031,94087,1,94095,94111,1]));static Modi=new k(new Uint32Array([71168,71236,1,71248,71257,1]));static Mongolian=new k(new Uint32Array([6144,6145,1,6148,6150,2,6151,6169,1,6176,6264,1,6272,6314,1,71264,71276,1]));static Mro=new k(new Uint32Array([92736,92766,1,92768,92777,1,92782,92783,1]));static Multani=new k(new Uint32Array([70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70313,1]));static Myanmar=new k(new Uint32Array([4096,4255,1,43488,43518,1,43616,43647,1,71376,71395,1]));static Nabataean=new k(new Uint32Array([67712,67742,1,67751,67759,1]));static Nag_Mundari=new k(new Uint32Array([124112,124153,1]));static Nandinagari=new k(new Uint32Array([72096,72103,1,72106,72151,1,72154,72164,1]));static New_Tai_Lue=new k(new Uint32Array([6528,6571,1,6576,6601,1,6608,6618,1,6622,6623,1]));static Newa=new k(new Uint32Array([70656,70747,1,70749,70753,1]));static Nko=new k(new Uint32Array([1984,2042,1,2045,2047,1]));static Nushu=new k(new Uint32Array([94177,110960,16783,110961,111355,1]));static Nyiakeng_Puachue_Hmong=new k(new Uint32Array([123136,123180,1,123184,123197,1,123200,123209,1,123214,123215,1]));static Ogham=new k(new Uint32Array([5760,5788,1]));static Ol_Chiki=new k(new Uint32Array([7248,7295,1]));static Ol_Onal=new k(new Uint32Array([124368,124410,1,124415,124415,1]));static Old_Hungarian=new k(new Uint32Array([68736,68786,1,68800,68850,1,68858,68863,1]));static Old_Italic=new k(new Uint32Array([66304,66339,1,66349,66351,1]));static Old_North_Arabian=new k(new Uint32Array([68224,68255,1]));static Old_Permic=new k(new Uint32Array([66384,66426,1]));static Old_Persian=new k(new Uint32Array([66464,66499,1,66504,66517,1]));static Old_Sogdian=new k(new Uint32Array([69376,69415,1]));static Old_South_Arabian=new k(new Uint32Array([68192,68223,1]));static Old_Turkic=new k(new Uint32Array([68608,68680,1]));static Old_Uyghur=new k(new Uint32Array([69488,69513,1]));static Oriya=new k(new Uint32Array([2817,2819,1,2821,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2876,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2908,2909,1,2911,2915,1,2918,2935,1]));static Osage=new k(new Uint32Array([66736,66771,1,66776,66811,1]));static Osmanya=new k(new Uint32Array([66688,66717,1,66720,66729,1]));static Pahawh_Hmong=new k(new Uint32Array([92928,92997,1,93008,93017,1,93019,93025,1,93027,93047,1,93053,93071,1]));static Palmyrene=new k(new Uint32Array([67680,67711,1]));static Pau_Cin_Hau=new k(new Uint32Array([72384,72440,1]));static Phags_Pa=new k(new Uint32Array([43072,43127,1]));static Phoenician=new k(new Uint32Array([67840,67867,1,67871,67871,1]));static Psalter_Pahlavi=new k(new Uint32Array([68480,68497,1,68505,68508,1,68521,68527,1]));static Rejang=new k(new Uint32Array([43312,43347,1,43359,43359,1]));static Runic=new k(new Uint32Array([5792,5866,1,5870,5880,1]));static Samaritan=new k(new Uint32Array([2048,2093,1,2096,2110,1]));static Saurashtra=new k(new Uint32Array([43136,43205,1,43214,43225,1]));static Sharada=new k(new Uint32Array([70016,70111,1]));static Shavian=new k(new Uint32Array([66640,66687,1]));static Siddham=new k(new Uint32Array([71040,71093,1,71096,71133,1]));static SignWriting=new k(new Uint32Array([120832,121483,1,121499,121503,1,121505,121519,1]));static Sinhala=new k(new Uint32Array([3457,3459,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3558,3567,1,3570,3572,1,70113,70132,1]));static Sogdian=new k(new Uint32Array([69424,69465,1]));static Sora_Sompeng=new k(new Uint32Array([69840,69864,1,69872,69881,1]));static Soyombo=new k(new Uint32Array([72272,72354,1]));static Sundanese=new k(new Uint32Array([7040,7103,1,7360,7367,1]));static Sunuwar=new k(new Uint32Array([72640,72673,1,72688,72697,1]));static Syloti_Nagri=new k(new Uint32Array([43008,43052,1]));static Syriac=new k(new Uint32Array([1792,1805,1,1807,1866,1,1869,1871,1,2144,2154,1]));static Tagalog=new k(new Uint32Array([5888,5909,1,5919,5919,1]));static Tagbanwa=new k(new Uint32Array([5984,5996,1,5998,6e3,1,6002,6003,1]));static Tai_Le=new k(new Uint32Array([6480,6509,1,6512,6516,1]));static Tai_Tham=new k(new Uint32Array([6688,6750,1,6752,6780,1,6783,6793,1,6800,6809,1,6816,6829,1]));static Tai_Viet=new k(new Uint32Array([43648,43714,1,43739,43743,1]));static Takri=new k(new Uint32Array([71296,71353,1,71360,71369,1]));static Tamil=new k(new Uint32Array([2946,2947,1,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3006,3010,1,3014,3016,1,3018,3021,1,3024,3031,7,3046,3066,1,73664,73713,1,73727,73727,1]));static Tangsa=new k(new Uint32Array([92784,92862,1,92864,92873,1]));static Tangut=new k(new Uint32Array([94176,94208,32,94209,100343,1,100352,101119,1,101632,101640,1]));static Telugu=new k(new Uint32Array([3072,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3132,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3160,3162,1,3165,3168,3,3169,3171,1,3174,3183,1,3191,3199,1]));static Thaana=new k(new Uint32Array([1920,1969,1]));static Thai=new k(new Uint32Array([3585,3642,1,3648,3675,1]));static Tibetan=new k(new Uint32Array([3840,3911,1,3913,3948,1,3953,3991,1,3993,4028,1,4030,4044,1,4046,4052,1,4057,4058,1]));static Tifinagh=new k(new Uint32Array([11568,11623,1,11631,11632,1,11647,11647,1]));static Tirhuta=new k(new Uint32Array([70784,70855,1,70864,70873,1]));static Todhri=new k(new Uint32Array([67008,67059,1]));static Toto=new k(new Uint32Array([123536,123566,1]));static Tulu_Tigalari=new k(new Uint32Array([70528,70537,1,70539,70542,3,70544,70581,1,70583,70592,1,70594,70597,3,70599,70602,1,70604,70613,1,70615,70616,1,70625,70626,1]));static Ugaritic=new k(new Uint32Array([66432,66461,1,66463,66463,1]));static Vai=new k(new Uint32Array([42240,42539,1]));static Vithkuqi=new k(new Uint32Array([66928,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1]));static Wancho=new k(new Uint32Array([123584,123641,1,123647,123647,1]));static Warang_Citi=new k(new Uint32Array([71840,71922,1,71935,71935,1]));static Yezidi=new k(new Uint32Array([69248,69289,1,69291,69293,1,69296,69297,1]));static Yi=new k(new Uint32Array([40960,42124,1,42128,42182,1]));static Zanabazar_Square=new k(new Uint32Array([72192,72263,1]));static CATEGORIES=new Map([["C",e.C],["Cc",e.Cc],["Cf",e.Cf],["Co",e.Co],["Cs",e.Cs],["L",e.L],["Ll",e.Ll],["Lm",e.Lm],["Lo",e.Lo],["Lt",e.Lt],["Lu",e.Lu],["M",e.M],["Mc",e.Mc],["Me",e.Me],["Mn",e.Mn],["N",e.N],["Nd",e.Nd],["Nl",e.Nl],["No",e.No],["P",e.P],["Pc",e.Pc],["Pd",e.Pd],["Pe",e.Pe],["Pf",e.Pf],["Pi",e.Pi],["Po",e.Po],["Ps",e.Ps],["S",e.S],["Sc",e.Sc],["Sk",e.Sk],["Sm",e.Sm],["So",e.So],["Z",e.Z],["Zl",e.Zl],["Zp",e.Zp],["Zs",e.Zs]]);static SCRIPTS=new Map([["Adlam",e.Adlam],["Ahom",e.Ahom],["Anatolian_Hieroglyphs",e.Anatolian_Hieroglyphs],["Arabic",e.Arabic],["Armenian",e.Armenian],["Avestan",e.Avestan],["Balinese",e.Balinese],["Bamum",e.Bamum],["Bassa_Vah",e.Bassa_Vah],["Batak",e.Batak],["Bengali",e.Bengali],["Bhaiksuki",e.Bhaiksuki],["Bopomofo",e.Bopomofo],["Brahmi",e.Brahmi],["Braille",e.Braille],["Buginese",e.Buginese],["Buhid",e.Buhid],["Canadian_Aboriginal",e.Canadian_Aboriginal],["Carian",e.Carian],["Caucasian_Albanian",e.Caucasian_Albanian],["Chakma",e.Chakma],["Cham",e.Cham],["Cherokee",e.Cherokee],["Chorasmian",e.Chorasmian],["Common",e.Common],["Coptic",e.Coptic],["Cuneiform",e.Cuneiform],["Cypriot",e.Cypriot],["Cypro_Minoan",e.Cypro_Minoan],["Cyrillic",e.Cyrillic],["Deseret",e.Deseret],["Devanagari",e.Devanagari],["Dives_Akuru",e.Dives_Akuru],["Dogra",e.Dogra],["Duployan",e.Duployan],["Egyptian_Hieroglyphs",e.Egyptian_Hieroglyphs],["Elbasan",e.Elbasan],["Elymaic",e.Elymaic],["Ethiopic",e.Ethiopic],["Garay",e.Garay],["Georgian",e.Georgian],["Glagolitic",e.Glagolitic],["Gothic",e.Gothic],["Grantha",e.Grantha],["Greek",e.Greek],["Gujarati",e.Gujarati],["Gunjala_Gondi",e.Gunjala_Gondi],["Gurmukhi",e.Gurmukhi],["Gurung_Khema",e.Gurung_Khema],["Han",e.Han],["Hangul",e.Hangul],["Hanifi_Rohingya",e.Hanifi_Rohingya],["Hanunoo",e.Hanunoo],["Hatran",e.Hatran],["Hebrew",e.Hebrew],["Hiragana",e.Hiragana],["Imperial_Aramaic",e.Imperial_Aramaic],["Inherited",e.Inherited],["Inscriptional_Pahlavi",e.Inscriptional_Pahlavi],["Inscriptional_Parthian",e.Inscriptional_Parthian],["Javanese",e.Javanese],["Kaithi",e.Kaithi],["Kannada",e.Kannada],["Katakana",e.Katakana],["Kawi",e.Kawi],["Kayah_Li",e.Kayah_Li],["Kharoshthi",e.Kharoshthi],["Khitan_Small_Script",e.Khitan_Small_Script],["Khmer",e.Khmer],["Khojki",e.Khojki],["Khudawadi",e.Khudawadi],["Kirat_Rai",e.Kirat_Rai],["Lao",e.Lao],["Latin",e.Latin],["Lepcha",e.Lepcha],["Limbu",e.Limbu],["Linear_A",e.Linear_A],["Linear_B",e.Linear_B],["Lisu",e.Lisu],["Lycian",e.Lycian],["Lydian",e.Lydian],["Mahajani",e.Mahajani],["Makasar",e.Makasar],["Malayalam",e.Malayalam],["Mandaic",e.Mandaic],["Manichaean",e.Manichaean],["Marchen",e.Marchen],["Masaram_Gondi",e.Masaram_Gondi],["Medefaidrin",e.Medefaidrin],["Meetei_Mayek",e.Meetei_Mayek],["Mende_Kikakui",e.Mende_Kikakui],["Meroitic_Cursive",e.Meroitic_Cursive],["Meroitic_Hieroglyphs",e.Meroitic_Hieroglyphs],["Miao",e.Miao],["Modi",e.Modi],["Mongolian",e.Mongolian],["Mro",e.Mro],["Multani",e.Multani],["Myanmar",e.Myanmar],["Nabataean",e.Nabataean],["Nag_Mundari",e.Nag_Mundari],["Nandinagari",e.Nandinagari],["New_Tai_Lue",e.New_Tai_Lue],["Newa",e.Newa],["Nko",e.Nko],["Nushu",e.Nushu],["Nyiakeng_Puachue_Hmong",e.Nyiakeng_Puachue_Hmong],["Ogham",e.Ogham],["Ol_Chiki",e.Ol_Chiki],["Ol_Onal",e.Ol_Onal],["Old_Hungarian",e.Old_Hungarian],["Old_Italic",e.Old_Italic],["Old_North_Arabian",e.Old_North_Arabian],["Old_Permic",e.Old_Permic],["Old_Persian",e.Old_Persian],["Old_Sogdian",e.Old_Sogdian],["Old_South_Arabian",e.Old_South_Arabian],["Old_Turkic",e.Old_Turkic],["Old_Uyghur",e.Old_Uyghur],["Oriya",e.Oriya],["Osage",e.Osage],["Osmanya",e.Osmanya],["Pahawh_Hmong",e.Pahawh_Hmong],["Palmyrene",e.Palmyrene],["Pau_Cin_Hau",e.Pau_Cin_Hau],["Phags_Pa",e.Phags_Pa],["Phoenician",e.Phoenician],["Psalter_Pahlavi",e.Psalter_Pahlavi],["Rejang",e.Rejang],["Runic",e.Runic],["Samaritan",e.Samaritan],["Saurashtra",e.Saurashtra],["Sharada",e.Sharada],["Shavian",e.Shavian],["Siddham",e.Siddham],["SignWriting",e.SignWriting],["Sinhala",e.Sinhala],["Sogdian",e.Sogdian],["Sora_Sompeng",e.Sora_Sompeng],["Soyombo",e.Soyombo],["Sundanese",e.Sundanese],["Sunuwar",e.Sunuwar],["Syloti_Nagri",e.Syloti_Nagri],["Syriac",e.Syriac],["Tagalog",e.Tagalog],["Tagbanwa",e.Tagbanwa],["Tai_Le",e.Tai_Le],["Tai_Tham",e.Tai_Tham],["Tai_Viet",e.Tai_Viet],["Takri",e.Takri],["Tamil",e.Tamil],["Tangsa",e.Tangsa],["Tangut",e.Tangut],["Telugu",e.Telugu],["Thaana",e.Thaana],["Thai",e.Thai],["Tibetan",e.Tibetan],["Tifinagh",e.Tifinagh],["Tirhuta",e.Tirhuta],["Todhri",e.Todhri],["Toto",e.Toto],["Tulu_Tigalari",e.Tulu_Tigalari],["Ugaritic",e.Ugaritic],["Vai",e.Vai],["Vithkuqi",e.Vithkuqi],["Wancho",e.Wancho],["Warang_Citi",e.Warang_Citi],["Yezidi",e.Yezidi],["Yi",e.Yi],["Zanabazar_Square",e.Zanabazar_Square]]);static FOLD_CATEGORIES=new Map([["L",e.foldL],["Ll",e.foldLl],["Lt",e.foldLt],["Lu",e.foldLu],["M",e.foldM],["Mn",e.foldMn]]);static FOLD_SCRIPT=new Map([["Common",e.foldCommon],["Greek",e.foldGreek],["Inherited",e.foldInherited]]);static Print=new k(new Uint32Array([33,126,1,161,172,1,174,887,1,890,895,1,900,906,1,908,910,2,911,929,1,931,1327,1,1329,1366,1,1369,1418,1,1421,1423,1,1425,1479,1,1488,1514,1,1519,1524,1,1542,1563,1,1565,1756,1,1758,1805,1,1808,1866,1,1869,1969,1,1984,2042,1,2045,2093,1,2096,2110,1,2112,2139,1,2142,2144,2,2145,2154,1,2160,2190,1,2199,2273,1,2275,2435,1,2437,2444,1,2447,2448,1,2451,2472,1,2474,2480,1,2482,2486,4,2487,2489,1,2492,2500,1,2503,2504,1,2507,2510,1,2519,2524,5,2525,2527,2,2528,2531,1,2534,2558,1,2561,2563,1,2565,2570,1,2575,2576,1,2579,2600,1,2602,2608,1,2610,2611,1,2613,2614,1,2616,2617,1,2620,2622,2,2623,2626,1,2631,2632,1,2635,2637,1,2641,2649,8,2650,2652,1,2654,2662,8,2663,2678,1,2689,2691,1,2693,2701,1,2703,2705,1,2707,2728,1,2730,2736,1,2738,2739,1,2741,2745,1,2748,2757,1,2759,2761,1,2763,2765,1,2768,2784,16,2785,2787,1,2790,2801,1,2809,2815,1,2817,2819,1,2821,2828,1,2831,2832,1,2835,2856,1,2858,2864,1,2866,2867,1,2869,2873,1,2876,2884,1,2887,2888,1,2891,2893,1,2901,2903,1,2908,2909,1,2911,2915,1,2918,2935,1,2946,2947,1,2949,2954,1,2958,2960,1,2962,2965,1,2969,2970,1,2972,2974,2,2975,2979,4,2980,2984,4,2985,2986,1,2990,3001,1,3006,3010,1,3014,3016,1,3018,3021,1,3024,3031,7,3046,3066,1,3072,3084,1,3086,3088,1,3090,3112,1,3114,3129,1,3132,3140,1,3142,3144,1,3146,3149,1,3157,3158,1,3160,3162,1,3165,3168,3,3169,3171,1,3174,3183,1,3191,3212,1,3214,3216,1,3218,3240,1,3242,3251,1,3253,3257,1,3260,3268,1,3270,3272,1,3274,3277,1,3285,3286,1,3293,3294,1,3296,3299,1,3302,3311,1,3313,3315,1,3328,3340,1,3342,3344,1,3346,3396,1,3398,3400,1,3402,3407,1,3412,3427,1,3430,3455,1,3457,3459,1,3461,3478,1,3482,3505,1,3507,3515,1,3517,3520,3,3521,3526,1,3530,3535,5,3536,3540,1,3542,3544,2,3545,3551,1,3558,3567,1,3570,3572,1,3585,3642,1,3647,3675,1,3713,3714,1,3716,3718,2,3719,3722,1,3724,3747,1,3749,3751,2,3752,3773,1,3776,3780,1,3782,3784,2,3785,3790,1,3792,3801,1,3804,3807,1,3840,3911,1,3913,3948,1,3953,3991,1,3993,4028,1,4030,4044,1,4046,4058,1,4096,4293,1,4295,4301,6,4304,4680,1,4682,4685,1,4688,4694,1,4696,4698,2,4699,4701,1,4704,4744,1,4746,4749,1,4752,4784,1,4786,4789,1,4792,4798,1,4800,4802,2,4803,4805,1,4808,4822,1,4824,4880,1,4882,4885,1,4888,4954,1,4957,4988,1,4992,5017,1,5024,5109,1,5112,5117,1,5120,5759,1,5761,5788,1,5792,5880,1,5888,5909,1,5919,5942,1,5952,5971,1,5984,5996,1,5998,6e3,1,6002,6003,1,6016,6109,1,6112,6121,1,6128,6137,1,6144,6157,1,6159,6169,1,6176,6264,1,6272,6314,1,6320,6389,1,6400,6430,1,6432,6443,1,6448,6459,1,6464,6468,4,6469,6509,1,6512,6516,1,6528,6571,1,6576,6601,1,6608,6618,1,6622,6683,1,6686,6750,1,6752,6780,1,6783,6793,1,6800,6809,1,6816,6829,1,6832,6862,1,6912,6988,1,6990,7155,1,7164,7223,1,7227,7241,1,7245,7306,1,7312,7354,1,7357,7367,1,7376,7418,1,7424,7957,1,7960,7965,1,7968,8005,1,8008,8013,1,8016,8023,1,8025,8031,2,8032,8061,1,8064,8116,1,8118,8132,1,8134,8147,1,8150,8155,1,8157,8175,1,8178,8180,1,8182,8190,1,8208,8231,1,8240,8286,1,8304,8305,1,8308,8334,1,8336,8348,1,8352,8384,1,8400,8432,1,8448,8587,1,8592,9257,1,9280,9290,1,9312,11123,1,11126,11157,1,11159,11507,1,11513,11557,1,11559,11565,6,11568,11623,1,11631,11632,1,11647,11670,1,11680,11686,1,11688,11694,1,11696,11702,1,11704,11710,1,11712,11718,1,11720,11726,1,11728,11734,1,11736,11742,1,11744,11869,1,11904,11929,1,11931,12019,1,12032,12245,1,12272,12287,1,12289,12351,1,12353,12438,1,12441,12543,1,12549,12591,1,12593,12686,1,12688,12773,1,12783,12830,1,12832,42124,1,42128,42182,1,42192,42539,1,42560,42743,1,42752,42957,1,42960,42961,1,42963,42965,2,42966,42972,1,42994,43052,1,43056,43065,1,43072,43127,1,43136,43205,1,43214,43225,1,43232,43347,1,43359,43388,1,43392,43469,1,43471,43481,1,43486,43518,1,43520,43574,1,43584,43597,1,43600,43609,1,43612,43714,1,43739,43766,1,43777,43782,1,43785,43790,1,43793,43798,1,43808,43814,1,43816,43822,1,43824,43883,1,43888,44013,1,44016,44025,1,44032,55203,1,55216,55238,1,55243,55291,1,63744,64109,1,64112,64217,1,64256,64262,1,64275,64279,1,64285,64310,1,64312,64316,1,64318,64320,2,64321,64323,2,64324,64326,2,64327,64450,1,64467,64911,1,64914,64967,1,64975,65008,33,65009,65049,1,65056,65106,1,65108,65126,1,65128,65131,1,65136,65140,1,65142,65276,1,65281,65470,1,65474,65479,1,65482,65487,1,65490,65495,1,65498,65500,1,65504,65510,1,65512,65518,1,65532,65533,1,65536,65547,1,65549,65574,1,65576,65594,1,65596,65597,1,65599,65613,1,65616,65629,1,65664,65786,1,65792,65794,1,65799,65843,1,65847,65934,1,65936,65948,1,65952,66e3,48,66001,66045,1,66176,66204,1,66208,66256,1,66272,66299,1,66304,66339,1,66349,66378,1,66384,66426,1,66432,66461,1,66463,66499,1,66504,66517,1,66560,66717,1,66720,66729,1,66736,66771,1,66776,66811,1,66816,66855,1,66864,66915,1,66927,66938,1,66940,66954,1,66956,66962,1,66964,66965,1,66967,66977,1,66979,66993,1,66995,67001,1,67003,67004,1,67008,67059,1,67072,67382,1,67392,67413,1,67424,67431,1,67456,67461,1,67463,67504,1,67506,67514,1,67584,67589,1,67592,67594,2,67595,67637,1,67639,67640,1,67644,67647,3,67648,67669,1,67671,67742,1,67751,67759,1,67808,67826,1,67828,67829,1,67835,67867,1,67871,67897,1,67903,67968,65,67969,68023,1,68028,68047,1,68050,68099,1,68101,68102,1,68108,68115,1,68117,68119,1,68121,68149,1,68152,68154,1,68159,68168,1,68176,68184,1,68192,68255,1,68288,68326,1,68331,68342,1,68352,68405,1,68409,68437,1,68440,68466,1,68472,68497,1,68505,68508,1,68521,68527,1,68608,68680,1,68736,68786,1,68800,68850,1,68858,68903,1,68912,68921,1,68928,68965,1,68969,68997,1,69006,69007,1,69216,69246,1,69248,69289,1,69291,69293,1,69296,69297,1,69314,69316,1,69372,69415,1,69424,69465,1,69488,69513,1,69552,69579,1,69600,69622,1,69632,69709,1,69714,69749,1,69759,69820,1,69822,69826,1,69840,69864,1,69872,69881,1,69888,69940,1,69942,69959,1,69968,70006,1,70016,70111,1,70113,70132,1,70144,70161,1,70163,70209,1,70272,70278,1,70280,70282,2,70283,70285,1,70287,70301,1,70303,70313,1,70320,70378,1,70384,70393,1,70400,70403,1,70405,70412,1,70415,70416,1,70419,70440,1,70442,70448,1,70450,70451,1,70453,70457,1,70459,70468,1,70471,70472,1,70475,70477,1,70480,70487,7,70493,70499,1,70502,70508,1,70512,70516,1,70528,70537,1,70539,70542,3,70544,70581,1,70583,70592,1,70594,70597,3,70599,70602,1,70604,70613,1,70615,70616,1,70625,70626,1,70656,70747,1,70749,70753,1,70784,70855,1,70864,70873,1,71040,71093,1,71096,71133,1,71168,71236,1,71248,71257,1,71264,71276,1,71296,71353,1,71360,71369,1,71376,71395,1,71424,71450,1,71453,71467,1,71472,71494,1,71680,71739,1,71840,71922,1,71935,71942,1,71945,71948,3,71949,71955,1,71957,71958,1,71960,71989,1,71991,71992,1,71995,72006,1,72016,72025,1,72096,72103,1,72106,72151,1,72154,72164,1,72192,72263,1,72272,72354,1,72368,72440,1,72448,72457,1,72640,72673,1,72688,72697,1,72704,72712,1,72714,72758,1,72760,72773,1,72784,72812,1,72816,72847,1,72850,72871,1,72873,72886,1,72960,72966,1,72968,72969,1,72971,73014,1,73018,73020,2,73021,73023,2,73024,73031,1,73040,73049,1,73056,73061,1,73063,73064,1,73066,73102,1,73104,73105,1,73107,73112,1,73120,73129,1,73440,73464,1,73472,73488,1,73490,73530,1,73534,73562,1,73648,73664,16,73665,73713,1,73727,74649,1,74752,74862,1,74864,74868,1,74880,75075,1,77712,77810,1,77824,78895,1,78912,78933,1,78944,82938,1,82944,83526,1,90368,90425,1,92160,92728,1,92736,92766,1,92768,92777,1,92782,92862,1,92864,92873,1,92880,92909,1,92912,92917,1,92928,92997,1,93008,93017,1,93019,93025,1,93027,93047,1,93053,93071,1,93504,93561,1,93760,93850,1,93952,94026,1,94031,94087,1,94095,94111,1,94176,94180,1,94192,94193,1,94208,100343,1,100352,101589,1,101631,101640,1,110576,110579,1,110581,110587,1,110589,110590,1,110592,110882,1,110898,110928,30,110929,110930,1,110933,110948,15,110949,110951,1,110960,111355,1,113664,113770,1,113776,113788,1,113792,113800,1,113808,113817,1,113820,113823,1,117760,118009,1,118016,118451,1,118528,118573,1,118576,118598,1,118608,118723,1,118784,119029,1,119040,119078,1,119081,119154,1,119163,119274,1,119296,119365,1,119488,119507,1,119520,119539,1,119552,119638,1,119648,119672,1,119808,119892,1,119894,119964,1,119966,119967,1,119970,119973,3,119974,119977,3,119978,119980,1,119982,119993,1,119995,119997,2,119998,120003,1,120005,120069,1,120071,120074,1,120077,120084,1,120086,120092,1,120094,120121,1,120123,120126,1,120128,120132,1,120134,120138,4,120139,120144,1,120146,120485,1,120488,120779,1,120782,121483,1,121499,121503,1,121505,121519,1,122624,122654,1,122661,122666,1,122880,122886,1,122888,122904,1,122907,122913,1,122915,122916,1,122918,122922,1,122928,122989,1,123023,123136,113,123137,123180,1,123184,123197,1,123200,123209,1,123214,123215,1,123536,123566,1,123584,123641,1,123647,124112,465,124113,124153,1,124368,124410,1,124415,124896,481,124897,124902,1,124904,124907,1,124909,124910,1,124912,124926,1,124928,125124,1,125127,125142,1,125184,125259,1,125264,125273,1,125278,125279,1,126065,126132,1,126209,126269,1,126464,126467,1,126469,126495,1,126497,126498,1,126500,126503,3,126505,126514,1,126516,126519,1,126521,126523,2,126530,126535,5,126537,126541,2,126542,126543,1,126545,126546,1,126548,126551,3,126553,126561,2,126562,126564,2,126567,126570,1,126572,126578,1,126580,126583,1,126585,126588,1,126590,126592,2,126593,126601,1,126603,126619,1,126625,126627,1,126629,126633,1,126635,126651,1,126704,126705,1,126976,127019,1,127024,127123,1,127136,127150,1,127153,127167,1,127169,127183,1,127185,127221,1,127232,127405,1,127462,127490,1,127504,127547,1,127552,127560,1,127568,127569,1,127584,127589,1,127744,128727,1,128732,128748,1,128752,128764,1,128768,128886,1,128891,128985,1,128992,129003,1,129008,129024,16,129025,129035,1,129040,129095,1,129104,129113,1,129120,129159,1,129168,129197,1,129200,129211,1,129216,129217,1,129280,129619,1,129632,129645,1,129648,129660,1,129664,129673,1,129679,129734,1,129742,129756,1,129759,129769,1,129776,129784,1,129792,129938,1,129940,130041,1,131072,173791,1,173824,177977,1,177984,178205,1,178208,183969,1,183984,191456,1,191472,192093,1,194560,195101,1,196608,201546,1,201552,205743,1,917760,917999,1]))},ue=class{static MAX_RUNE=1114111;static MAX_ASCII=127;static MAX_LATIN1=255;static MAX_BMP=65535;static MIN_FOLD=65;static MAX_FOLD=125251;static is32(t,n){let r=0,s=t.length;for(;rs)continue;let i=t.getLo(r);if(n0&&n>=t.getLo(0)&&this.is32(t,n)}static isUpper(t){if(t<=this.MAX_LATIN1){let n=String.fromCodePoint(t);return n.toUpperCase()===n&&n.toLowerCase()!==n}return this.is(on.Upper,t)}static isPrint(t){return t<=this.MAX_LATIN1?t>=32&&t=161&&t!==173:this.is(on.Print,t)}static simpleFold(t){if(on.CASE_ORBIT.has(t))return on.CASE_ORBIT.get(t);let n=D.toLowerCase(t);return n!==t?n:D.toUpperCase(t)}static equalsIgnoreCase(t,n){if(t<0||n<0||t===n)return!0;if(t<=this.MAX_ASCII&&n<=this.MAX_ASCII)return D.CODES.get("A")<=t&&t<=D.CODES.get("Z")&&(t|=32),D.CODES.get("A")<=n&&n<=D.CODES.get("Z")&&(n|=32),t===n;for(let r=this.simpleFold(t);r!==t;r=this.simpleFold(r))if(r===n)return!0;return!1}},Te=class{static METACHARACTERS="\\.+*?()|[]{}^$";static EMPTY_BEGIN_LINE=1;static EMPTY_END_LINE=2;static EMPTY_BEGIN_TEXT=4;static EMPTY_END_TEXT=8;static EMPTY_WORD_BOUNDARY=16;static EMPTY_NO_WORD_BOUNDARY=32;static EMPTY_ALL=-1;static emptyInts(){return[]}static isalnum(t){return D.CODES.get("0")<=t&&t<=D.CODES.get("9")||D.CODES.get("a")<=t&&t<=D.CODES.get("z")||D.CODES.get("A")<=t&&t<=D.CODES.get("Z")}static unhex(t){return D.CODES.get("0")<=t&&t<=D.CODES.get("9")?t-D.CODES.get("0"):D.CODES.get("a")<=t&&t<=D.CODES.get("f")?t-D.CODES.get("a")+10:D.CODES.get("A")<=t&&t<=D.CODES.get("F")?t-D.CODES.get("A")+10:-1}static escapeRune(t){let n="";if(ue.isPrint(t))this.METACHARACTERS.indexOf(String.fromCodePoint(t))>=0&&(n+="\\"),n+=String.fromCodePoint(t);else switch(t){case D.CODES.get('"'):n+='\\"';break;case D.CODES.get("\\"):n+="\\\\";break;case D.CODES.get(" "):n+="\\t";break;case D.CODES.get(` `):n+="\\n";break;case D.CODES.get("\r"):n+="\\r";break;case D.CODES.get("\b"):n+="\\b";break;case D.CODES.get("\f"):n+="\\f";break;default:{let r=t.toString(16);t<256?(n+="\\x",r.length===1&&(n+="0"),n+=r):n+=`\\x{${r}}`;break}}return n}static stringToRunes(t){return String(t).split("").map(n=>n.codePointAt(0))}static runeToString(t){return String.fromCodePoint(t)}static isWordRune(t){return D.CODES.get("a")<=t&&t<=D.CODES.get("z")||D.CODES.get("A")<=t&&t<=D.CODES.get("Z")||D.CODES.get("0")<=t&&t<=D.CODES.get("9")||t===D.CODES.get("_")}static emptyOpContext(t,n){let r=0;return t<0&&(r|=this.EMPTY_BEGIN_TEXT|this.EMPTY_BEGIN_LINE),t===D.CODES.get(` `)&&(r|=this.EMPTY_BEGIN_LINE),n<0&&(r|=this.EMPTY_END_TEXT|this.EMPTY_END_LINE),n===D.CODES.get(` -`)&&(r|=this.EMPTY_END_LINE),this.isWordRune(t)!==this.isWordRune(n)?r|=this.EMPTY_WORD_BOUNDARY:r|=this.EMPTY_NO_WORD_BOUNDARY,r}static quoteMeta(t){return t.split("").map(n=>this.METACHARACTERS.indexOf(n)>=0?`\\${n}`:n).join("")}static charCount(t){return t>ue.MAX_BMP?2:1}static stringToUtf8ByteArray(t){if(globalThis.TextEncoder)return Array.from(new TextEncoder().encode(t));{let n=[],r=0;for(let s=0;s>6|192,n[r++]=i&63|128):(i&64512)===55296&&s+1>18|240,n[r++]=i>>12&63|128,n[r++]=i>>6&63|128,n[r++]=i&63|128):(n[r++]=i>>12|224,n[r++]=i>>6&63|128,n[r++]=i&63|128)}return n}}static utf8ByteArrayToString(t){if(globalThis.TextDecoder)return new TextDecoder("utf-8").decode(new Uint8Array(t));{let n=[],r=0,s=0;for(;r191&&i<224){let o=t[r++];n[s++]=String.fromCharCode((i&31)<<6|o&63)}else if(i>239&&i<365){let o=t[r++],a=t[r++],l=t[r++],c=((i&7)<<18|(o&63)<<12|(a&63)<<6|l&63)-65536;n[s++]=String.fromCharCode(55296+(c>>10)),n[s++]=String.fromCharCode(56320+(c&1023))}else{let o=t[r++],a=t[r++];n[s++]=String.fromCharCode((i&15)<<12|(o&63)<<6|a&63)}}return n.join("")}}},ip=(e=[],t=0)=>{let n={};for(let r=0;rt.codePointAt(0))}length(){return this.charSequence.length}},cs=class{static utf16(t){return new rl(t)}static utf8(t){return Array.isArray(t)?new Zi(t):new Zi(Oe.stringToUtf8ByteArray(t))}},Mn=class{static EOF(){return-8}canCheckPrefix(){return!0}endPos(){return this.end}},sl=class extends Mn{constructor(t,n=0,r=t.length){super(),this.bytes=t,this.start=n,this.end=r}step(t){if(t+=this.start,t>=this.end)return Mn.EOF();let n=this.bytes[t++]&255;return(n&128)===0?n<<3|1:(n&224)===192?(n=n&31,t>=this.end?Mn.EOF():(n=n<<6|this.bytes[t++]&63,n<<3|2)):(n&240)===224?(n=n&15,t+1>=this.end?Mn.EOF():(n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n<<3|3)):(n=n&7,t+2>=this.end?Mn.EOF():(n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n<<3|4))}index(t,n){n+=this.start;let r=this.indexOf(this.bytes,t.prefixUTF8,n);return r<0?r:r-n}context(t){t+=this.start;let n=-1;if(t>this.start&&t<=this.end){let s=t-1;if(n=this.bytes[s--],n>=128){let i=t-4;for(i=i&&(this.bytes[s]&192)===128;)s--;s>3}}let r=t>3:-1;return Oe.emptyOpContext(n,r)}indexOf(t,n,r=0){let s=n.length;if(s===0)return-1;let i=t.length;for(let o=r;o<=i-s;o++)for(let a=0;a0&&t<=this.charSequence.length?this.charSequence.codePointAt(t-1):-1,r=t{let s=r.codePointAt(0);return s===D.CODES.get("\\")||s===D.CODES.get("$")?`\\${r}`:r}).join(""):t.indexOf("$")<0?t:t.split("").map(r=>r.codePointAt(0)===D.CODES.get("$")?"$$":r).join("")}constructor(t,n){if(t===null)throw new Error("pattern is null");this.patternInput=t;let r=this.patternInput.re2();this.patternGroupCount=r.numberOfCapturingGroups(),this.groups=[],this.namedGroups=r.namedGroups,this.numberOfInstructions=r.numberOfInstructions(),n instanceof ar?this.resetMatcherInput(n):Array.isArray(n)?this.resetMatcherInput(cs.utf8(n)):this.resetMatcherInput(cs.utf16(n))}pattern(){return this.patternInput}reset(){return this.matcherInputLength=this.matcherInput.length(),this.appendPos=0,this.hasMatch=!1,this.hasGroups=!1,this.anchorFlag=0,this}resetMatcherInput(t){if(t===null)throw new Error("input is null");return this.matcherInput=t,this.reset(),this}start(t=0){if(typeof t=="string"){let n=this.namedGroups[t];if(!Number.isFinite(n))throw new An(`group '${t}' not found`);t=n}return this.loadGroup(t),this.groups[2*t]}end(t=0){if(typeof t=="string"){let n=this.namedGroups[t];if(!Number.isFinite(n))throw new An(`group '${t}' not found`);t=n}return this.loadGroup(t),this.groups[2*t+1]}programSize(){return this.numberOfInstructions}group(t=0){if(typeof t=="string"){let s=this.namedGroups[t];if(!Number.isFinite(s))throw new An(`group '${t}' not found`);t=s}let n=this.start(t),r=this.end(t);return n<0&&r<0?null:this.substring(n,r)}groupCount(){return this.patternGroupCount}loadGroup(t){if(t<0||t>this.patternGroupCount)throw new An(`Group index out of bounds: ${t}`);if(!this.hasMatch)throw new An("perhaps no match attempted");if(t===0||this.hasGroups)return;let n=this.groups[1]+1;n>this.matcherInputLength&&(n=this.matcherInputLength);let r=this.patternInput.re2().matchMachineInput(this.matcherInput,this.groups[0],n,this.anchorFlag,1+this.patternGroupCount);if(!r[0])throw new An("inconsistency in matching group data");this.groups=r[1],this.hasGroups=!0}matches(){return this.genMatch(0,V.ANCHOR_BOTH)}lookingAt(){return this.genMatch(0,V.ANCHOR_START)}find(t=null){if(t!==null){if(t<0||t>this.matcherInputLength)throw new An(`start index out of bounds: ${t}`);return this.reset(),this.genMatch(t,0)}return t=0,this.hasMatch&&(t=this.groups[1],this.groups[0]===this.groups[1]&&t++),this.genMatch(t,V.UNANCHORED)}genMatch(t,n){let r=this.patternInput.re2().matchMachineInput(this.matcherInput,t,this.matcherInputLength,n,1);return r[0]?(this.groups=r[1],this.hasMatch=!0,this.hasGroups=!1,this.anchorFlag=n,!0):!1}substring(t,n){return this.matcherInput.isUTF8Encoding()?Oe.utf8ByteArrayToString(this.matcherInput.asBytes().slice(t,n)):this.matcherInput.asCharSequence().substring(t,n).toString()}inputLength(){return this.matcherInputLength}appendReplacement(t,n=!1){let r="",s=this.start(),i=this.end();return this.appendPosD.CODES.get("9")||a*10+o-D.CODES.get("0")>this.patternGroupCount));i++)a=a*10+o-D.CODES.get("0");if(a>this.patternGroupCount)throw new An(`n > number of groups: ${a}`);let l=this.group(a);l!==null&&(n+=l),r=i,i--;continue}else if(o===D.CODES.get("{")){rD.CODES.get("9")||a*10+o-D.CODES.get("0")>this.patternGroupCount));i++)a=a*10+o-D.CODES.get("0");if(a>this.patternGroupCount){n+=`$${a}`,r=i,i--;continue}let l=this.group(a);l!==null&&(n+=l),r=i,i--;continue}else if(o===D.CODES.get("<")){r")&&t.codePointAt(a)!==D.CODES.get(" ");)a++;if(a===t.length||t.codePointAt(a)!==D.CODES.get(">")){n+=t.substring(i-1,a+1),r=a+1;continue}let l=t.substring(i+1,a);Object.prototype.hasOwnProperty.call(this.namedGroups,l)?n+=this.group(l):n+=`$<${l}>`,r=a+1}}return r ${this.out}, ${this.arg}`;case e.ALT_MATCH:return`altmatch -> ${this.out}, ${this.arg}`;case e.CAPTURE:return`cap ${this.arg} -> ${this.out}`;case e.EMPTY_WIDTH:return`empty ${this.arg} -> ${this.out}`;case e.MATCH:return"match";case e.FAIL:return"fail";case e.NOP:return`nop -> ${this.out}`;case e.RUNE:return this.runes===null?"rune ":["rune ",e.escapeRunes(this.runes),(this.arg&V.FOLD_CASE)!==0?"/i":""," -> ",this.out].join("");case e.RUNE1:return`rune1 ${e.escapeRunes(this.runes)} -> ${this.out}`;case e.RUNE_ANY:return`any -> ${this.out}`;case e.RUNE_ANY_NOT_NL:return`anynotnl -> ${this.out}`;default:throw new Error("unhandled case in Inst.toString")}}},ll=class{constructor(){this.inst=null,this.cap=[]}},Qi=class{constructor(){this.sparse=[],this.densePcs=[],this.denseThreads=[],this.size=0}contains(t){let n=this.sparse[t];return nthis.matchcap.length?this.initNewCap(t):this.resetCap(t)}resetCap(t){for(let n=0;n0?(this.poolSize--,n=this.pool[this.poolSize]):n=new ll,n.inst=t,n}freeQueue(t,n=0){let r=t.size-n,s=this.poolSize+r;this.pool.length>3,c=a&7,u=-1,f=0;a!==Mn.EOF()&&(a=t.step(n+c),u=a>>3,f=a&7);let p;for(n===0?p=Oe.emptyOpContext(-1,l):p=t.context(n);;){if(i.isEmpty()){if((s&Oe.EMPTY_BEGIN_TEXT)!==0&&n!==0||this.matched)break;if(this.re2.prefix.length!==0&&u!==this.re2.prefixRune&&t.canCheckPrefix()){let m=t.index(this.re2,n);if(m<0)break;n+=m,a=t.step(n),l=a>>3,c=a&7,a=t.step(n+c),u=a>>3,f=a&7}}!this.matched&&(n===0||r===V.UNANCHORED)&&(this.ncap>0&&(this.matchcap[0]=n),this.add(i,this.prog.start,n,this.matchcap,p,null));let h=n+c;if(p=t.context(h),this.step(i,o,n,h,l,p,r,n===t.endPos()),c===0||this.ncap===0&&this.matched)break;n+=c,l=u,c=f,l!==-1&&(a=t.step(n+c),u=a>>3,f=a&7);let d=i;i=o,o=d}return this.freeQueue(o),this.matched}step(t,n,r,s,i,o,a,l){let c=this.re2.longest;for(let u=0;u0&&this.matchcap[0]0&&(!c||!this.matched||this.matchcap[1]0&&o.cap!==s&&(o.cap=s.slice(0,this.ncap)),t.denseThreads[a]=o,o=null;break;default:throw new Error("unhandled")}return o}},D3=e=>{let t=-2128831035;for(let n=0;n{if(e.length!==t.length)return!1;for(let n=0;n0;){let o=r.pop();if(n.has(o))continue;n.add(o);let a=this.prog.getInst(o);switch(a.op){case he.MATCH:s=!0;break;case he.ALT:case he.ALT_MATCH:r.push(a.out),r.push(a.arg);break;case he.NOP:case he.CAPTURE:r.push(a.out);break;case he.EMPTY_WIDTH:return null}}return{pcs:Int32Array.from(n).sort(),isMatch:s}}getState(t){let n=this.computeClosure(t);if(!n)return null;let r=n.pcs,s=D3(r),i=this.stateCache.get(s);if(i)for(let a=0;a=this.stateLimit)return this.stateCache.clear(),this.stateCount=0,this.startState=null,null;let o=new cl(r,n.isMatch);return i.push(o),this.stateCount++,o}step(t,n,r){if(r===V.UNANCHORED&&n<=ue.MAX_ASCII){let o=t.nextAscii[n];if(o!==null)return o}else{let o=n+(r===V.UNANCHORED?0:ue.MAX_RUNE+1);if(t.nextMap.has(o))return t.nextMap.get(o)}let s=[];for(let o=0;o>3,c=a&7;if(c===0)break;if(i=this.step(i,l,r),i===null)return null;if(i.isMatch)if(r===V.ANCHOR_BOTH){if(o+c===s)return!0}else return!0;if(i.nfaStates.length===0&&r!==V.UNANCHORED)return!1;o+=c}return!1}},_=class e{static Op=ip(["NO_MATCH","EMPTY_MATCH","LITERAL","CHAR_CLASS","ANY_CHAR_NOT_NL","ANY_CHAR","BEGIN_LINE","END_LINE","BEGIN_TEXT","END_TEXT","WORD_BOUNDARY","NO_WORD_BOUNDARY","CAPTURE","STAR","PLUS","QUEST","REPEAT","CONCAT","ALTERNATE","LEFT_PAREN","VERTICAL_BAR"]);static isPseudoOp(t){return t>=e.Op.LEFT_PAREN}static emptySubs(){return[]}static quoteIfHyphen(t){return t===D.CODES.get("-")?"\\":""}static fromRegexp(t){let n=new e(t.op);return n.flags=t.flags,n.subs=t.subs,n.runes=t.runes,n.cap=t.cap,n.min=t.min,n.max=t.max,n.name=t.name,n.namedGroups=t.namedGroups,n}constructor(t){this.op=t,this.flags=0,this.subs=e.emptySubs(),this.runes=[],this.min=0,this.max=0,this.cap=0,this.name=null,this.namedGroups={}}reinit(){this.flags=0,this.subs=e.emptySubs(),this.runes=[],this.cap=0,this.min=0,this.max=0,this.name=null,this.namedGroups={}}toString(){return this.appendTo()}appendTo(){let t="";switch(this.op){case e.Op.NO_MATCH:t+="[^\\x00-\\x{10FFFF}]";break;case e.Op.EMPTY_MATCH:t+="(?:)";break;case e.Op.STAR:case e.Op.PLUS:case e.Op.QUEST:case e.Op.REPEAT:{let n=this.subs[0];switch(n.op>e.Op.CAPTURE||n.op===e.Op.LITERAL&&n.runes.length>1?t+=`(?:${n.appendTo()})`:t+=n.appendTo(),this.op){case e.Op.STAR:t+="*";break;case e.Op.PLUS:t+="+";break;case e.Op.QUEST:t+="?";break;case e.Op.REPEAT:t+=`{${this.min}`,this.min!==this.max&&(t+=",",this.max>=0&&(t+=this.max)),t+="}";break}(this.flags&V.NON_GREEDY)!==0&&(t+="?");break}case e.Op.CONCAT:{for(let n of this.subs)n.op===e.Op.ALTERNATE?t+=`(?:${n.appendTo()})`:t+=n.appendTo();break}case e.Op.ALTERNATE:{let n="";for(let r of this.subs)t+=n,n="|",t+=r.appendTo();break}case e.Op.LITERAL:(this.flags&V.FOLD_CASE)!==0&&(t+="(?i:");for(let n of this.runes)t+=Oe.escapeRune(n);(this.flags&V.FOLD_CASE)!==0&&(t+=")");break;case e.Op.ANY_CHAR_NOT_NL:t+="(?-s:.)";break;case e.Op.ANY_CHAR:t+="(?s:.)";break;case e.Op.CAPTURE:this.name===null||this.name.length===0?t+="(":t+=`(?P<${this.name}>`,this.subs[0].op!==e.Op.EMPTY_MATCH&&(t+=this.subs[0].appendTo()),t+=")";break;case e.Op.BEGIN_TEXT:t+="\\A";break;case e.Op.END_TEXT:(this.flags&V.WAS_DOLLAR)!==0?t+="(?-m:$)":t+="\\z";break;case e.Op.BEGIN_LINE:t+="^";break;case e.Op.END_LINE:t+="$";break;case e.Op.WORD_BOUNDARY:t+="\\b";break;case e.Op.NO_WORD_BOUNDARY:t+="\\B";break;case e.Op.CHAR_CLASS:if(this.runes.length%2!==0){t+="[invalid char class]";break}if(t+="[",this.runes.length===0)t+="^\\x00-\\x{10FFFF}";else if(this.runes[0]===0&&this.runes[this.runes.length-1]===ue.MAX_RUNE){t+="^";for(let n=1;n>1];return(t&1)===0?n.out:n.arg}patch(t,n){for(;t!==0;){let r=this.inst[t>>1];(t&1)===0?(t=r.out,r.out=n):(t=r.arg,r.arg=n)}}append(t,n){if(t===0)return n;if(n===0)return t;let r=t;for(;;){let i=this.next(r);if(i===0)break;r=i}let s=this.inst[r>>1];return(r&1)===0?s.out=n:s.arg=n,t}toString(){let t="";for(let n=0;nthis.METACHARACTERS.indexOf(n)>=0?`\\${n}`:n).join("")}static charCount(t){return t>ue.MAX_BMP?2:1}static stringToUtf8ByteArray(t){if(globalThis.TextEncoder)return Array.from(new TextEncoder().encode(t));{let n=[],r=0;for(let s=0;s>6|192,n[r++]=i&63|128):(i&64512)===55296&&s+1>18|240,n[r++]=i>>12&63|128,n[r++]=i>>6&63|128,n[r++]=i&63|128):(n[r++]=i>>12|224,n[r++]=i>>6&63|128,n[r++]=i&63|128)}return n}}static utf8ByteArrayToString(t){if(globalThis.TextDecoder)return new TextDecoder("utf-8").decode(new Uint8Array(t));{let n=[],r=0,s=0;for(;r191&&i<224){let o=t[r++];n[s++]=String.fromCharCode((i&31)<<6|o&63)}else if(i>239&&i<365){let o=t[r++],a=t[r++],l=t[r++],c=((i&7)<<18|(o&63)<<12|(a&63)<<6|l&63)-65536;n[s++]=String.fromCharCode(55296+(c>>10)),n[s++]=String.fromCharCode(56320+(c&1023))}else{let o=t[r++],a=t[r++];n[s++]=String.fromCharCode((i&15)<<12|(o&63)<<6|a&63)}}return n.join("")}}},O1=(e=[],t=0)=>{let n={};for(let r=0;rt.codePointAt(0))}length(){return this.charSequence.length}},Kr=class{static utf16(t){return new Ua(t)}static utf8(t){return Array.isArray(t)?new $i(t):new $i(Te.stringToUtf8ByteArray(t))}},Tn=class{static EOF(){return-8}canCheckPrefix(){return!0}endPos(){return this.end}},Ba=class extends Tn{constructor(t,n=0,r=t.length){super(),this.bytes=t,this.start=n,this.end=r}step(t){if(t+=this.start,t>=this.end)return Tn.EOF();let n=this.bytes[t++]&255;return(n&128)===0?n<<3|1:(n&224)===192?(n=n&31,t>=this.end?Tn.EOF():(n=n<<6|this.bytes[t++]&63,n<<3|2)):(n&240)===224?(n=n&15,t+1>=this.end?Tn.EOF():(n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n<<3|3)):(n=n&7,t+2>=this.end?Tn.EOF():(n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n=n<<6|this.bytes[t++]&63,n<<3|4))}index(t,n){n+=this.start;let r=this.indexOf(this.bytes,t.prefixUTF8,n);return r<0?r:r-n}context(t){t+=this.start;let n=-1;if(t>this.start&&t<=this.end){let s=t-1;if(n=this.bytes[s--],n>=128){let i=t-4;for(i=i&&(this.bytes[s]&192)===128;)s--;s>3}}let r=t>3:-1;return Te.emptyOpContext(n,r)}indexOf(t,n,r=0){let s=n.length;if(s===0)return-1;let i=t.length;for(let o=r;o<=i-s;o++)for(let a=0;a0&&t<=this.charSequence.length?this.charSequence.codePointAt(t-1):-1,r=t{let s=r.codePointAt(0);return s===D.CODES.get("\\")||s===D.CODES.get("$")?`\\${r}`:r}).join(""):t.indexOf("$")<0?t:t.split("").map(r=>r.codePointAt(0)===D.CODES.get("$")?"$$":r).join("")}constructor(t,n){if(t===null)throw new Error("pattern is null");this.patternInput=t;let r=this.patternInput.re2();this.patternGroupCount=r.numberOfCapturingGroups(),this.groups=[],this.namedGroups=r.namedGroups,this.numberOfInstructions=r.numberOfInstructions(),n instanceof Jn?this.resetMatcherInput(n):Array.isArray(n)?this.resetMatcherInput(Kr.utf8(n)):this.resetMatcherInput(Kr.utf16(n))}pattern(){return this.patternInput}reset(){return this.matcherInputLength=this.matcherInput.length(),this.appendPos=0,this.hasMatch=!1,this.hasGroups=!1,this.anchorFlag=0,this}resetMatcherInput(t){if(t===null)throw new Error("input is null");return this.matcherInput=t,this.reset(),this}start(t=0){if(typeof t=="string"){let n=this.namedGroups[t];if(!Number.isFinite(n))throw new mn(`group '${t}' not found`);t=n}return this.loadGroup(t),this.groups[2*t]}end(t=0){if(typeof t=="string"){let n=this.namedGroups[t];if(!Number.isFinite(n))throw new mn(`group '${t}' not found`);t=n}return this.loadGroup(t),this.groups[2*t+1]}programSize(){return this.numberOfInstructions}group(t=0){if(typeof t=="string"){let s=this.namedGroups[t];if(!Number.isFinite(s))throw new mn(`group '${t}' not found`);t=s}let n=this.start(t),r=this.end(t);return n<0&&r<0?null:this.substring(n,r)}groupCount(){return this.patternGroupCount}loadGroup(t){if(t<0||t>this.patternGroupCount)throw new mn(`Group index out of bounds: ${t}`);if(!this.hasMatch)throw new mn("perhaps no match attempted");if(t===0||this.hasGroups)return;let n=this.groups[1]+1;n>this.matcherInputLength&&(n=this.matcherInputLength);let r=this.patternInput.re2().matchMachineInput(this.matcherInput,this.groups[0],n,this.anchorFlag,1+this.patternGroupCount);if(!r[0])throw new mn("inconsistency in matching group data");this.groups=r[1],this.hasGroups=!0}matches(){return this.genMatch(0,V.ANCHOR_BOTH)}lookingAt(){return this.genMatch(0,V.ANCHOR_START)}find(t=null){if(t!==null){if(t<0||t>this.matcherInputLength)throw new mn(`start index out of bounds: ${t}`);return this.reset(),this.genMatch(t,0)}return t=0,this.hasMatch&&(t=this.groups[1],this.groups[0]===this.groups[1]&&t++),this.genMatch(t,V.UNANCHORED)}genMatch(t,n){let r=this.patternInput.re2().matchMachineInput(this.matcherInput,t,this.matcherInputLength,n,1);return r[0]?(this.groups=r[1],this.hasMatch=!0,this.hasGroups=!1,this.anchorFlag=n,!0):!1}substring(t,n){return this.matcherInput.isUTF8Encoding()?Te.utf8ByteArrayToString(this.matcherInput.asBytes().slice(t,n)):this.matcherInput.asCharSequence().substring(t,n).toString()}inputLength(){return this.matcherInputLength}appendReplacement(t,n=!1){let r="",s=this.start(),i=this.end();return this.appendPosD.CODES.get("9")||a*10+o-D.CODES.get("0")>this.patternGroupCount));i++)a=a*10+o-D.CODES.get("0");if(a>this.patternGroupCount)throw new mn(`n > number of groups: ${a}`);let l=this.group(a);l!==null&&(n+=l),r=i,i--;continue}else if(o===D.CODES.get("{")){rD.CODES.get("9")||a*10+o-D.CODES.get("0")>this.patternGroupCount));i++)a=a*10+o-D.CODES.get("0");if(a>this.patternGroupCount){n+=`$${a}`,r=i,i--;continue}let l=this.group(a);l!==null&&(n+=l),r=i,i--;continue}else if(o===D.CODES.get("<")){r")&&t.codePointAt(a)!==D.CODES.get(" ");)a++;if(a===t.length||t.codePointAt(a)!==D.CODES.get(">")){n+=t.substring(i-1,a+1),r=a+1;continue}let l=t.substring(i+1,a);Object.prototype.hasOwnProperty.call(this.namedGroups,l)?n+=this.group(l):n+=`$<${l}>`,r=a+1}}return r ${this.out}, ${this.arg}`;case e.ALT_MATCH:return`altmatch -> ${this.out}, ${this.arg}`;case e.CAPTURE:return`cap ${this.arg} -> ${this.out}`;case e.EMPTY_WIDTH:return`empty ${this.arg} -> ${this.out}`;case e.MATCH:return"match";case e.FAIL:return"fail";case e.NOP:return`nop -> ${this.out}`;case e.RUNE:return this.runes===null?"rune ":["rune ",e.escapeRunes(this.runes),(this.arg&V.FOLD_CASE)!==0?"/i":""," -> ",this.out].join("");case e.RUNE1:return`rune1 ${e.escapeRunes(this.runes)} -> ${this.out}`;case e.RUNE_ANY:return`any -> ${this.out}`;case e.RUNE_ANY_NOT_NL:return`anynotnl -> ${this.out}`;default:throw new Error("unhandled case in Inst.toString")}}},ja=class{constructor(){this.inst=null,this.cap=[]}},Oi=class{constructor(){this.sparse=[],this.densePcs=[],this.denseThreads=[],this.size=0}contains(t){let n=this.sparse[t];return nthis.matchcap.length?this.initNewCap(t):this.resetCap(t)}resetCap(t){for(let n=0;n0?(this.poolSize--,n=this.pool[this.poolSize]):n=new ja,n.inst=t,n}freeQueue(t,n=0){let r=t.size-n,s=this.poolSize+r;this.pool.length>3,c=a&7,u=-1,f=0;a!==Tn.EOF()&&(a=t.step(n+c),u=a>>3,f=a&7);let p;for(n===0?p=Te.emptyOpContext(-1,l):p=t.context(n);;){if(i.isEmpty()){if((s&Te.EMPTY_BEGIN_TEXT)!==0&&n!==0||this.matched)break;if(this.re2.prefix.length!==0&&u!==this.re2.prefixRune&&t.canCheckPrefix()){let m=t.index(this.re2,n);if(m<0)break;n+=m,a=t.step(n),l=a>>3,c=a&7,a=t.step(n+c),u=a>>3,f=a&7}}!this.matched&&(n===0||r===V.UNANCHORED)&&(this.ncap>0&&(this.matchcap[0]=n),this.add(i,this.prog.start,n,this.matchcap,p,null));let h=n+c;if(p=t.context(h),this.step(i,o,n,h,l,p,r,n===t.endPos()),c===0||this.ncap===0&&this.matched)break;n+=c,l=u,c=f,l!==-1&&(a=t.step(n+c),u=a>>3,f=a&7);let d=i;i=o,o=d}return this.freeQueue(o),this.matched}step(t,n,r,s,i,o,a,l){let c=this.re2.longest;for(let u=0;u0&&this.matchcap[0]0&&(!c||!this.matched||this.matchcap[1]0&&o.cap!==s&&(o.cap=s.slice(0,this.ncap)),t.denseThreads[a]=o,o=null;break;default:throw new Error("unhandled")}return o}},W4=e=>{let t=-2128831035;for(let n=0;n{if(e.length!==t.length)return!1;for(let n=0;n0;){let o=r.pop();if(n.has(o))continue;n.add(o);let a=this.prog.getInst(o);switch(a.op){case he.MATCH:s=!0;break;case he.ALT:case he.ALT_MATCH:r.push(a.out),r.push(a.arg);break;case he.NOP:case he.CAPTURE:r.push(a.out);break;case he.EMPTY_WIDTH:return null}}return{pcs:Int32Array.from(n).sort(),isMatch:s}}getState(t){let n=this.computeClosure(t);if(!n)return null;let r=n.pcs,s=W4(r),i=this.stateCache.get(s);if(i)for(let a=0;a=this.stateLimit)return this.stateCache.clear(),this.stateCount=0,this.startState=null,null;let o=new Ga(r,n.isMatch);return i.push(o),this.stateCount++,o}step(t,n,r){if(r===V.UNANCHORED&&n<=ue.MAX_ASCII){let o=t.nextAscii[n];if(o!==null)return o}else{let o=n+(r===V.UNANCHORED?0:ue.MAX_RUNE+1);if(t.nextMap.has(o))return t.nextMap.get(o)}let s=[];for(let o=0;o>3,c=a&7;if(c===0)break;if(i=this.step(i,l,r),i===null)return null;if(i.isMatch)if(r===V.ANCHOR_BOTH){if(o+c===s)return!0}else return!0;if(i.nfaStates.length===0&&r!==V.UNANCHORED)return!1;o+=c}return!1}},_=class e{static Op=O1(["NO_MATCH","EMPTY_MATCH","LITERAL","CHAR_CLASS","ANY_CHAR_NOT_NL","ANY_CHAR","BEGIN_LINE","END_LINE","BEGIN_TEXT","END_TEXT","WORD_BOUNDARY","NO_WORD_BOUNDARY","CAPTURE","STAR","PLUS","QUEST","REPEAT","CONCAT","ALTERNATE","LEFT_PAREN","VERTICAL_BAR"]);static isPseudoOp(t){return t>=e.Op.LEFT_PAREN}static emptySubs(){return[]}static quoteIfHyphen(t){return t===D.CODES.get("-")?"\\":""}static fromRegexp(t){let n=new e(t.op);return n.flags=t.flags,n.subs=t.subs,n.runes=t.runes,n.cap=t.cap,n.min=t.min,n.max=t.max,n.name=t.name,n.namedGroups=t.namedGroups,n}constructor(t){this.op=t,this.flags=0,this.subs=e.emptySubs(),this.runes=[],this.min=0,this.max=0,this.cap=0,this.name=null,this.namedGroups={}}reinit(){this.flags=0,this.subs=e.emptySubs(),this.runes=[],this.cap=0,this.min=0,this.max=0,this.name=null,this.namedGroups={}}toString(){return this.appendTo()}appendTo(){let t="";switch(this.op){case e.Op.NO_MATCH:t+="[^\\x00-\\x{10FFFF}]";break;case e.Op.EMPTY_MATCH:t+="(?:)";break;case e.Op.STAR:case e.Op.PLUS:case e.Op.QUEST:case e.Op.REPEAT:{let n=this.subs[0];switch(n.op>e.Op.CAPTURE||n.op===e.Op.LITERAL&&n.runes.length>1?t+=`(?:${n.appendTo()})`:t+=n.appendTo(),this.op){case e.Op.STAR:t+="*";break;case e.Op.PLUS:t+="+";break;case e.Op.QUEST:t+="?";break;case e.Op.REPEAT:t+=`{${this.min}`,this.min!==this.max&&(t+=",",this.max>=0&&(t+=this.max)),t+="}";break}(this.flags&V.NON_GREEDY)!==0&&(t+="?");break}case e.Op.CONCAT:{for(let n of this.subs)n.op===e.Op.ALTERNATE?t+=`(?:${n.appendTo()})`:t+=n.appendTo();break}case e.Op.ALTERNATE:{let n="";for(let r of this.subs)t+=n,n="|",t+=r.appendTo();break}case e.Op.LITERAL:(this.flags&V.FOLD_CASE)!==0&&(t+="(?i:");for(let n of this.runes)t+=Te.escapeRune(n);(this.flags&V.FOLD_CASE)!==0&&(t+=")");break;case e.Op.ANY_CHAR_NOT_NL:t+="(?-s:.)";break;case e.Op.ANY_CHAR:t+="(?s:.)";break;case e.Op.CAPTURE:this.name===null||this.name.length===0?t+="(":t+=`(?P<${this.name}>`,this.subs[0].op!==e.Op.EMPTY_MATCH&&(t+=this.subs[0].appendTo()),t+=")";break;case e.Op.BEGIN_TEXT:t+="\\A";break;case e.Op.END_TEXT:(this.flags&V.WAS_DOLLAR)!==0?t+="(?-m:$)":t+="\\z";break;case e.Op.BEGIN_LINE:t+="^";break;case e.Op.END_LINE:t+="$";break;case e.Op.WORD_BOUNDARY:t+="\\b";break;case e.Op.NO_WORD_BOUNDARY:t+="\\B";break;case e.Op.CHAR_CLASS:if(this.runes.length%2!==0){t+="[invalid char class]";break}if(t+="[",this.runes.length===0)t+="^\\x00-\\x{10FFFF}";else if(this.runes[0]===0&&this.runes[this.runes.length-1]===ue.MAX_RUNE){t+="^";for(let n=1;n>1];return(t&1)===0?n.out:n.arg}patch(t,n){for(;t!==0;){let r=this.inst[t>>1];(t&1)===0?(t=r.out,r.out=n):(t=r.arg,r.arg=n)}}append(t,n){if(t===0)return n;if(n===0)return t;let r=t;for(;;){let i=this.next(r);if(i===0)break;r=i}let s=this.inst[r>>1];return(r&1)===0?s.out=n:s.arg=n,t}toString(){let t="";for(let n=0;n0){r=[];for(let s=0;st.min){let s=e.simplify1(_.Op.QUEST,t.flags,n,null);for(let i=t.min+1;i0&&(r+=" ");let i=t[s],o=t[s+1];i===o?r+=`0x${i.toString(16)}`:r+=`0x${i.toString(16)}-0x${o.toString(16)}`}return r+="]",r}static cmp(t,n,r,s){let i=t[n]-r;return i!==0?i:s-t[n+1]}static qsortIntPair(t,n,r){let s=((n+r)/2|0)&-2,i=t[s],o=t[s+1],a=n,l=r;for(;a<=l;){for(;an&&e.cmp(t,l,i,o)>0;)l-=2;if(a<=l){if(a!==l){let c=t[a];t[a]=t[l],t[l]=c,c=t[a+1],t[a+1]=t[l+1],t[l+1]=c}a+=2,l-=2}}nthis.r[t-1]&&(this.r[t-1]=s);continue}this.r[t]=r,this.r[t+1]=s,t+=2}return this.len=t,this}appendLiteral(t,n){return(n&V.FOLD_CASE)!==0?this.appendFoldedRange(t,t):this.appendRange(t,t)}appendRange(t,n){if(this.len>0){for(let r=2;r<=4;r+=2)if(this.len>=r){let s=this.r[this.len-r],i=this.r[this.len-r+1];if(t<=i+1&&s<=n+1)return ti&&(this.r[this.len-r+1]=n),this}}return this.r[this.len++]=t,this.r[this.len++]=n,this}appendFoldedRange(t,n){if(t<=ue.MIN_FOLD&&n>=ue.MAX_FOLD)return this.appendRange(t,n);if(nue.MAX_FOLD)return this.appendRange(t,n);tue.MAX_FOLD&&(this.appendRange(ue.MAX_FOLD+1,n),n=ue.MAX_FOLD);for(let r=t;r<=n;r++){this.appendRange(r,r);for(let s=ue.simpleFold(r);s!==r;s=ue.simpleFold(s))this.appendRange(s,s)}return this}appendClass(t){for(let n=0;nue.MAX_FOLD)return t;let n=t,r=t;for(t=ue.simpleFold(t);t!==r;t=ue.simpleFold(t))n>t&&(n=t);return n}static leadingRegexp(t){if(t.op===_.Op.EMPTY_MATCH)return null;if(t.op===_.Op.CONCAT&&t.subs.length>0){let n=t.subs[0];return n.op===_.Op.EMPTY_MATCH?null:n}return t}static literalRegexp(t,n){let r=new _(_.Op.LITERAL);return r.flags=n,r.runes=Oe.stringToRunes(t),r}static parse(t,n){return new e(t,n).parseInternal()}static parseRepeat(t){let n=t.pos();if(!t.more()||!t.lookingAt("{"))return-1;t.skip(1);let r=e.parseInt(t);if(r===-1||!t.more())return-1;let s;if(!t.lookingAt(","))s=r;else{if(t.skip(1),!t.more())return-1;if(t.lookingAt("}"))s=-1;else if((s=e.parseInt(t))===-1)return-1}if(!t.more()||!t.lookingAt("}"))return-1;if(t.skip(1),r<0||r>1e3||s===-2||s>1e3||s>=0&&r>s)throw new je(e.ERR_INVALID_REPEAT_SIZE,t.from(n));return r<<16|s&ue.MAX_BMP}static isValidCaptureName(t){if(t.length===0)return!1;for(let n=0;n=D.CODES.get("0")&&t.peek()<=D.CODES.get("9");)t.skip(1);let r=t.from(n);return r.length===0||r.length>1&&r.codePointAt(0)===D.CODES.get("0")?-1:r.length>8?-2:parseFloat(r,10)}static isCharClass(t){return t.op===_.Op.LITERAL&&t.runes.length===1||t.op===_.Op.CHAR_CLASS||t.op===_.Op.ANY_CHAR_NOT_NL||t.op===_.Op.ANY_CHAR}static matchRune(t,n){switch(t.op){case _.Op.LITERAL:return t.runes.length===1&&t.runes[0]===n;case _.Op.CHAR_CLASS:for(let r=0;r0){r=[];for(let s=0;st.min){let s=e.simplify1(_.Op.QUEST,t.flags,n,null);for(let i=t.min+1;i0&&(r+=" ");let i=t[s],o=t[s+1];i===o?r+=`0x${i.toString(16)}`:r+=`0x${i.toString(16)}-0x${o.toString(16)}`}return r+="]",r}static cmp(t,n,r,s){let i=t[n]-r;return i!==0?i:s-t[n+1]}static qsortIntPair(t,n,r){let s=((n+r)/2|0)&-2,i=t[s],o=t[s+1],a=n,l=r;for(;a<=l;){for(;an&&e.cmp(t,l,i,o)>0;)l-=2;if(a<=l){if(a!==l){let c=t[a];t[a]=t[l],t[l]=c,c=t[a+1],t[a+1]=t[l+1],t[l+1]=c}a+=2,l-=2}}nthis.r[t-1]&&(this.r[t-1]=s);continue}this.r[t]=r,this.r[t+1]=s,t+=2}return this.len=t,this}appendLiteral(t,n){return(n&V.FOLD_CASE)!==0?this.appendFoldedRange(t,t):this.appendRange(t,t)}appendRange(t,n){if(this.len>0){for(let r=2;r<=4;r+=2)if(this.len>=r){let s=this.r[this.len-r],i=this.r[this.len-r+1];if(t<=i+1&&s<=n+1)return ti&&(this.r[this.len-r+1]=n),this}}return this.r[this.len++]=t,this.r[this.len++]=n,this}appendFoldedRange(t,n){if(t<=ue.MIN_FOLD&&n>=ue.MAX_FOLD)return this.appendRange(t,n);if(nue.MAX_FOLD)return this.appendRange(t,n);tue.MAX_FOLD&&(this.appendRange(ue.MAX_FOLD+1,n),n=ue.MAX_FOLD);for(let r=t;r<=n;r++){this.appendRange(r,r);for(let s=ue.simpleFold(r);s!==r;s=ue.simpleFold(s))this.appendRange(s,s)}return this}appendClass(t){for(let n=0;nue.MAX_FOLD)return t;let n=t,r=t;for(t=ue.simpleFold(t);t!==r;t=ue.simpleFold(t))n>t&&(n=t);return n}static leadingRegexp(t){if(t.op===_.Op.EMPTY_MATCH)return null;if(t.op===_.Op.CONCAT&&t.subs.length>0){let n=t.subs[0];return n.op===_.Op.EMPTY_MATCH?null:n}return t}static literalRegexp(t,n){let r=new _(_.Op.LITERAL);return r.flags=n,r.runes=Te.stringToRunes(t),r}static parse(t,n){return new e(t,n).parseInternal()}static parseRepeat(t){let n=t.pos();if(!t.more()||!t.lookingAt("{"))return-1;t.skip(1);let r=e.parseInt(t);if(r===-1||!t.more())return-1;let s;if(!t.lookingAt(","))s=r;else{if(t.skip(1),!t.more())return-1;if(t.lookingAt("}"))s=-1;else if((s=e.parseInt(t))===-1)return-1}if(!t.more()||!t.lookingAt("}"))return-1;if(t.skip(1),r<0||r>1e3||s===-2||s>1e3||s>=0&&r>s)throw new je(e.ERR_INVALID_REPEAT_SIZE,t.from(n));return r<<16|s&ue.MAX_BMP}static isValidCaptureName(t){if(t.length===0)return!1;for(let n=0;n=D.CODES.get("0")&&t.peek()<=D.CODES.get("9");)t.skip(1);let r=t.from(n);return r.length===0||r.length>1&&r.codePointAt(0)===D.CODES.get("0")?-1:r.length>8?-2:parseFloat(r,10)}static isCharClass(t){return t.op===_.Op.LITERAL&&t.runes.length===1||t.op===_.Op.CHAR_CLASS||t.op===_.Op.ANY_CHAR_NOT_NL||t.op===_.Op.ANY_CHAR}static matchRune(t,n){switch(t.op){case _.Op.LITERAL:return t.runes.length===1&&t.runes[0]===n;case _.Op.CHAR_CLASS:for(let r=0;rD.CODES.get("7"))break;case D.CODES.get("0"):{let s=r-D.CODES.get("0");for(let i=1;i<3&&!(!t.more()||t.peek()D.CODES.get("7"));i++)s=s*8+t.peek()-D.CODES.get("0"),t.skip(1);return s}case D.CODES.get("x"):{if(!t.more())break;if(r=t.pop(),r===D.CODES.get("{")){let o=0,a=0;for(;;){if(!t.more())break e;if(r=t.pop(),r===D.CODES.get("}"))break;let l=Oe.unhex(r);if(l<0||(a=a*16+l,a>ue.MAX_RUNE))break e;o++}if(o===0)break e;return a}let s=Oe.unhex(r);if(!t.more())break;r=t.pop();let i=Oe.unhex(r);if(s<0||i<0)break;return s*16+i}case D.CODES.get("a"):return D.CODES.get("\x07");case D.CODES.get("f"):return D.CODES.get("\f");case D.CODES.get("n"):return D.CODES.get(` -`);case D.CODES.get("r"):return D.CODES.get("\r");case D.CODES.get("t"):return D.CODES.get(" ");case D.CODES.get("v"):return D.CODES.get("\v");default:if(r<=ue.MAX_ASCII&&!Oe.isalnum(r))return r;break}throw new je(e.ERR_INVALID_ESCAPE,t.from(n))}static parseClassChar(t,n){if(!t.more())throw new je(e.ERR_MISSING_BRACKET,t.from(n));return t.lookingAt("\\")?e.parseEscape(t):t.pop()}static concatRunes(t,n){return[...t,...n]}constructor(t,n=0){this.wholeRegexp=t,this.flags=n,this.numCap=0,this.namedGroups={},this.stack=[],this.free=null,this.numRegexp=0,this.numRunes=0,this.repeats=0,this.height=null,this.size=null}newRegexp(t){let n=this.free;return n!==null&&n.subs!==null&&n.subs.length>0?(this.free=n.subs[0],n.reinit(),n.op=t):(n=new _(t),this.numRegexp+=1),n}reuse(t){this.height!==null&&Object.prototype.hasOwnProperty.call(this.height,t)&&delete this.height[t],t.subs!==null&&t.subs.length>0&&(t.subs[0]=this.free),this.free=t}checkLimits(t){if(this.numRunes>e.MAX_RUNES)throw new je(e.ERR_LARGE);this.checkSize(t),this.checkHeight(t)}checkSize(t){if(this.size===null){if(this.repeats===0&&(this.repeats=1),t.op===_.Op.REPEAT){let n=t.max;n===-1&&(n=t.min),n<=0&&(n=1),n>e.MAX_SIZE/this.repeats?this.repeats=e.MAX_SIZE:this.repeats*=n}if(this.numRegexpe.MAX_SIZE)throw new je(e.ERR_LARGE)}calcSize(t,n=!1){if(!n&&Object.prototype.hasOwnProperty.call(this.size,t))return this.size[t];let r=0;switch(t.op){case _.Op.LITERAL:{r=t.runes.length;break}case _.Op.CAPTURE:case _.Op.STAR:{r=2+this.calcSize(t.subs[0]);break}case _.Op.PLUS:case _.Op.QUEST:{r=1+this.calcSize(t.subs[0]);break}case _.Op.CONCAT:{for(let s of t.subs)r=r+this.calcSize(s);break}case _.Op.ALTERNATE:{for(let s of t.subs)r=r+this.calcSize(s);t.subs.length>1&&(r=r+t.subs.length-1);break}case _.Op.REPEAT:{let s=this.calcSize(t.subs[0]);if(t.max===-1){t.min===0?r=2+s:r=1+t.min*s;break}r=t.max*s+(t.max-t.min);break}}return r=Math.max(1,r),this.size[t]=r,r}checkHeight(t){if(!(this.numRegexpe.MAX_HEIGHT)throw new je(e.ERR_NESTING_DEPTH)}}calcHeight(t,n=!1){if(!n&&Object.prototype.hasOwnProperty.call(this.height,t))return this.height[t];let r=1;for(let s of t.subs){let i=this.calcHeight(s);r<1+i&&(r=1+i)}return this.height[t]=r,r}pop(){return this.stack.pop()}popToPseudo(){let t=this.stack.length,n=t;for(;n>0&&!_.isPseudoOp(this.stack[n-1].op);)n--;let r=this.stack.slice(n,t);return this.stack=this.stack.slice(0,n),r}push(t){if(this.numRunes+=t.runes.length,t.op===_.Op.CHAR_CLASS&&t.runes.length===2&&t.runes[0]===t.runes[1]){if(this.maybeConcat(t.runes[0],this.flags&-2))return null;t.op=_.Op.LITERAL,t.runes=[t.runes[0]],t.flags=this.flags&-2}else if(t.op===_.Op.CHAR_CLASS&&t.runes.length===4&&t.runes[0]===t.runes[1]&&t.runes[2]===t.runes[3]&&ue.simpleFold(t.runes[0])===t.runes[2]&&ue.simpleFold(t.runes[2])===t.runes[0]||t.op===_.Op.CHAR_CLASS&&t.runes.length===2&&t.runes[0]+1===t.runes[1]&&ue.simpleFold(t.runes[0])===t.runes[1]&&ue.simpleFold(t.runes[1])===t.runes[0]){if(this.maybeConcat(t.runes[0],this.flags|V.FOLD_CASE))return null;t.op=_.Op.LITERAL,t.runes=[t.runes[0]],t.flags=this.flags|V.FOLD_CASE}else this.maybeConcat(-1,0);return this.stack.push(t),this.checkLimits(t),t}maybeConcat(t,n){let r=this.stack.length;if(r<2)return!1;let s=this.stack[r-1],i=this.stack[r-2];return s.op!==_.Op.LITERAL||i.op!==_.Op.LITERAL||(s.flags&V.FOLD_CASE)!==(i.flags&V.FOLD_CASE)?!1:(i.runes=e.concatRunes(i.runes,s.runes),t>=0?(s.runes=[t],s.flags=n,!0):(this.pop(),this.reuse(s),!1))}newLiteral(t,n){let r=this.newRegexp(_.Op.LITERAL);return r.flags=n,(n&V.FOLD_CASE)!==0&&(t=e.minFoldRune(t)),r.runes=[t],r}literal(t){this.push(this.newLiteral(t,this.flags))}op(t){let n=this.newRegexp(t);return n.flags=this.flags,this.push(n)}repeat(t,n,r,s,i,o){let a=this.flags;if((a&V.PERL_X)!==0&&(i.more()&&i.lookingAt("?")&&(i.skip(1),a^=V.NON_GREEDY),o!==-1))throw new je(e.ERR_INVALID_REPEAT_OP,i.from(o));let l=this.stack.length;if(l===0)throw new je(e.ERR_MISSING_REPEAT_ARGUMENT,i.from(s));let c=this.stack[l-1];if(_.isPseudoOp(c.op))throw new je(e.ERR_MISSING_REPEAT_ARGUMENT,i.from(s));let u=this.newRegexp(t);if(u.min=n,u.max=r,u.flags=a,u.subs=[c],this.stack[l-1]=u,this.checkLimits(u),t===_.Op.REPEAT&&(n>=2||r>=2)&&!this.repeatIsValid(u,1e3))throw new je(e.ERR_INVALID_REPEAT_SIZE,i.from(s))}repeatIsValid(t,n){if(t.op===_.Op.REPEAT){let r=t.max;if(r===0)return!0;if(r<0&&(r=t.min),r>n)return!1;r>0&&(n=Math.trunc(n/r))}for(let r of t.subs)if(!this.repeatIsValid(r,n))return!1;return!0}concat(){this.maybeConcat(-1,0);let t=this.popToPseudo();return t.length===0?this.push(this.newRegexp(_.Op.EMPTY_MATCH)):this.push(this.collapse(t,_.Op.CONCAT))}alternate(){let t=this.popToPseudo();return t.length>0&&this.cleanAlt(t[t.length-1]),t.length===0?this.push(this.newRegexp(_.Op.NO_MATCH)):this.push(this.collapse(t,_.Op.ALTERNATE))}cleanAlt(t){t.op===_.Op.CHAR_CLASS&&(t.runes=new Ln(t.runes).cleanClass().toArray(),t.runes.length===2&&t.runes[0]===0&&t.runes[1]===ue.MAX_RUNE?(t.runes=[],t.op=_.Op.ANY_CHAR):t.runes.length===4&&t.runes[0]===0&&t.runes[1]===D.CODES.get(` +`))&&(t.op=_.Op.ANY_CHAR);break;case _.Op.CHAR_CLASS:n.op===_.Op.LITERAL?t.runes=new $n(t.runes).appendLiteral(n.runes[0],n.flags).toArray():t.runes=new $n(t.runes).appendClass(n.runes).toArray();break;case _.Op.LITERAL:if(n.runes[0]===t.runes[0]&&n.flags===t.flags)break;t.op=_.Op.CHAR_CLASS,t.runes=new $n().appendLiteral(t.runes[0],t.flags).appendLiteral(n.runes[0],n.flags).toArray();break}}static parseEscape(t){let n=t.pos();if(t.skip(1),!t.more())throw new je(e.ERR_TRAILING_BACKSLASH);let r=t.pop();e:switch(r){case D.CODES.get("1"):case D.CODES.get("2"):case D.CODES.get("3"):case D.CODES.get("4"):case D.CODES.get("5"):case D.CODES.get("6"):case D.CODES.get("7"):if(!t.more()||t.peek()D.CODES.get("7"))break;case D.CODES.get("0"):{let s=r-D.CODES.get("0");for(let i=1;i<3&&!(!t.more()||t.peek()D.CODES.get("7"));i++)s=s*8+t.peek()-D.CODES.get("0"),t.skip(1);return s}case D.CODES.get("x"):{if(!t.more())break;if(r=t.pop(),r===D.CODES.get("{")){let o=0,a=0;for(;;){if(!t.more())break e;if(r=t.pop(),r===D.CODES.get("}"))break;let l=Te.unhex(r);if(l<0||(a=a*16+l,a>ue.MAX_RUNE))break e;o++}if(o===0)break e;return a}let s=Te.unhex(r);if(!t.more())break;r=t.pop();let i=Te.unhex(r);if(s<0||i<0)break;return s*16+i}case D.CODES.get("a"):return D.CODES.get("\x07");case D.CODES.get("f"):return D.CODES.get("\f");case D.CODES.get("n"):return D.CODES.get(` +`);case D.CODES.get("r"):return D.CODES.get("\r");case D.CODES.get("t"):return D.CODES.get(" ");case D.CODES.get("v"):return D.CODES.get("\v");default:if(r<=ue.MAX_ASCII&&!Te.isalnum(r))return r;break}throw new je(e.ERR_INVALID_ESCAPE,t.from(n))}static parseClassChar(t,n){if(!t.more())throw new je(e.ERR_MISSING_BRACKET,t.from(n));return t.lookingAt("\\")?e.parseEscape(t):t.pop()}static concatRunes(t,n){return[...t,...n]}constructor(t,n=0){this.wholeRegexp=t,this.flags=n,this.numCap=0,this.namedGroups={},this.stack=[],this.free=null,this.numRegexp=0,this.numRunes=0,this.repeats=0,this.height=null,this.size=null}newRegexp(t){let n=this.free;return n!==null&&n.subs!==null&&n.subs.length>0?(this.free=n.subs[0],n.reinit(),n.op=t):(n=new _(t),this.numRegexp+=1),n}reuse(t){this.height!==null&&Object.prototype.hasOwnProperty.call(this.height,t)&&delete this.height[t],t.subs!==null&&t.subs.length>0&&(t.subs[0]=this.free),this.free=t}checkLimits(t){if(this.numRunes>e.MAX_RUNES)throw new je(e.ERR_LARGE);this.checkSize(t),this.checkHeight(t)}checkSize(t){if(this.size===null){if(this.repeats===0&&(this.repeats=1),t.op===_.Op.REPEAT){let n=t.max;n===-1&&(n=t.min),n<=0&&(n=1),n>e.MAX_SIZE/this.repeats?this.repeats=e.MAX_SIZE:this.repeats*=n}if(this.numRegexpe.MAX_SIZE)throw new je(e.ERR_LARGE)}calcSize(t,n=!1){if(!n&&Object.prototype.hasOwnProperty.call(this.size,t))return this.size[t];let r=0;switch(t.op){case _.Op.LITERAL:{r=t.runes.length;break}case _.Op.CAPTURE:case _.Op.STAR:{r=2+this.calcSize(t.subs[0]);break}case _.Op.PLUS:case _.Op.QUEST:{r=1+this.calcSize(t.subs[0]);break}case _.Op.CONCAT:{for(let s of t.subs)r=r+this.calcSize(s);break}case _.Op.ALTERNATE:{for(let s of t.subs)r=r+this.calcSize(s);t.subs.length>1&&(r=r+t.subs.length-1);break}case _.Op.REPEAT:{let s=this.calcSize(t.subs[0]);if(t.max===-1){t.min===0?r=2+s:r=1+t.min*s;break}r=t.max*s+(t.max-t.min);break}}return r=Math.max(1,r),this.size[t]=r,r}checkHeight(t){if(!(this.numRegexpe.MAX_HEIGHT)throw new je(e.ERR_NESTING_DEPTH)}}calcHeight(t,n=!1){if(!n&&Object.prototype.hasOwnProperty.call(this.height,t))return this.height[t];let r=1;for(let s of t.subs){let i=this.calcHeight(s);r<1+i&&(r=1+i)}return this.height[t]=r,r}pop(){return this.stack.pop()}popToPseudo(){let t=this.stack.length,n=t;for(;n>0&&!_.isPseudoOp(this.stack[n-1].op);)n--;let r=this.stack.slice(n,t);return this.stack=this.stack.slice(0,n),r}push(t){if(this.numRunes+=t.runes.length,t.op===_.Op.CHAR_CLASS&&t.runes.length===2&&t.runes[0]===t.runes[1]){if(this.maybeConcat(t.runes[0],this.flags&-2))return null;t.op=_.Op.LITERAL,t.runes=[t.runes[0]],t.flags=this.flags&-2}else if(t.op===_.Op.CHAR_CLASS&&t.runes.length===4&&t.runes[0]===t.runes[1]&&t.runes[2]===t.runes[3]&&ue.simpleFold(t.runes[0])===t.runes[2]&&ue.simpleFold(t.runes[2])===t.runes[0]||t.op===_.Op.CHAR_CLASS&&t.runes.length===2&&t.runes[0]+1===t.runes[1]&&ue.simpleFold(t.runes[0])===t.runes[1]&&ue.simpleFold(t.runes[1])===t.runes[0]){if(this.maybeConcat(t.runes[0],this.flags|V.FOLD_CASE))return null;t.op=_.Op.LITERAL,t.runes=[t.runes[0]],t.flags=this.flags|V.FOLD_CASE}else this.maybeConcat(-1,0);return this.stack.push(t),this.checkLimits(t),t}maybeConcat(t,n){let r=this.stack.length;if(r<2)return!1;let s=this.stack[r-1],i=this.stack[r-2];return s.op!==_.Op.LITERAL||i.op!==_.Op.LITERAL||(s.flags&V.FOLD_CASE)!==(i.flags&V.FOLD_CASE)?!1:(i.runes=e.concatRunes(i.runes,s.runes),t>=0?(s.runes=[t],s.flags=n,!0):(this.pop(),this.reuse(s),!1))}newLiteral(t,n){let r=this.newRegexp(_.Op.LITERAL);return r.flags=n,(n&V.FOLD_CASE)!==0&&(t=e.minFoldRune(t)),r.runes=[t],r}literal(t){this.push(this.newLiteral(t,this.flags))}op(t){let n=this.newRegexp(t);return n.flags=this.flags,this.push(n)}repeat(t,n,r,s,i,o){let a=this.flags;if((a&V.PERL_X)!==0&&(i.more()&&i.lookingAt("?")&&(i.skip(1),a^=V.NON_GREEDY),o!==-1))throw new je(e.ERR_INVALID_REPEAT_OP,i.from(o));let l=this.stack.length;if(l===0)throw new je(e.ERR_MISSING_REPEAT_ARGUMENT,i.from(s));let c=this.stack[l-1];if(_.isPseudoOp(c.op))throw new je(e.ERR_MISSING_REPEAT_ARGUMENT,i.from(s));let u=this.newRegexp(t);if(u.min=n,u.max=r,u.flags=a,u.subs=[c],this.stack[l-1]=u,this.checkLimits(u),t===_.Op.REPEAT&&(n>=2||r>=2)&&!this.repeatIsValid(u,1e3))throw new je(e.ERR_INVALID_REPEAT_SIZE,i.from(s))}repeatIsValid(t,n){if(t.op===_.Op.REPEAT){let r=t.max;if(r===0)return!0;if(r<0&&(r=t.min),r>n)return!1;r>0&&(n=Math.trunc(n/r))}for(let r of t.subs)if(!this.repeatIsValid(r,n))return!1;return!0}concat(){this.maybeConcat(-1,0);let t=this.popToPseudo();return t.length===0?this.push(this.newRegexp(_.Op.EMPTY_MATCH)):this.push(this.collapse(t,_.Op.CONCAT))}alternate(){let t=this.popToPseudo();return t.length>0&&this.cleanAlt(t[t.length-1]),t.length===0?this.push(this.newRegexp(_.Op.NO_MATCH)):this.push(this.collapse(t,_.Op.ALTERNATE))}cleanAlt(t){t.op===_.Op.CHAR_CLASS&&(t.runes=new $n(t.runes).cleanClass().toArray(),t.runes.length===2&&t.runes[0]===0&&t.runes[1]===ue.MAX_RUNE?(t.runes=[],t.op=_.Op.ANY_CHAR):t.runes.length===4&&t.runes[0]===0&&t.runes[1]===D.CODES.get(` `)-1&&t.runes[2]===D.CODES.get(` -`)+1&&t.runes[3]===ue.MAX_RUNE&&(t.runes=[],t.op=_.Op.ANY_CHAR_NOT_NL))}collapse(t,n){if(t.length===1)return t[0];let r=0;for(let a of t)r+=a.op===n?a.subs.length:1;let s=new Array(r).fill(null),i=0;for(let a of t)a.op===n?(s.splice(i,a.subs.length,...a.subs),i+=a.subs.length,this.reuse(a)):s[i++]=a;let o=this.newRegexp(n);if(o.subs=s,n===_.Op.ALTERNATE&&(o.subs=this.factor(o.subs),o.subs.length===1)){let a=o;o=o.subs[0],this.reuse(a)}return o}factor(t){if(t.length<2)return t;let n=0,r=t.length,s=0,i=null,o=0,a=0,l=0;for(let u=0;u<=r;u++){let f=null,p=0,h=0;if(u0&&(d=d.subs[0]),d.op===_.Op.LITERAL&&(f=d.runes,p=d.runes.length,h=d.flags&V.FOLD_CASE),h===a){let m=0;for(;m0){o=m;continue}}}if(u!==l)if(u===l+1)t[s++]=t[n+l];else{let d=this.newRegexp(_.Op.LITERAL);d.flags=a,d.runes=i.slice(0,o);for(let y=l;y0){let r=this.removeLeadingString(t.subs[0],n);if(t.subs[0]=r,r.op===_.Op.EMPTY_MATCH)switch(this.reuse(r),t.subs.length){case 0:case 1:t.op=_.Op.EMPTY_MATCH,t.subs=null;break;case 2:{let s=t;t=t.subs[1],this.reuse(s);break}default:t.subs=t.subs.slice(1,t.subs.length);break}return t}return t.op===_.Op.LITERAL&&(t.runes=t.runes.slice(n,t.runes.length),t.runes.length===0&&(t.op=_.Op.EMPTY_MATCH)),t}removeLeadingRegexp(t,n){if(t.op===_.Op.CONCAT&&t.subs.length>0){switch(n&&this.reuse(t.subs[0]),t.subs=t.subs.slice(1,t.subs.length),t.subs.length){case 0:{t.op=_.Op.EMPTY_MATCH,t.subs=_.emptySubs();break}case 1:{let r=t;t=t.subs[0],this.reuse(r);break}}return t}return n&&this.reuse(t),this.newRegexp(_.Op.EMPTY_MATCH)}parseInternal(){if((this.flags&V.LITERAL)!==0)return e.literalRegexp(this.wholeRegexp,this.flags);let t=-1,n=-1,r=-1,s=new dl(this.wholeRegexp);for(;s.more();){let o=-1;e:switch(s.peek()){case D.CODES.get("("):if((this.flags&V.PERL_X)!==0&&s.lookingAt("(?")){this.parsePerlFlags(s);break}this.op(_.Op.LEFT_PAREN).cap=++this.numCap,s.skip(1);break;case D.CODES.get("|"):this.parseVerticalBar(),s.skip(1);break;case D.CODES.get(")"):this.parseRightParen(),s.skip(1);break;case D.CODES.get("^"):(this.flags&V.ONE_LINE)!==0?this.op(_.Op.BEGIN_TEXT):this.op(_.Op.BEGIN_LINE),s.skip(1);break;case D.CODES.get("$"):(this.flags&V.ONE_LINE)!==0?this.op(_.Op.END_TEXT).flags|=V.WAS_DOLLAR:this.op(_.Op.END_LINE),s.skip(1);break;case D.CODES.get("."):(this.flags&V.DOT_NL)!==0?this.op(_.Op.ANY_CHAR):this.op(_.Op.ANY_CHAR_NOT_NL),s.skip(1);break;case D.CODES.get("["):this.parseClass(s);break;case D.CODES.get("*"):case D.CODES.get("+"):case D.CODES.get("?"):{o=s.pos();let a=null;switch(s.pop()){case D.CODES.get("*"):a=_.Op.STAR;break;case D.CODES.get("+"):a=_.Op.PLUS;break;case D.CODES.get("?"):a=_.Op.QUEST;break}this.repeat(a,n,r,o,s,t);break}case D.CODES.get("{"):{o=s.pos();let a=e.parseRepeat(s);if(a<0){s.rewindTo(o),this.literal(s.pop());break}n=a>>16,r=(a&ue.MAX_BMP)<<16>>16,this.repeat(_.Op.REPEAT,n,r,o,s,t);break}case D.CODES.get("\\"):{let a=s.pos();if(s.skip(1),(this.flags&V.PERL_X)!==0&&s.more())switch(s.pop()){case D.CODES.get("A"):this.op(_.Op.BEGIN_TEXT);break e;case D.CODES.get("b"):this.op(_.Op.WORD_BOUNDARY);break e;case D.CODES.get("B"):this.op(_.Op.NO_WORD_BOUNDARY);break e;case D.CODES.get("C"):throw new je(e.ERR_INVALID_ESCAPE,"\\C");case D.CODES.get("Q"):{let f=s.rest(),p=f.indexOf("\\E");p>=0&&(f=f.substring(0,p)),s.skipString(f),s.skipString("\\E");let h=0;for(;h");if(l<0)throw new je(e.ERR_INVALID_NAMED_CAPTURE,r);let c=r.substring(a,l);if(t.skipString(c),t.skip(a+1),!e.isValidCaptureName(c))throw new je(e.ERR_INVALID_NAMED_CAPTURE,r.substring(0,l+1));let u=this.op(_.Op.LEFT_PAREN);if(u.cap=++this.numCap,this.namedGroups[c])throw new je(e.ERR_DUPLICATE_NAMED_CAPTURE,c);this.namedGroups[c]=this.numCap,u.name=c;return}t.skip(2);let s=this.flags,i=1,o=!1;e:for(;t.more();){let a=t.pop();switch(a){case D.CODES.get("i"):s|=V.FOLD_CASE,o=!0;break;case D.CODES.get("m"):s&=-17,o=!0;break;case D.CODES.get("s"):s|=V.DOT_NL,o=!0;break;case D.CODES.get("U"):s|=V.NON_GREEDY,o=!0;break;case D.CODES.get("-"):if(i<0)break e;i=-1,s=~s,o=!1;break;case D.CODES.get(":"):case D.CODES.get(")"):if(i<0){if(!o)break e;s=~s}a===D.CODES.get(":")&&this.op(_.Op.LEFT_PAREN),this.flags=s;return;default:break e}}throw new je(e.ERR_INVALID_PERL_OP,t.from(n))}parseVerticalBar(){this.concat(),this.swapVerticalBar()||this.op(_.Op.VERTICAL_BAR)}swapVerticalBar(){let t=this.stack.length;if(t>=3&&this.stack[t-2].op===_.Op.VERTICAL_BAR&&e.isCharClass(this.stack[t-1])&&e.isCharClass(this.stack[t-3])){let n=this.stack[t-1],r=this.stack[t-3];if(n.op>r.op){let s=r;r=n,n=s,this.stack[t-3]=r}return e.mergeCharClass(r,n),this.reuse(n),this.pop(),!0}if(t>=2){let n=this.stack[t-1],r=this.stack[t-2];if(r.op===_.Op.VERTICAL_BAR)return t>=3&&this.cleanAlt(this.stack[t-3]),this.stack[t-2]=n,this.stack[t-1]=r,!0}return!1}parseRightParen(){if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),this.stack.length<2)throw new je(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);let n=this.pop(),r=this.pop();if(r.op!==_.Op.LEFT_PAREN)throw new je(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);this.flags=r.flags,r.cap===0?this.push(n):(r.op=_.Op.CAPTURE,r.subs=[n],this.push(r))}parsePerlClassEscape(t,n){let r=t.pos();if((this.flags&V.PERL_X)===0||!t.more()||t.pop()!==D.CODES.get("\\")||!t.more())return!1;t.pop();let s=t.from(r),i=H1.has(s)?H1.get(s):null;return i===null?!1:(n.appendGroup(i,(this.flags&V.FOLD_CASE)!==0),!0)}parseNamedClass(t,n){let r=t.rest(),s=r.indexOf(":]");if(s<0)return!1;let i=r.substring(0,s+2);t.skipString(i);let o=sp.has(i)?sp.get(i):null;if(o===null)throw new je(e.ERR_INVALID_CHAR_RANGE,i);return n.appendGroup(o,(this.flags&V.FOLD_CASE)!==0),!0}parseUnicodeClass(t,n){let r=t.pos();if((this.flags&V.UNICODE_GROUPS)===0||!t.lookingAt("\\p")&&!t.lookingAt("\\P"))return!1;t.skip(1);let s=1,i=t.pop();if(i===D.CODES.get("P")&&(s=-1),!t.more())throw t.rewindTo(r),new je(e.ERR_INVALID_CHAR_RANGE,t.rest());i=t.pop();let o;if(i!==D.CODES.get("{"))o=Oe.runeToString(i);else{let u=t.rest(),f=u.indexOf("}");if(f<0)throw t.rewindTo(r),new je(e.ERR_INVALID_CHAR_RANGE,t.rest());o=u.substring(0,f),t.skipString(o),t.skip(1)}o.length!==0&&o.codePointAt(0)===D.CODES.get("^")&&(s=0-s,o=o.substring(1));let a=e.unicodeTable(o);if(a===null)throw new je(e.ERR_INVALID_CHAR_RANGE,t.from(r));let l=a.first,c=a.second;if((this.flags&V.FOLD_CASE)===0||c===null)n.appendTableWithSign(l,s);else{let u=new Ln().appendTable(l).appendTable(c).cleanClass().toArray();n.appendClassWithSign(u,s)}return!0}parseClass(t){let n=t.pos();t.skip(1);let r=this.newRegexp(_.Op.CHAR_CLASS);r.flags=this.flags;let s=new Ln,i=1;t.more()&&t.lookingAt("^")&&(i=-1,t.skip(1),(this.flags&V.CLASS_NL)===0&&s.appendRange(D.CODES.get(` +`)+1&&t.runes[3]===ue.MAX_RUNE&&(t.runes=[],t.op=_.Op.ANY_CHAR_NOT_NL))}collapse(t,n){if(t.length===1)return t[0];let r=0;for(let a of t)r+=a.op===n?a.subs.length:1;let s=new Array(r).fill(null),i=0;for(let a of t)a.op===n?(s.splice(i,a.subs.length,...a.subs),i+=a.subs.length,this.reuse(a)):s[i++]=a;let o=this.newRegexp(n);if(o.subs=s,n===_.Op.ALTERNATE&&(o.subs=this.factor(o.subs),o.subs.length===1)){let a=o;o=o.subs[0],this.reuse(a)}return o}factor(t){if(t.length<2)return t;let n=0,r=t.length,s=0,i=null,o=0,a=0,l=0;for(let u=0;u<=r;u++){let f=null,p=0,h=0;if(u0&&(d=d.subs[0]),d.op===_.Op.LITERAL&&(f=d.runes,p=d.runes.length,h=d.flags&V.FOLD_CASE),h===a){let m=0;for(;m0){o=m;continue}}}if(u!==l)if(u===l+1)t[s++]=t[n+l];else{let d=this.newRegexp(_.Op.LITERAL);d.flags=a,d.runes=i.slice(0,o);for(let y=l;y0){let r=this.removeLeadingString(t.subs[0],n);if(t.subs[0]=r,r.op===_.Op.EMPTY_MATCH)switch(this.reuse(r),t.subs.length){case 0:case 1:t.op=_.Op.EMPTY_MATCH,t.subs=null;break;case 2:{let s=t;t=t.subs[1],this.reuse(s);break}default:t.subs=t.subs.slice(1,t.subs.length);break}return t}return t.op===_.Op.LITERAL&&(t.runes=t.runes.slice(n,t.runes.length),t.runes.length===0&&(t.op=_.Op.EMPTY_MATCH)),t}removeLeadingRegexp(t,n){if(t.op===_.Op.CONCAT&&t.subs.length>0){switch(n&&this.reuse(t.subs[0]),t.subs=t.subs.slice(1,t.subs.length),t.subs.length){case 0:{t.op=_.Op.EMPTY_MATCH,t.subs=_.emptySubs();break}case 1:{let r=t;t=t.subs[0],this.reuse(r);break}}return t}return n&&this.reuse(t),this.newRegexp(_.Op.EMPTY_MATCH)}parseInternal(){if((this.flags&V.LITERAL)!==0)return e.literalRegexp(this.wholeRegexp,this.flags);let t=-1,n=-1,r=-1,s=new Qa(this.wholeRegexp);for(;s.more();){let o=-1;e:switch(s.peek()){case D.CODES.get("("):if((this.flags&V.PERL_X)!==0&&s.lookingAt("(?")){this.parsePerlFlags(s);break}this.op(_.Op.LEFT_PAREN).cap=++this.numCap,s.skip(1);break;case D.CODES.get("|"):this.parseVerticalBar(),s.skip(1);break;case D.CODES.get(")"):this.parseRightParen(),s.skip(1);break;case D.CODES.get("^"):(this.flags&V.ONE_LINE)!==0?this.op(_.Op.BEGIN_TEXT):this.op(_.Op.BEGIN_LINE),s.skip(1);break;case D.CODES.get("$"):(this.flags&V.ONE_LINE)!==0?this.op(_.Op.END_TEXT).flags|=V.WAS_DOLLAR:this.op(_.Op.END_LINE),s.skip(1);break;case D.CODES.get("."):(this.flags&V.DOT_NL)!==0?this.op(_.Op.ANY_CHAR):this.op(_.Op.ANY_CHAR_NOT_NL),s.skip(1);break;case D.CODES.get("["):this.parseClass(s);break;case D.CODES.get("*"):case D.CODES.get("+"):case D.CODES.get("?"):{o=s.pos();let a=null;switch(s.pop()){case D.CODES.get("*"):a=_.Op.STAR;break;case D.CODES.get("+"):a=_.Op.PLUS;break;case D.CODES.get("?"):a=_.Op.QUEST;break}this.repeat(a,n,r,o,s,t);break}case D.CODES.get("{"):{o=s.pos();let a=e.parseRepeat(s);if(a<0){s.rewindTo(o),this.literal(s.pop());break}n=a>>16,r=(a&ue.MAX_BMP)<<16>>16,this.repeat(_.Op.REPEAT,n,r,o,s,t);break}case D.CODES.get("\\"):{let a=s.pos();if(s.skip(1),(this.flags&V.PERL_X)!==0&&s.more())switch(s.pop()){case D.CODES.get("A"):this.op(_.Op.BEGIN_TEXT);break e;case D.CODES.get("b"):this.op(_.Op.WORD_BOUNDARY);break e;case D.CODES.get("B"):this.op(_.Op.NO_WORD_BOUNDARY);break e;case D.CODES.get("C"):throw new je(e.ERR_INVALID_ESCAPE,"\\C");case D.CODES.get("Q"):{let f=s.rest(),p=f.indexOf("\\E");p>=0&&(f=f.substring(0,p)),s.skipString(f),s.skipString("\\E");let h=0;for(;h");if(l<0)throw new je(e.ERR_INVALID_NAMED_CAPTURE,r);let c=r.substring(a,l);if(t.skipString(c),t.skip(a+1),!e.isValidCaptureName(c))throw new je(e.ERR_INVALID_NAMED_CAPTURE,r.substring(0,l+1));let u=this.op(_.Op.LEFT_PAREN);if(u.cap=++this.numCap,this.namedGroups[c])throw new je(e.ERR_DUPLICATE_NAMED_CAPTURE,c);this.namedGroups[c]=this.numCap,u.name=c;return}t.skip(2);let s=this.flags,i=1,o=!1;e:for(;t.more();){let a=t.pop();switch(a){case D.CODES.get("i"):s|=V.FOLD_CASE,o=!0;break;case D.CODES.get("m"):s&=-17,o=!0;break;case D.CODES.get("s"):s|=V.DOT_NL,o=!0;break;case D.CODES.get("U"):s|=V.NON_GREEDY,o=!0;break;case D.CODES.get("-"):if(i<0)break e;i=-1,s=~s,o=!1;break;case D.CODES.get(":"):case D.CODES.get(")"):if(i<0){if(!o)break e;s=~s}a===D.CODES.get(":")&&this.op(_.Op.LEFT_PAREN),this.flags=s;return;default:break e}}throw new je(e.ERR_INVALID_PERL_OP,t.from(n))}parseVerticalBar(){this.concat(),this.swapVerticalBar()||this.op(_.Op.VERTICAL_BAR)}swapVerticalBar(){let t=this.stack.length;if(t>=3&&this.stack[t-2].op===_.Op.VERTICAL_BAR&&e.isCharClass(this.stack[t-1])&&e.isCharClass(this.stack[t-3])){let n=this.stack[t-1],r=this.stack[t-3];if(n.op>r.op){let s=r;r=n,n=s,this.stack[t-3]=r}return e.mergeCharClass(r,n),this.reuse(n),this.pop(),!0}if(t>=2){let n=this.stack[t-1],r=this.stack[t-2];if(r.op===_.Op.VERTICAL_BAR)return t>=3&&this.cleanAlt(this.stack[t-3]),this.stack[t-2]=n,this.stack[t-1]=r,!0}return!1}parseRightParen(){if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),this.stack.length<2)throw new je(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);let n=this.pop(),r=this.pop();if(r.op!==_.Op.LEFT_PAREN)throw new je(e.ERR_UNEXPECTED_PAREN,this.wholeRegexp);this.flags=r.flags,r.cap===0?this.push(n):(r.op=_.Op.CAPTURE,r.subs=[n],this.push(r))}parsePerlClassEscape(t,n){let r=t.pos();if((this.flags&V.PERL_X)===0||!t.more()||t.pop()!==D.CODES.get("\\")||!t.more())return!1;t.pop();let s=t.from(r),i=m1.has(s)?m1.get(s):null;return i===null?!1:(n.appendGroup(i,(this.flags&V.FOLD_CASE)!==0),!0)}parseNamedClass(t,n){let r=t.rest(),s=r.indexOf(":]");if(s<0)return!1;let i=r.substring(0,s+2);t.skipString(i);let o=T1.has(i)?T1.get(i):null;if(o===null)throw new je(e.ERR_INVALID_CHAR_RANGE,i);return n.appendGroup(o,(this.flags&V.FOLD_CASE)!==0),!0}parseUnicodeClass(t,n){let r=t.pos();if((this.flags&V.UNICODE_GROUPS)===0||!t.lookingAt("\\p")&&!t.lookingAt("\\P"))return!1;t.skip(1);let s=1,i=t.pop();if(i===D.CODES.get("P")&&(s=-1),!t.more())throw t.rewindTo(r),new je(e.ERR_INVALID_CHAR_RANGE,t.rest());i=t.pop();let o;if(i!==D.CODES.get("{"))o=Te.runeToString(i);else{let u=t.rest(),f=u.indexOf("}");if(f<0)throw t.rewindTo(r),new je(e.ERR_INVALID_CHAR_RANGE,t.rest());o=u.substring(0,f),t.skipString(o),t.skip(1)}o.length!==0&&o.codePointAt(0)===D.CODES.get("^")&&(s=0-s,o=o.substring(1));let a=e.unicodeTable(o);if(a===null)throw new je(e.ERR_INVALID_CHAR_RANGE,t.from(r));let l=a.first,c=a.second;if((this.flags&V.FOLD_CASE)===0||c===null)n.appendTableWithSign(l,s);else{let u=new $n().appendTable(l).appendTable(c).cleanClass().toArray();n.appendClassWithSign(u,s)}return!0}parseClass(t){let n=t.pos();t.skip(1);let r=this.newRegexp(_.Op.CHAR_CLASS);r.flags=this.flags;let s=new $n,i=1;t.more()&&t.lookingAt("^")&&(i=-1,t.skip(1),(this.flags&V.CLASS_NL)===0&&s.appendRange(D.CODES.get(` `),D.CODES.get(` -`)));let o=!0;for(;!t.more()||t.peek()!==D.CODES.get("]")||o;){if(t.more()&&t.lookingAt("-")&&(this.flags&V.PERL_X)===0&&!o){let u=t.rest();if(u==="-"||!u.startsWith("-]"))throw t.rewindTo(n),new je(e.ERR_INVALID_CHAR_RANGE,t.rest())}o=!1;let a=t.pos();if(t.lookingAt("[:")){if(this.parseNamedClass(t,s))continue;t.rewindTo(a)}if(this.parseUnicodeClass(t,s)||this.parsePerlClassEscape(t,s))continue;t.rewindTo(a);let l=e.parseClassChar(t,n),c=l;if(t.more()&&t.lookingAt("-")){if(t.skip(1),t.more()&&t.lookingAt("]"))t.skip(-1);else if(c=e.parseClassChar(t,n),c0&&(a.prefixRune=a.prefix.codePointAt(0)),a.namedGroups=s.namedGroups,a}static match(t,n){return e.compile(t).match(n)}constructor(t,n,r=0,s=0){this.expr=t,this.prog=n,this.numSubexp=r,this.longest=s,this.cond=n.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=!1,this.prefixRune=0,this.pooled=new gl,this.dfa=new ul(n)}executeEngine(t,n,r,s){if(s>0)return this.doExecuteNFA(t,n,r,s);let i=this.dfa.match(t,n,r);return i!==null?i?[]:null:this.doExecuteNFA(t,n,r,s)}numberOfCapturingGroups(){return this.numSubexp}numberOfInstructions(){return this.prog.numInst()}get(){let t;do t=this.pooled.get();while(t&&!this.pooled.compareAndSet(t,t.next));return t}reset(){this.pooled.set(null)}put(t,n){let r=this.pooled.get();do r=this.pooled.get(),!n&&r&&(t=Qs.fromMachine(t),n=!0),t.next!==r&&(t.next=r);while(!this.pooled.compareAndSet(r,t))}toString(){return this.expr}doExecuteNFA(t,n,r,s){let i=this.get(),o=!1;i?i.next!==null&&(i=Qs.fromMachine(i),o=!0):(i=Qs.fromRE2(this),o=!0),i.init(s);let a=i.match(t,n,r)?i.submatches():null;return this.put(i,o),a}match(t){return this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,0)!==null}matchWithGroup(t,n,r,s,i){return t instanceof ar||(t=cs.utf16(t)),this.matchMachineInput(t,n,r,s,i)}matchMachineInput(t,n,r,s,i){if(n>r)return[!1,null];let o=t.isUTF16Encoding()?Ye.fromUTF16(t.asCharSequence(),0,r):Ye.fromUTF8(t.asBytes(),0,r),a=this.executeEngine(o,n,s,2*i);return a===null?[!1,null]:[!0,a]}matchUTF8(t){return this.executeEngine(Ye.fromUTF8(t),0,V.UNANCHORED,0)!==null}replaceAll(t,n){return this.replaceAllFunc(t,()=>n,2*t.length+1)}replaceFirst(t,n){return this.replaceAllFunc(t,()=>n,1)}replaceAllFunc(t,n,r){let s=0,i=0,o="",a=Ye.fromUTF16(t),l=0;for(;i<=t.length;){let c=this.executeEngine(a,i,V.UNANCHORED,2);if(c===null||c.length===0)break;o+=t.substring(s,c[0]),(c[1]>s||c[0]===0)&&(o+=n(t.substring(c[0],c[1])),l++),s=c[1];let u=a.step(i)&7;if(i+u>c[1]?i+=u:i+1>c[1]?i++:i=c[1],l>=r)break}return o+=t.substring(s),o}pad(t){if(t===null)return null;let n=(1+this.numSubexp)*2;if(t.lengths){let s=[],i=t.endPos();n<0&&(n=i+1);let o=0,a=0,l=-1;for(;a=0&&(r[s]=t.slice(n[2*s],n[2*s+1]));return r}findUTF8SubmatchIndex(t){return this.pad(this.executeEngine(Ye.fromUTF8(t),0,V.UNANCHORED,this.prog.numCap))}findSubmatch(t){let n=this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,this.prog.numCap);if(n===null)return null;let r=new Array(1+this.numSubexp).fill(null);for(let s=0;s=0&&(r[s]=t.substring(n[2*s],n[2*s+1]));return r}findSubmatchIndex(t){return this.pad(this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,this.prog.numCap))}findAllUTF8(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>t.slice(s[0],s[1]));return r.length===0?null:r}findAllUTF8Index(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>s.slice(0,2));return r.length===0?null:r}findAll(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>t.substring(s[0],s[1]));return r.length===0?null:r}findAllIndex(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>s.slice(0,2));return r.length===0?null:r}findAllUTF8Submatch(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>{let i=new Array(s.length/2|0).fill(null);for(let o=0;o=0&&(i[o]=t.slice(s[2*o],s[2*o+1]));return i});return r.length===0?null:r}findAllUTF8SubmatchIndex(t,n){let r=this.allMatches(Ye.fromUTF8(t),n);return r.length===0?null:r}findAllSubmatch(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>{let i=new Array(s.length/2|0).fill(null);for(let o=0;o=0&&(i[o]=t.substring(s[2*o],s[2*o+1]));return i});return r.length===0?null:r}findAllSubmatchIndex(t,n){let r=this.allMatches(Ye.fromUTF16(t),n);return r.length===0?null:r}},wl=class e{static isUpperCaseAlpha(t){return"A"<=t&&t<="Z"}static isHexadecimal(t){return"0"<=t&&t<="9"||"A"<=t&&t<="F"||"a"<=t&&t<="f"}static getUtf8CharSize(t){let n=t.charCodeAt(0);return n<128?1:n<2048?2:n<65536?3:4}static translate(t){if(typeof t!="string")return t;let n="",r=!1,s=t.length;s===0&&(n="(?:)",r=!0);let i=0;for(;i>4).toString(16).toUpperCase(),n+=(l.charCodeAt(0)-64&15).toString(16).toUpperCase(),i+=3,r=!0;continue}}n+="\\c",i+=2;continue}case"u":{if(i+2=s||t[i+3]!=="="&&t[i+3]!=="!")){n+="(?P<",i+=3,r=!0;continue}let a=e.getUtf8CharSize(o);n+=t.substring(i,i+a),i+=a}return r?n:t}},lr=class e{static CASE_INSENSITIVE=1;static DOTALL=2;static MULTILINE=4;static DISABLE_UNICODE_GROUPS=8;static LONGEST_MATCH=16;static quote(t){return Oe.quoteMeta(t)}static quoteReplacement(t,n=!1){return Ki.quoteReplacement(t,n)}static translateRegExp(t){return wl.translate(t)}static compile(t,n=0){let r=t;if((n&e.CASE_INSENSITIVE)!==0&&(r=`(?i)${r}`),(n&e.DOTALL)!==0&&(r=`(?s)${r}`),(n&e.MULTILINE)!==0&&(r=`(?m)${r}`),(n&~(e.MULTILINE|e.DOTALL|e.CASE_INSENSITIVE|e.DISABLE_UNICODE_GROUPS|e.LONGEST_MATCH))!==0)throw new al("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH");let s=V.PERL;(n&e.DISABLE_UNICODE_GROUPS)!==0&&(s&=-129);let i=new e(t,n);return i.re2Input=yl.compileImpl(r,s,(n&e.LONGEST_MATCH)!==0),i}static matches(t,n){return e.compile(t).testExact(n)}static initTest(t,n,r){if(t==null)throw new Error("pattern is null");if(r==null)throw new Error("re2 is null");let s=new e(t,n);return s.re2Input=r,s}constructor(t,n){this.patternInput=t,this.flagsInput=n}reset(){this.re2Input.reset()}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(t){return this.testExact(t)}matcher(t){return Array.isArray(t)&&(t=cs.utf8(t)),new Ki(this,t)}test(t){return Array.isArray(t)?this.re2Input.matchUTF8(t):this.re2Input.match(t)}testExact(t){let n=Array.isArray(t)?Ye.fromUTF8(t):Ye.fromUTF16(t);return this.re2Input.executeEngine(n,0,V.ANCHOR_BOTH,0)!==null}split(t,n=0){let r=this.matcher(t),s=[],i=0,o=0;for(;r.find();){if(o===0&&r.end()===0){o=r.end();continue}if(n>0&&s.length===n-1)break;if(o===r.start()){if(n===0){i+=1,o=r.end();continue}}else for(;i>0;)s.push(""),i-=1;s.push(r.substring(o,r.start())),o=r.end()}if(n===0&&o!==r.inputLength()){for(;i>0;)s.push(""),i-=1;s.push(r.substring(o,r.inputLength()))}return(n!==0||s.length===0)&&s.push(r.substring(o,r.inputLength())),s}toString(){return this.patternInput}programSize(){return this.re2Input.numberOfInstructions()}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(t){return this===t?!0:t===null||this.constructor!==t.constructor?!1:this.flagsInput===t.flagsInput&&this.patternInput===t.patternInput}}});function F3(e){let t=0;return e.includes("i")&&(t|=lr.CASE_INSENSITIVE),e.includes("m")&&(t|=lr.MULTILINE),e.includes("s")&&(t|=lr.DOTALL),t}function L3(e){return lr.translateRegExp(e)}function Q(e,t=""){return new Xi(e,t)}var Xi,Yn,ap=v(()=>{"use strict";op();Xi=class{_re2;_pattern;_flags;_global;_ignoreCase;_multiline;_lastIndex=0;_nativeRegex=null;_matcher=null;_matcherInput=null;acquireMatcher(t){return this._matcher===null?(this._matcher=this._re2.matcher(t),this._matcherInput=t,this._matcher):(this._matcherInput!==t&&(this._matcher.matcherInput.charSequence=t,this._matcherInput=t),this._matcher.reset(),this._matcher)}constructor(t,n=""){this._pattern=t,this._flags=n,this._global=n.includes("g"),this._ignoreCase=n.includes("i"),this._multiline=n.includes("m");try{let r=L3(t),s=F3(n);this._re2=lr.compile(r,s)}catch(r){if(r instanceof je){let s=r.message||"",i="";throw s.includes("(?=")||s.includes("(?!")||s.includes("(?<")||s.includes("(?0){let l=Object.create(null);for(let[c,u]of Object.entries(a)){let f=n.group(u);f!==null&&(l[c]=f)}o.groups=l}return this._global&&(this._lastIndex=n.end(0),n.start(0)===n.end(0)&&this._lastIndex++),o}match(t){if(this._global&&(this._lastIndex=0),!this._global)return this.exec(t);let n=[],r=this.acquireMatcher(t),s=0;for(;r.find(s);){let i=r.group(0)??"";if(n.push(i),s=r.end(0),r.start(0)===r.end(0)&&s++,s>t.length)break}return n.length>0?n:null}replace(t,n){if(this._global&&(this._lastIndex=0),typeof n=="string"){let c=this.acquireMatcher(t);return this._global?c.replaceAll(n,!0):c.replaceFirst(n,!0)}let r=[],s=this._re2.matcher(t),i=0,o=0,a=this._re2.groupCount(),l=this._re2.namedGroups();for(;s.find(o);){r.push(t.slice(i,s.start(0)));let c=[],u=s.group(0)??"";for(let h=1;h<=a;h++)c.push(s.group(h));if(c.push(s.start(0)),c.push(t),l&&Object.keys(l).length>0){let h=Object.create(null);for(let[d,m]of Object.entries(l))h[d]=s.group(m)??"";c.push(h)}let f=s.start(0),p=s.end(0);if(r.push(n(u,...c)),i=p,o=i,f===p&&o++,!this._global||o>t.length)break}return r.push(t.slice(i)),r.join("")}split(t,n){return n===void 0||n<0?this._re2.split(t,-1):n===0?[]:this._re2.split(t,-1).slice(0,n)}search(t){let n=this.acquireMatcher(t);return n.find()?n.start(0):-1}*matchAll(t){if(!this._global)throw new Error("matchAll requires global flag");this._lastIndex=0;let n=this._re2.matcher(t),r=this._re2.groupCount(),s=this._re2.namedGroups(),i=0;for(;n.find(i);){let o=[];o.push(n.group(0)??"");for(let l=1;l<=r;l++)o.push(n.group(l));let a=o;if(a.index=n.start(0),a.input=t,s&&Object.keys(s).length>0){let l=Object.create(null);for(let[c,u]of Object.entries(s)){let f=n.group(u);f!==null&&(l[c]=f)}a.groups=l}if(yield a,i=n.end(0),n.start(0)===n.end(0)&&i++,i>t.length)break}}get native(){if(!this._nativeRegex)try{this._nativeRegex=new RegExp(this._pattern,this._flags)}catch{this._nativeRegex=new RegExp("",this._flags),Object.defineProperty(this._nativeRegex,"source",{value:this._pattern,writable:!1})}return this._nativeRegex}get source(){return this._pattern}get flags(){return this._flags}get global(){return this._global}get ignoreCase(){return this._ignoreCase}get multiline(){return this._multiline}get lastIndex(){return this._lastIndex}set lastIndex(t){this._lastIndex=t}};Yn=class{_regex;constructor(t){this._regex=t}test(t){return this._regex.global&&(this._regex.lastIndex=0),this._regex.test(t)}exec(t){return this._regex.exec(t)}match(t){return this._regex.global&&(this._regex.lastIndex=0),t.match(this._regex)}replace(t,n){return this._regex.global&&(this._regex.lastIndex=0),t.replace(this._regex,n)}split(t,n){return t.split(this._regex,n)}search(t){return t.search(this._regex)}*matchAll(t){if(!this._regex.global)throw new Error("matchAll requires global flag");this._regex.lastIndex=0;let n=this._regex.exec(t);for(;n!==null;)yield n,n[0].length===0&&this._regex.lastIndex++,n=this._regex.exec(t)}get native(){return this._regex}get source(){return this._regex.source}get flags(){return this._regex.flags}get global(){return this._regex.global}get ignoreCase(){return this._regex.ignoreCase}get multiline(){return this._regex.multiline}get lastIndex(){return this._regex.lastIndex}set lastIndex(t){this._regex.lastIndex=t}}});var Ze=v(()=>{"use strict";ap()});function Dt(e,t,n){let r=typeof n=="boolean"?{ignoreCase:n}:n??{},s=t;r.stripQuotes&&(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"))&&(s=s.slice(1,-1));let i=r.ignoreCase?`i:${s}`:s,o=Ys.get(i);if(!o){if(o=U3(s,r.ignoreCase),Ys.size>=M3){let a=Ys.keys().next().value;a!==void 0&&Ys.delete(a)}Ys.set(i,o)}return o.test(e)}function U3(e,t){let n="^";for(let r=0;r{"use strict";Ze();M3=2048,Ys=new Map});function Js(e,t){let n=e.ignoreCase?t.toLowerCase():t,r=e.needles;for(let s=0;s]+)>)/g,(n,r,s)=>{if(r==="&")return t[0];if(s!==void 0)return t.groups?.[s]??"";let i=parseInt(r,10);return t[i]??""})}function fs(e,t,n={}){let{invertMatch:r=!1,showLineNumbers:s=!1,countOnly:i=!1,countMatches:o=!1,filename:a="",onlyMatching:l=!1,beforeContext:c=0,afterContext:u=0,maxCount:f=0,contextSeparator:p="--",showColumn:h=!1,vimgrep:d=!1,showByteOffset:m=!1,replace:g=null,passthru:y=!1,multiline:w=!1,kResetGroup:b,preFilter:x}=n;if(w)return B3(e,t,{invertMatch:r,showLineNumbers:s,countOnly:i,countMatches:o,filename:a,onlyMatching:l,beforeContext:c,afterContext:u,maxCount:f,contextSeparator:p,showColumn:h,showByteOffset:m,replace:g,kResetGroup:b,preFilter:x});let A=e.split(` -`),I=A.length,O=I>0&&A[I-1]===""?I-1:I;if(i||o){let T=0,N=(o||l)&&!r;for(let F=0;F0,matchCount:T}}if(c===0&&u===0&&!y){let T=[],N=!1,P=0,F=0;for(let W=0;W0&&P>=f);W++){let se=A[W],de=null;if(x&&!Js(x,se)||(t.lastIndex=0,de=t.exec(se)),de!==null!==r)if(N=!0,P++,l)for(let j=de;j!==null;j=t.exec(se)){let te=b!==void 0?j[b]??"":j[0],ve=g!==null?lp(g,j):te,ie=a?`${a}:`:"";m&&(ie+=`${F+j.index}:`),s&&(ie+=`${W+1}:`),h&&(ie+=`${j.index+1}:`),T.push(ie+ve),j[0].length===0&&t.lastIndex++}else if(d)for(let j=de;j!==null;j=t.exec(se)){let te=a?`${a}:`:"";m&&(te+=`${F+j.index}:`),s&&(te+=`${W+1}:`),h&&(te+=`${j.index+1}:`),T.push(te+se),j[0].length===0&&t.lastIndex++}else{let j=de?de.index+1:1,te=se;g!==null&&(t.lastIndex=0,te=t.replace(se,(...ie)=>{if(ie[0].length===0)return"";let G=ie,Pe=ie[ie.length-1];return typeof Pe=="object"&&Pe!==null?(G.groups=Pe,G.input=ie[ie.length-2],G.index=ie[ie.length-3]):(G.input=ie[ie.length-1],G.index=ie[ie.length-2]),lp(g,G)}));let ve=a?`${a}:`:"";m&&(ve+=`${F+(de?de.index:0)}:`),s&&(ve+=`${W+1}:`),h&&(ve+=`${j}:`),T.push(ve+te)}F+=se.length+1}return{output:T.length>0?`${T.join(` +`)));let o=!0;for(;!t.more()||t.peek()!==D.CODES.get("]")||o;){if(t.more()&&t.lookingAt("-")&&(this.flags&V.PERL_X)===0&&!o){let u=t.rest();if(u==="-"||!u.startsWith("-]"))throw t.rewindTo(n),new je(e.ERR_INVALID_CHAR_RANGE,t.rest())}o=!1;let a=t.pos();if(t.lookingAt("[:")){if(this.parseNamedClass(t,s))continue;t.rewindTo(a)}if(this.parseUnicodeClass(t,s)||this.parsePerlClassEscape(t,s))continue;t.rewindTo(a);let l=e.parseClassChar(t,n),c=l;if(t.more()&&t.lookingAt("-")){if(t.skip(1),t.more()&&t.lookingAt("]"))t.skip(-1);else if(c=e.parseClassChar(t,n),c0&&(a.prefixRune=a.prefix.codePointAt(0)),a.namedGroups=s.namedGroups,a}static match(t,n){return e.compile(t).match(n)}constructor(t,n,r=0,s=0){this.expr=t,this.prog=n,this.numSubexp=r,this.longest=s,this.cond=n.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=!1,this.prefixRune=0,this.pooled=new Ya,this.dfa=new Va(n)}executeEngine(t,n,r,s){if(s>0)return this.doExecuteNFA(t,n,r,s);let i=this.dfa.match(t,n,r);return i!==null?i?[]:null:this.doExecuteNFA(t,n,r,s)}numberOfCapturingGroups(){return this.numSubexp}numberOfInstructions(){return this.prog.numInst()}get(){let t;do t=this.pooled.get();while(t&&!this.pooled.compareAndSet(t,t.next));return t}reset(){this.pooled.set(null)}put(t,n){let r=this.pooled.get();do r=this.pooled.get(),!n&&r&&(t=Rs.fromMachine(t),n=!0),t.next!==r&&(t.next=r);while(!this.pooled.compareAndSet(r,t))}toString(){return this.expr}doExecuteNFA(t,n,r,s){let i=this.get(),o=!1;i?i.next!==null&&(i=Rs.fromMachine(i),o=!0):(i=Rs.fromRE2(this),o=!0),i.init(s);let a=i.match(t,n,r)?i.submatches():null;return this.put(i,o),a}match(t){return this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,0)!==null}matchWithGroup(t,n,r,s,i){return t instanceof Jn||(t=Kr.utf16(t)),this.matchMachineInput(t,n,r,s,i)}matchMachineInput(t,n,r,s,i){if(n>r)return[!1,null];let o=t.isUTF16Encoding()?Ye.fromUTF16(t.asCharSequence(),0,r):Ye.fromUTF8(t.asBytes(),0,r),a=this.executeEngine(o,n,s,2*i);return a===null?[!1,null]:[!0,a]}matchUTF8(t){return this.executeEngine(Ye.fromUTF8(t),0,V.UNANCHORED,0)!==null}replaceAll(t,n){return this.replaceAllFunc(t,()=>n,2*t.length+1)}replaceFirst(t,n){return this.replaceAllFunc(t,()=>n,1)}replaceAllFunc(t,n,r){let s=0,i=0,o="",a=Ye.fromUTF16(t),l=0;for(;i<=t.length;){let c=this.executeEngine(a,i,V.UNANCHORED,2);if(c===null||c.length===0)break;o+=t.substring(s,c[0]),(c[1]>s||c[0]===0)&&(o+=n(t.substring(c[0],c[1])),l++),s=c[1];let u=a.step(i)&7;if(i+u>c[1]?i+=u:i+1>c[1]?i++:i=c[1],l>=r)break}return o+=t.substring(s),o}pad(t){if(t===null)return null;let n=(1+this.numSubexp)*2;if(t.lengths){let s=[],i=t.endPos();n<0&&(n=i+1);let o=0,a=0,l=-1;for(;a=0&&(r[s]=t.slice(n[2*s],n[2*s+1]));return r}findUTF8SubmatchIndex(t){return this.pad(this.executeEngine(Ye.fromUTF8(t),0,V.UNANCHORED,this.prog.numCap))}findSubmatch(t){let n=this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,this.prog.numCap);if(n===null)return null;let r=new Array(1+this.numSubexp).fill(null);for(let s=0;s=0&&(r[s]=t.substring(n[2*s],n[2*s+1]));return r}findSubmatchIndex(t){return this.pad(this.executeEngine(Ye.fromUTF16(t),0,V.UNANCHORED,this.prog.numCap))}findAllUTF8(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>t.slice(s[0],s[1]));return r.length===0?null:r}findAllUTF8Index(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>s.slice(0,2));return r.length===0?null:r}findAll(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>t.substring(s[0],s[1]));return r.length===0?null:r}findAllIndex(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>s.slice(0,2));return r.length===0?null:r}findAllUTF8Submatch(t,n){let r=this.allMatches(Ye.fromUTF8(t),n,s=>{let i=new Array(s.length/2|0).fill(null);for(let o=0;o=0&&(i[o]=t.slice(s[2*o],s[2*o+1]));return i});return r.length===0?null:r}findAllUTF8SubmatchIndex(t,n){let r=this.allMatches(Ye.fromUTF8(t),n);return r.length===0?null:r}findAllSubmatch(t,n){let r=this.allMatches(Ye.fromUTF16(t),n,s=>{let i=new Array(s.length/2|0).fill(null);for(let o=0;o=0&&(i[o]=t.substring(s[2*o],s[2*o+1]));return i});return r.length===0?null:r}findAllSubmatchIndex(t,n){let r=this.allMatches(Ye.fromUTF16(t),n);return r.length===0?null:r}},el=class e{static isUpperCaseAlpha(t){return"A"<=t&&t<="Z"}static isHexadecimal(t){return"0"<=t&&t<="9"||"A"<=t&&t<="F"||"a"<=t&&t<="f"}static getUtf8CharSize(t){let n=t.charCodeAt(0);return n<128?1:n<2048?2:n<65536?3:4}static translate(t){if(typeof t!="string")return t;let n="",r=!1,s=t.length;s===0&&(n="(?:)",r=!0);let i=0;for(;i>4).toString(16).toUpperCase(),n+=(l.charCodeAt(0)-64&15).toString(16).toUpperCase(),i+=3,r=!0;continue}}n+="\\c",i+=2;continue}case"u":{if(i+2=s||t[i+3]!=="="&&t[i+3]!=="!")){n+="(?P<",i+=3,r=!0;continue}let a=e.getUtf8CharSize(o);n+=t.substring(i,i+a),i+=a}return r?n:t}},er=class e{static CASE_INSENSITIVE=1;static DOTALL=2;static MULTILINE=4;static DISABLE_UNICODE_GROUPS=8;static LONGEST_MATCH=16;static quote(t){return Te.quoteMeta(t)}static quoteReplacement(t,n=!1){return Ti.quoteReplacement(t,n)}static translateRegExp(t){return el.translate(t)}static compile(t,n=0){let r=t;if((n&e.CASE_INSENSITIVE)!==0&&(r=`(?i)${r}`),(n&e.DOTALL)!==0&&(r=`(?s)${r}`),(n&e.MULTILINE)!==0&&(r=`(?m)${r}`),(n&~(e.MULTILINE|e.DOTALL|e.CASE_INSENSITIVE|e.DISABLE_UNICODE_GROUPS|e.LONGEST_MATCH))!==0)throw new Ha("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH");let s=V.PERL;(n&e.DISABLE_UNICODE_GROUPS)!==0&&(s&=-129);let i=new e(t,n);return i.re2Input=Ja.compileImpl(r,s,(n&e.LONGEST_MATCH)!==0),i}static matches(t,n){return e.compile(t).testExact(n)}static initTest(t,n,r){if(t==null)throw new Error("pattern is null");if(r==null)throw new Error("re2 is null");let s=new e(t,n);return s.re2Input=r,s}constructor(t,n){this.patternInput=t,this.flagsInput=n}reset(){this.re2Input.reset()}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(t){return this.testExact(t)}matcher(t){return Array.isArray(t)&&(t=Kr.utf8(t)),new Ti(this,t)}test(t){return Array.isArray(t)?this.re2Input.matchUTF8(t):this.re2Input.match(t)}testExact(t){let n=Array.isArray(t)?Ye.fromUTF8(t):Ye.fromUTF16(t);return this.re2Input.executeEngine(n,0,V.ANCHOR_BOTH,0)!==null}split(t,n=0){let r=this.matcher(t),s=[],i=0,o=0;for(;r.find();){if(o===0&&r.end()===0){o=r.end();continue}if(n>0&&s.length===n-1)break;if(o===r.start()){if(n===0){i+=1,o=r.end();continue}}else for(;i>0;)s.push(""),i-=1;s.push(r.substring(o,r.start())),o=r.end()}if(n===0&&o!==r.inputLength()){for(;i>0;)s.push(""),i-=1;s.push(r.substring(o,r.inputLength()))}return(n!==0||s.length===0)&&s.push(r.substring(o,r.inputLength())),s}toString(){return this.patternInput}programSize(){return this.re2Input.numberOfInstructions()}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(t){return this===t?!0:t===null||this.constructor!==t.constructor?!1:this.flagsInput===t.flagsInput&&this.patternInput===t.patternInput}}});function H4(e){let t=0;return e.includes("i")&&(t|=er.CASE_INSENSITIVE),e.includes("m")&&(t|=er.MULTILINE),e.includes("s")&&(t|=er.DOTALL),t}function j4(e){return er.translateRegExp(e)}function Q(e,t=""){return new Ri(e,t)}var Ri,Gn,P1=O(()=>{"use strict";R1();Ri=class{_re2;_pattern;_flags;_global;_ignoreCase;_multiline;_lastIndex=0;_nativeRegex=null;_matcher=null;_matcherInput=null;acquireMatcher(t){return this._matcher===null?(this._matcher=this._re2.matcher(t),this._matcherInput=t,this._matcher):(this._matcherInput!==t&&(this._matcher.matcherInput.charSequence=t,this._matcherInput=t),this._matcher.reset(),this._matcher)}constructor(t,n=""){this._pattern=t,this._flags=n,this._global=n.includes("g"),this._ignoreCase=n.includes("i"),this._multiline=n.includes("m");try{let r=j4(t),s=H4(n);this._re2=er.compile(r,s)}catch(r){if(r instanceof je){let s=r.message||"",i="";throw s.includes("(?=")||s.includes("(?!")||s.includes("(?<")||s.includes("(?0){let l=Object.create(null);for(let[c,u]of Object.entries(a)){let f=n.group(u);f!==null&&(l[c]=f)}o.groups=l}return this._global&&(this._lastIndex=n.end(0),n.start(0)===n.end(0)&&this._lastIndex++),o}match(t){if(this._global&&(this._lastIndex=0),!this._global)return this.exec(t);let n=[],r=this.acquireMatcher(t),s=0;for(;r.find(s);){let i=r.group(0)??"";if(n.push(i),s=r.end(0),r.start(0)===r.end(0)&&s++,s>t.length)break}return n.length>0?n:null}replace(t,n){if(this._global&&(this._lastIndex=0),typeof n=="string"){let c=this.acquireMatcher(t);return this._global?c.replaceAll(n,!0):c.replaceFirst(n,!0)}let r=[],s=this._re2.matcher(t),i=0,o=0,a=this._re2.groupCount(),l=this._re2.namedGroups();for(;s.find(o);){r.push(t.slice(i,s.start(0)));let c=[],u=s.group(0)??"";for(let h=1;h<=a;h++)c.push(s.group(h));if(c.push(s.start(0)),c.push(t),l&&Object.keys(l).length>0){let h=Object.create(null);for(let[d,m]of Object.entries(l))h[d]=s.group(m)??"";c.push(h)}let f=s.start(0),p=s.end(0);if(r.push(n(u,...c)),i=p,o=i,f===p&&o++,!this._global||o>t.length)break}return r.push(t.slice(i)),r.join("")}split(t,n){return n===void 0||n<0?this._re2.split(t,-1):n===0?[]:this._re2.split(t,-1).slice(0,n)}search(t){let n=this.acquireMatcher(t);return n.find()?n.start(0):-1}*matchAll(t){if(!this._global)throw new Error("matchAll requires global flag");this._lastIndex=0;let n=this._re2.matcher(t),r=this._re2.groupCount(),s=this._re2.namedGroups(),i=0;for(;n.find(i);){let o=[];o.push(n.group(0)??"");for(let l=1;l<=r;l++)o.push(n.group(l));let a=o;if(a.index=n.start(0),a.input=t,s&&Object.keys(s).length>0){let l=Object.create(null);for(let[c,u]of Object.entries(s)){let f=n.group(u);f!==null&&(l[c]=f)}a.groups=l}if(yield a,i=n.end(0),n.start(0)===n.end(0)&&i++,i>t.length)break}}get native(){if(!this._nativeRegex)try{this._nativeRegex=new RegExp(this._pattern,this._flags)}catch{this._nativeRegex=new RegExp("",this._flags),Object.defineProperty(this._nativeRegex,"source",{value:this._pattern,writable:!1})}return this._nativeRegex}get source(){return this._pattern}get flags(){return this._flags}get global(){return this._global}get ignoreCase(){return this._ignoreCase}get multiline(){return this._multiline}get lastIndex(){return this._lastIndex}set lastIndex(t){this._lastIndex=t}};Gn=class{_regex;constructor(t){this._regex=t}test(t){return this._regex.global&&(this._regex.lastIndex=0),this._regex.test(t)}exec(t){return this._regex.exec(t)}match(t){return this._regex.global&&(this._regex.lastIndex=0),t.match(this._regex)}replace(t,n){return this._regex.global&&(this._regex.lastIndex=0),t.replace(this._regex,n)}split(t,n){return t.split(this._regex,n)}search(t){return t.search(this._regex)}*matchAll(t){if(!this._regex.global)throw new Error("matchAll requires global flag");this._regex.lastIndex=0;let n=this._regex.exec(t);for(;n!==null;)yield n,n[0].length===0&&this._regex.lastIndex++,n=this._regex.exec(t)}get native(){return this._regex}get source(){return this._regex.source}get flags(){return this._regex.flags}get global(){return this._regex.global}get ignoreCase(){return this._regex.ignoreCase}get multiline(){return this._regex.multiline}get lastIndex(){return this._regex.lastIndex}set lastIndex(t){this._regex.lastIndex=t}}});var Ze=O(()=>{"use strict";P1()});function Rt(e,t,n){let r=typeof n=="boolean"?{ignoreCase:n}:n??{},s=t;r.stripQuotes&&(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"))&&(s=s.slice(1,-1));let i=r.ignoreCase?`i:${s}`:s,o=Ds.get(i);if(!o){if(o=V4(s,r.ignoreCase),Ds.size>=G4){let a=Ds.keys().next().value;a!==void 0&&Ds.delete(a)}Ds.set(i,o)}return o.test(e)}function V4(e,t){let n="^";for(let r=0;r{"use strict";Ze();G4=2048,Ds=new Map});function _s(e,t){let n=e.ignoreCase?t.toLowerCase():t,r=e.needles;for(let s=0;s]+)>)/g,(n,r,s)=>{if(r==="&")return t[0];if(s!==void 0)return t.groups?.[s]??"";let i=parseInt(r,10);return t[i]??""})}function Er(e,t,n={}){let{invertMatch:r=!1,showLineNumbers:s=!1,countOnly:i=!1,countMatches:o=!1,filename:a="",onlyMatching:l=!1,beforeContext:c=0,afterContext:u=0,maxCount:f=0,contextSeparator:p="--",showColumn:h=!1,vimgrep:d=!1,showByteOffset:m=!1,replace:g=null,passthru:y=!1,multiline:w=!1,kResetGroup:b,preFilter:x}=n;if(w)return q4(e,t,{invertMatch:r,showLineNumbers:s,countOnly:i,countMatches:o,filename:a,onlyMatching:l,beforeContext:c,afterContext:u,maxCount:f,contextSeparator:p,showColumn:h,showByteOffset:m,replace:g,kResetGroup:b,preFilter:x});let A=e.split(` +`),v=A.length,$=v>0&&A[v-1]===""?v-1:v;if(i||o){let T=0,N=(o||l)&&!r;for(let L=0;L<$;L++){let W=A[L];if(!(x&&!r&&!_s(x,W)))if(t.lastIndex=0,N)for(let se=t.exec(W);se!==null;se=t.exec(W))T++,se[0].length===0&&t.lastIndex++;else t.test(W)!==r&&T++}return{output:`${a?`${a}:${T}`:String(T)} +`,matched:T>0,matchCount:T}}if(c===0&&u===0&&!y){let T=[],N=!1,P=0,L=0;for(let W=0;W<$&&!(f>0&&P>=f);W++){let se=A[W],de=null;if(x&&!_s(x,se)||(t.lastIndex=0,de=t.exec(se)),de!==null!==r)if(N=!0,P++,l)for(let j=de;j!==null;j=t.exec(se)){let ee=b!==void 0?j[b]??"":j[0],ve=g!==null?D1(g,j):ee,ie=a?`${a}:`:"";m&&(ie+=`${L+j.index}:`),s&&(ie+=`${W+1}:`),h&&(ie+=`${j.index+1}:`),T.push(ie+ve),j[0].length===0&&t.lastIndex++}else if(d)for(let j=de;j!==null;j=t.exec(se)){let ee=a?`${a}:`:"";m&&(ee+=`${L+j.index}:`),s&&(ee+=`${W+1}:`),h&&(ee+=`${j.index+1}:`),T.push(ee+se),j[0].length===0&&t.lastIndex++}else{let j=de?de.index+1:1,ee=se;g!==null&&(t.lastIndex=0,ee=t.replace(se,(...ie)=>{if(ie[0].length===0)return"";let G=ie,Pe=ie[ie.length-1];return typeof Pe=="object"&&Pe!==null?(G.groups=Pe,G.input=ie[ie.length-2],G.index=ie[ie.length-3]):(G.input=ie[ie.length-1],G.index=ie[ie.length-2]),D1(g,G)}));let ve=a?`${a}:`:"";m&&(ve+=`${L+(de?de.index:0)}:`),s&&(ve+=`${W+1}:`),h&&(ve+=`${j}:`),T.push(ve+ee)}L+=se.length+1}return{output:T.length>0?`${T.join(` `)} -`:"",matched:N,matchCount:P}}if(y){let T=[],N=!1,P=0;for(let F=0;F0?`${T.join(` +`:"",matched:N,matchCount:P}}if(y){let T=[],N=!1,P=0;for(let L=0;L<$;L++){let W=A[L],se;x&&!_s(x,W)?se=!1:(t.lastIndex=0,se=t.test(W));let de=se!==r;de&&(N=!0,P++);let q=de?":":"-",j=a?`${a}${q}`:"";s&&(j+=`${L+1}${q}`),T.push(j+W)}return{output:T.length>0?`${T.join(` `)} -`:"",matched:N,matchCount:P}}let M=[],R=0,L=new Set,$=-1,C=[];for(let T=0;T0&&R>=f);T++){let N=A[T],P;x&&!Js(x,N)?P=!1:(t.lastIndex=0,P=t.test(N)),P!==r&&(C.push(T),R++)}for(let T of C){let N=Math.max(0,T-c);$>=0&&N>$+1&&M.push(p);for(let F=N;F0?`${M.join(` +`:"",matched:N,matchCount:P}}let F=[],R=0,M=new Set,I=-1,C=[];for(let T=0;T<$&&!(f>0&&R>=f);T++){let N=A[T],P;x&&!_s(x,N)?P=!1:(t.lastIndex=0,P=t.test(N)),P!==r&&(C.push(T),R++)}for(let T of C){let N=Math.max(0,T-c);I>=0&&N>I+1&&F.push(p);for(let L=N;L0?`${F.join(` `)} -`:"",matched:R>0,matchCount:R}}function B3(e,t,n){let{invertMatch:r,showLineNumbers:s,countOnly:i,countMatches:o,filename:a,onlyMatching:l,beforeContext:c,afterContext:u,maxCount:f,contextSeparator:p,showColumn:h,showByteOffset:d,replace:m,kResetGroup:g,preFilter:y}=n;if(y&&!r&&!Js(y,e))return i||o?{output:`${a?`${a}:0`:"0"} +`:"",matched:R>0,matchCount:R}}function q4(e,t,n){let{invertMatch:r,showLineNumbers:s,countOnly:i,countMatches:o,filename:a,onlyMatching:l,beforeContext:c,afterContext:u,maxCount:f,contextSeparator:p,showColumn:h,showByteOffset:d,replace:m,kResetGroup:g,preFilter:y}=n;if(y&&!r&&!_s(y,e))return i||o?{output:`${a?`${a}:0`:"0"} `,matched:!1,matchCount:0}:{output:"",matched:!1,matchCount:0};let w=e.split(` `),b=w.length,x=b>0&&w[b-1]===""?b-1:b,A=[0];for(let C=0;C{let T=0;for(let N=0;NC);N++)T=N;return T},O=C=>{let T=I(C);return C-A[T]+1},M=[];t.lastIndex=0;for(let C=t.exec(e);C!==null&&!(f>0&&M.length>=f);C=t.exec(e)){let T=I(C.index),N=I(C.index+Math.max(0,C[0].length-1)),P=g!==void 0?C[g]??"":C[0];M.push({startLine:T,endLine:N,byteOffset:C.index,column:O(C.index),matchText:P}),C[0].length===0&&t.lastIndex++}if(i||o){let C;if(o)C=r?0:M.length;else{let N=new Set;for(let P of M)for(let F=P.startLine;F<=P.endLine;F++)N.add(F);C=r?x-N.size:N.size}return{output:`${a?`${a}:${C}`:String(C)} -`,matched:C>0,matchCount:C}}if(r){let C=new Set;for(let N of M)for(let P=N.startLine;P<=N.endLine;P++)C.add(P);let T=[];for(let N=0;N0?`${T.join(` +`&&A.push(C+1);let v=C=>{let T=0;for(let N=0;NC);N++)T=N;return T},$=C=>{let T=v(C);return C-A[T]+1},F=[];t.lastIndex=0;for(let C=t.exec(e);C!==null&&!(f>0&&F.length>=f);C=t.exec(e)){let T=v(C.index),N=v(C.index+Math.max(0,C[0].length-1)),P=g!==void 0?C[g]??"":C[0];F.push({startLine:T,endLine:N,byteOffset:C.index,column:$(C.index),matchText:P}),C[0].length===0&&t.lastIndex++}if(i||o){let C;if(o)C=r?0:F.length;else{let N=new Set;for(let P of F)for(let L=P.startLine;L<=P.endLine;L++)N.add(L);C=r?x-N.size:N.size}return{output:`${a?`${a}:${C}`:String(C)} +`,matched:C>0,matchCount:C}}if(r){let C=new Set;for(let N of F)for(let P=N.startLine;P<=N.endLine;P++)C.add(P);let T=[];for(let N=0;N0?`${T.join(` `)} -`:"",matched:T.length>0,matchCount:T.length}}if(M.length===0)return{output:"",matched:!1,matchCount:0};let R=new Set,L=-1,$=[];for(let C of M){let T=Math.max(0,C.startLine-c),N=Math.min(x-1,C.endLine+u);L>=0&&T>L+1&&$.push(p);for(let P=T;P0?`${$.join(` +`:"",matched:T.length>0,matchCount:T.length}}if(F.length===0)return{output:"",matched:!1,matchCount:0};let R=new Set,M=-1,I=[];for(let C of F){let T=Math.max(0,C.startLine-c),N=Math.min(x-1,C.endLine+u);M>=0&&T>M+1&&I.push(p);for(let P=T;P0?`${I.join(` `)} -`:"",matched:!0,matchCount:M.length}}var cp=v(()=>{"use strict"});function up(e){let t="",n=0;for(;n:]]"){t+="\\b",n+=7;continue}if(e[n]==="["){let r="[";for(n++,n]+)>/g,"(?<$1>"),t.mode==="perl"){n=G3(n),n=V3(n),n=q3(n);let a=X3(n);n=a.pattern,r=a.kResetGroup}break}default:n=up(e),n=e8(n);break}t.wholeWord&&(n=`\\b(?:${n})\\b`),t.lineRegexp&&(n=`^${n}$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(n),i="g"+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.multilineDotall?"s":"")+(s?"u":""),o=z3(n,t.ignoreCase??!1);return{regex:Q(n,i),kResetGroup:r,preFilter:o??void 0}}function z3(e,t){let n=e;if(n.startsWith("\\b(?:")&&n.endsWith(")\\b")?n=n.slice(5,n.length-3):n.startsWith("\\b")&&n.endsWith("\\b")&&n.length>=4&&(n=n.slice(2,n.length-2)),n.length===0)return null;let r=H3(n);if(r===null)return null;let s=[];for(let i of r){let o=j3(i);if(o===null||o.length===0)return null;s.push(o)}return s.length===0?null:{needles:t?s.map(i=>i.toLowerCase()):s,ignoreCase:t}}function H3(e){let t=[],n=0,r=!1,s=0;for(let i=0;i=0&&t[s]==="\\";s--)r++;r%2===0&&(t=t.slice(0,-1))}if(t.length===0)return null;let n="";for(let r=0;r0&&n+1=0&&e[r]==="\\";)n++,r--;if(n%2===0)return t}t+=2}else t++;return-1}function J3(e){let t=0,n=0;for(;n"),t=t.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),t}function e8(e){let t="",n=0,r=!0,s=0;for(;n{"use strict";Ze();W3=new Map([["alpha","a-zA-Z"],["digit","0-9"],["alnum","a-zA-Z0-9"],["lower","a-z"],["upper","A-Z"],["xdigit","0-9A-Fa-f"],["space"," \\t\\n\\r\\f\\v"],["blank"," \\t"],["punct","!-/:-@\\[-`{-~"],["graph","!-~"],["print"," -~"],["cntrl","\\x00-\\x1F\\x7F"],["ascii","\\x00-\\x7F"],["word","a-zA-Z0-9_"]])});var El=v(()=>{"use strict";cp();fp()});var Ji={};ee(Ji,{egrepCommand:()=>s8,egrepFlagsForFuzzing:()=>a8,fgrepCommand:()=>r8,fgrepFlagsForFuzzing:()=>o8,flagsForFuzzing:()=>i8,grepCommand:()=>Al});async function hp(e,t,n,r,s=0){if(s>=pp)return;let i=n.fs.resolvePath(n.cwd,e);try{if(!(await n.fs.stat(i)).isDirectory){let l=e.split("/").pop()||"";if(t){let c=t.replace(/^\//,"");Dt(l,c,{stripQuotes:!0})&&r.push(e)}return}let a=await n.fs.readdir(i);for(let l of a){let c=e==="."?l:`${e}/${l}`,u=n.fs.resolvePath(n.cwd,c);if((await n.fs.stat(u)).isDirectory)await hp(c,t,n,r,s+1);else if(t){let p=t.replace(/^\//,"");Dt(l,p,{stripQuotes:!0})&&r.push(c)}}}catch{}}async function n8(e,t){let n=[],r=e.lastIndexOf("/"),s,i;if(r===-1?(s=t.cwd,i=e):(s=e.slice(0,r)||"/",i=e.slice(r+1)),e.includes("**")){let a=[],l=e.split("**"),c=l[0].replace(/\/$/,"")||".",u=l[1]||"";return await hp(c,u,t,a),a.map(f=>({path:f}))}let o=t.fs.resolvePath(t.cwd,s);try{if(t.fs.readdirWithFileTypes){let a=await t.fs.readdirWithFileTypes(o);for(let l of a)if(Dt(l.name,i,{stripQuotes:!0})){let c=r===-1?l.name:`${s}/${l.name}`;n.push({path:c,isFile:l.isFile})}}else{let a=await t.fs.readdir(o);for(let l of a)if(Dt(l,i,{stripQuotes:!0})){let c=r===-1?l:`${s}/${l}`;n.push({path:c})}}}catch{}return n.sort((a,l)=>a.path.localeCompare(l.path))}async function Yi(e,t,n=[],r=[],s=[],i,o=0){if(o>=pp)return[];let a=t.fs.resolvePath(t.cwd,e),l=[];try{let c,u;if(i!==void 0)c=i,u=!i;else{let p=await t.fs.stat(a);c=p.isFile,u=p.isDirectory}if(c){let p=e.split("/").pop()||e;return r.length>0&&r.some(h=>Dt(p,h,{stripQuotes:!0}))?[]:n.length>0&&!n.some(h=>Dt(p,h,{stripQuotes:!0}))?[]:[{path:e,isFile:!0}]}if(!u)return[];let f=e.split("/").pop()||e;if(s.length>0&&s.some(p=>Dt(f,p,{stripQuotes:!0})))return[];if(t.fs.readdirWithFileTypes){let p=await t.fs.readdirWithFileTypes(a);for(let h of p){if(h.name.startsWith("."))continue;let d=e==="."?h.name:`${e}/${h.name}`,m=await Yi(d,t,n,r,s,h.isFile,o+1);l.push(...m)}}else{let p=await t.fs.readdir(a);for(let h of p){if(h.startsWith("."))continue;let d=e==="."?h:`${e}/${h}`,m=await Yi(d,t,n,r,s,void 0,o+1);l.push(...m)}}}catch{}return l}var t8,Al,pp,r8,s8,i8,o8,a8,eo=v(()=>{"use strict";ye();bl();oe();El();t8={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"]},Al={name:"grep",async execute(e,t){if(B(e))return U(t8);let n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,p=!1,h=!1,d=!1,m=!1,g=!1,y=0,w=0,b=0,x=[],A=[],I=[],O=null,M=[];for(let j=0;j1||l)&&!m,de=50;for(let j=0;j{let $e=ie.path,G=$e.split("/").pop()||$e;if(A.length>0&&!l&&A.some(Pe=>Dt(G,Pe,{stripQuotes:!0}))||x.length>0&&!l&&!x.some(Pe=>Dt(G,Pe,{stripQuotes:!0})))return null;try{let Pe=t.fs.resolvePath(t.cwd,$e),Qe=!1;if(ie.isFile===void 0?Qe=(await t.fs.stat(Pe)).isDirectory:Qe=!ie.isFile,Qe)return l?null:{error:`grep: ${$e}: Is a directory -`};let at=await t.fs.readFile(Pe);if(C&&!s){let st=C.ignoreCase?at.toLowerCase():at;if(!C.needles.some(tt=>st.includes(tt))){if(i){let tt=se?`${$e}:0`:"0";return{file:$e,result:{output:`${tt} -`,matched:!1,matchCount:0}}}return{file:$e,result:{output:"",matched:!1,matchCount:0}}}}let dt=fs(at,L,{invertMatch:s,showLineNumbers:r,countOnly:i,filename:se?$e:"",onlyMatching:d,beforeContext:w,afterContext:b,maxCount:y,kResetGroup:$,preFilter:C});return{file:$e,result:dt}}catch{return{error:`grep: ${$e}: No such file or directory -`}}}));for(let ie of ve){if(ie===null)continue;if("error"in ie&&ie.error){N+=ie.error,ie.error.includes("Is a directory")||(F=!0);continue}if(!("file"in ie)||!ie.result)continue;let{file:$e,result:G}=ie;if(G.matched){if(P=!0,g)return{stdout:"",stderr:"",exitCode:0};o?T+=`${$e} -`:a||(T+=G.output)}else a?T+=`${$e} -`:i&&!o&&(T+=G.output)}}let q;return F?q=2:a?q=T.length>0?0:1:q=P?0:1,g?{stdout:"",stderr:"",exitCode:q}:{stdout:T,stderr:N,exitCode:q}}},pp=256;r8={name:"fgrep",async execute(e,t){return Al.execute(["-F",...e],t)}},s8={name:"egrep",async execute(e,t){return Al.execute(["-E",...e],t)}},i8={name:"grep",flags:[{flag:"-E",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-P",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-L",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-e",type:"value",valueHint:"pattern"}],stdinType:"text",needsArgs:!0},o8={name:"fgrep",flags:[],stdinType:"text",needsArgs:!0},a8={name:"egrep",flags:[],stdinType:"text",needsArgs:!0}});function mp(e,t){if(Array.isArray(e))throw new TypeError(`${t}: expected object, got array`);if(Object.getPrototypeOf(e)!==null)throw new TypeError(`${t}: expected null-prototype object, got prototypal object`)}function _e(e){return!dp.has(e)}function ze(e,t,n){mp(e,"safeSet"),_e(t)&&(e[t]=n)}function Un(e,t){return mp(e,"safeHasOwn"),Object.hasOwn(e,t)}function ps(e){let t=new WeakMap,n=r=>{if(r===null||typeof r!="object"||r instanceof Date)return r;let s=t.get(r);if(s!==void 0)return s;if(Array.isArray(r)){let o=[];t.set(r,o);for(let a of r)o.push(n(a));return o}let i=Object.create(null);t.set(r,i);for(let o of Object.keys(r))i[o]=n(r[o]);return i};return n(e)}function Ge(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function gp(e){return Object.assign(Object.create(null),e)}function wt(e){return Object.assign(Object.create(null),e)}function Sl(...e){return Object.assign(Object.create(null),...e)}var dp,LN,Sn=v(()=>{"use strict";dp=new Set(["__proto__","constructor","prototype"]),LN=new Set([...dp,"__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])});function wp(){let e=[];for(let[t,n]of Object.entries(yp).sort()){let r=[];for(let s of n.extensions)r.push(`*${s}`);for(let s of n.globs)r.push(s);e.push(`${t}: ${r.join(", ")}`)}return`${e.join(` +`:"",matched:!0,matchCount:F.length}}var _1=O(()=>{"use strict"});function F1(e){let t="",n=0;for(;n:]]"){t+="\\b",n+=7;continue}if(e[n]==="["){let r="[";for(n++,n]+)>/g,"(?<$1>"),t.mode==="perl"){n=Y4(n),n=J4(n),n=e3(n);let a=s3(n);n=a.pattern,r=a.kResetGroup}break}default:n=F1(e),n=a3(n);break}t.wholeWord&&(n=`\\b(?:${n})\\b`),t.lineRegexp&&(n=`^${n}$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(n),i="g"+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.multilineDotall?"s":"")+(s?"u":""),o=K4(n,t.ignoreCase??!1);return{regex:Q(n,i),kResetGroup:r,preFilter:o??void 0}}function K4(e,t){let n=e;if(n.startsWith("\\b(?:")&&n.endsWith(")\\b")?n=n.slice(5,n.length-3):n.startsWith("\\b")&&n.endsWith("\\b")&&n.length>=4&&(n=n.slice(2,n.length-2)),n.length===0)return null;let r=Q4(n);if(r===null)return null;let s=[];for(let i of r){let o=X4(i);if(o===null||o.length===0)return null;s.push(o)}return s.length===0?null:{needles:t?s.map(i=>i.toLowerCase()):s,ignoreCase:t}}function Q4(e){let t=[],n=0,r=!1,s=0;for(let i=0;i=0&&t[s]==="\\";s--)r++;r%2===0&&(t=t.slice(0,-1))}if(t.length===0)return null;let n="";for(let r=0;r0&&n+1=0&&e[r]==="\\";)n++,r--;if(n%2===0)return t}t+=2}else t++;return-1}function o3(e){let t=0,n=0;for(;n"),t=t.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),t}function a3(e){let t="",n=0,r=!0,s=0;for(;n{"use strict";Ze();Z4=new Map([["alpha","a-zA-Z"],["digit","0-9"],["alnum","a-zA-Z0-9"],["lower","a-z"],["upper","A-Z"],["xdigit","0-9A-Fa-f"],["space"," \\t\\n\\r\\f\\v"],["blank"," \\t"],["punct","!-/:-@\\[-`{-~"],["graph","!-~"],["print"," -~"],["cntrl","\\x00-\\x1F\\x7F"],["ascii","\\x00-\\x7F"],["word","a-zA-Z0-9_"]])});var nl=O(()=>{"use strict";_1();L1()});var _i={};te(_i,{egrepCommand:()=>f3,egrepFlagsForFuzzing:()=>d3,fgrepCommand:()=>u3,fgrepFlagsForFuzzing:()=>h3,flagsForFuzzing:()=>p3,grepCommand:()=>rl});async function U1(e,t,n,r,s=0){if(s>=M1)return;let i=n.fs.resolvePath(n.cwd,e);try{if(!(await n.fs.stat(i)).isDirectory){let l=e.split("/").pop()||"";if(t){let c=t.replace(/^\//,"");Rt(l,c,{stripQuotes:!0})&&r.push(e)}return}let a=await n.fs.readdir(i);for(let l of a){let c=e==="."?l:`${e}/${l}`,u=n.fs.resolvePath(n.cwd,c);if((await n.fs.stat(u)).isDirectory)await U1(c,t,n,r,s+1);else if(t){let p=t.replace(/^\//,"");Rt(l,p,{stripQuotes:!0})&&r.push(c)}}}catch{}}async function c3(e,t){let n=[],r=e.lastIndexOf("/"),s,i;if(r===-1?(s=t.cwd,i=e):(s=e.slice(0,r)||"/",i=e.slice(r+1)),e.includes("**")){let a=[],l=e.split("**"),c=l[0].replace(/\/$/,"")||".",u=l[1]||"";return await U1(c,u,t,a),a.map(f=>({path:f}))}let o=t.fs.resolvePath(t.cwd,s);try{if(t.fs.readdirWithFileTypes){let a=await t.fs.readdirWithFileTypes(o);for(let l of a)if(Rt(l.name,i,{stripQuotes:!0})){let c=r===-1?l.name:`${s}/${l.name}`;n.push({path:c,isFile:l.isFile})}}else{let a=await t.fs.readdir(o);for(let l of a)if(Rt(l,i,{stripQuotes:!0})){let c=r===-1?l:`${s}/${l}`;n.push({path:c})}}}catch{}return n.sort((a,l)=>a.path.localeCompare(l.path))}async function Di(e,t,n=[],r=[],s=[],i,o=0){if(o>=M1)return[];let a=t.fs.resolvePath(t.cwd,e),l=[];try{let c,u;if(i!==void 0)c=i,u=!i;else{let p=await t.fs.stat(a);c=p.isFile,u=p.isDirectory}if(c){let p=e.split("/").pop()||e;return r.length>0&&r.some(h=>Rt(p,h,{stripQuotes:!0}))?[]:n.length>0&&!n.some(h=>Rt(p,h,{stripQuotes:!0}))?[]:[{path:e,isFile:!0}]}if(!u)return[];let f=e.split("/").pop()||e;if(s.length>0&&s.some(p=>Rt(f,p,{stripQuotes:!0})))return[];if(t.fs.readdirWithFileTypes){let p=await t.fs.readdirWithFileTypes(a);for(let h of p){if(h.name.startsWith("."))continue;let d=e==="."?h.name:`${e}/${h.name}`,m=await Di(d,t,n,r,s,h.isFile,o+1);l.push(...m)}}else{let p=await t.fs.readdir(a);for(let h of p){if(h.startsWith("."))continue;let d=e==="."?h:`${e}/${h}`,m=await Di(d,t,n,r,s,void 0,o+1);l.push(...m)}}}catch{}return l}var l3,rl,M1,u3,f3,p3,h3,d3,Fi=O(()=>{"use strict";ye();tl();oe();nl();l3={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"]},rl={name:"grep",async execute(e,t){if(B(e))return U(l3);let n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,p=!1,h=!1,d=!1,m=!1,g=!1,y=0,w=0,b=0,x=[],A=[],v=[],$=null,F=[];for(let j=0;j1||l)&&!m,de=50;for(let j=0;j{let Ie=ie.path,G=Ie.split("/").pop()||Ie;if(A.length>0&&!l&&A.some(Pe=>Rt(G,Pe,{stripQuotes:!0}))||x.length>0&&!l&&!x.some(Pe=>Rt(G,Pe,{stripQuotes:!0})))return null;try{let Pe=t.fs.resolvePath(t.cwd,Ie),Qe=!1;if(ie.isFile===void 0?Qe=(await t.fs.stat(Pe)).isDirectory:Qe=!ie.isFile,Qe)return l?null:{error:`grep: ${Ie}: Is a directory +`};let at=await t.fs.readFile(Pe);if(C&&!s){let st=C.ignoreCase?at.toLowerCase():at;if(!C.needles.some(tt=>st.includes(tt))){if(i){let tt=se?`${Ie}:0`:"0";return{file:Ie,result:{output:`${tt} +`,matched:!1,matchCount:0}}}return{file:Ie,result:{output:"",matched:!1,matchCount:0}}}}let ht=Er(at,M,{invertMatch:s,showLineNumbers:r,countOnly:i,filename:se?Ie:"",onlyMatching:d,beforeContext:w,afterContext:b,maxCount:y,kResetGroup:I,preFilter:C});return{file:Ie,result:ht}}catch{return{error:`grep: ${Ie}: No such file or directory +`}}}));for(let ie of ve){if(ie===null)continue;if("error"in ie&&ie.error){N+=ie.error,ie.error.includes("Is a directory")||(L=!0);continue}if(!("file"in ie)||!ie.result)continue;let{file:Ie,result:G}=ie;if(G.matched){if(P=!0,g)return{stdout:"",stderr:"",exitCode:0};o?T+=`${Ie} +`:a||(T+=G.output)}else a?T+=`${Ie} +`:i&&!o&&(T+=G.output)}}let q;return L?q=2:a?q=T.length>0?0:1:q=P?0:1,g?{stdout:"",stderr:"",exitCode:q}:{stdout:T,stderr:N,exitCode:q}}},M1=256;u3={name:"fgrep",async execute(e,t){return rl.execute(["-F",...e],t)}},f3={name:"egrep",async execute(e,t){return rl.execute(["-E",...e],t)}},p3={name:"grep",flags:[{flag:"-E",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-P",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-L",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-e",type:"value",valueHint:"pattern"}],stdinType:"text",needsArgs:!0},h3={name:"fgrep",flags:[],stdinType:"text",needsArgs:!0},d3={name:"egrep",flags:[],stdinType:"text",needsArgs:!0}});function W1(e,t){if(Array.isArray(e))throw new TypeError(`${t}: expected object, got array`);if(Object.getPrototypeOf(e)!==null)throw new TypeError(`${t}: expected null-prototype object, got prototypal object`)}function _e(e){return!B1.has(e)}function ze(e,t,n){W1(e,"safeSet"),_e(t)&&(e[t]=n)}function On(e,t){return W1(e,"safeHasOwn"),Object.hasOwn(e,t)}function Xr(e){let t=new WeakMap,n=r=>{if(r===null||typeof r!="object"||r instanceof Date)return r;let s=t.get(r);if(s!==void 0)return s;if(Array.isArray(r)){let o=[];t.set(r,o);for(let a of r)o.push(n(a));return o}let i=Object.create(null);t.set(r,i);for(let o of Object.keys(r))i[o]=n(r[o]);return i};return n(e)}function Ge(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function z1(e){return Object.assign(Object.create(null),e)}function yt(e){return Object.assign(Object.create(null),e)}function sl(...e){return Object.assign(Object.create(null),...e)}var B1,Gk,gn=O(()=>{"use strict";B1=new Set(["__proto__","constructor","prototype"]),Gk=new Set([...B1,"__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])});function j1(){let e=[];for(let[t,n]of Object.entries(H1).sort()){let r=[];for(let s of n.extensions)r.push(`*${s}`);for(let s of n.globs)r.push(s);e.push(`${t}: ${r.join(", ")}`)}return`${e.join(` `)} -`}var yp,ti,Cl=v(()=>{"use strict";Ze();Sn();yp=gp({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),ti=class{types;constructor(){this.types=new Map(Object.entries(yp).map(([t,n])=>[t,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(t){let n=t.indexOf(":");if(n===-1)return;let r=t.slice(0,n),s=t.slice(n+1);if(s.startsWith("include:")){let i=s.slice(8),o=this.types.get(i);if(o){let a=this.types.get(r)||{extensions:[],globs:[]};a.extensions.push(...o.extensions),a.globs.push(...o.globs),this.types.set(r,a)}}else{let i=this.types.get(r)||{extensions:[],globs:[]};if(s.startsWith("*.")&&!s.slice(2).includes("*")){let o=s.slice(1);i.extensions.includes(o)||i.extensions.push(o)}else i.globs.includes(s)||i.globs.push(s);this.types.set(r,i)}}clearType(t){let n=this.types.get(t);n&&(n.extensions=[],n.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,n){let r=t.toLowerCase();for(let s of n){if(s==="all"){if(this.matchesAnyType(t))return!0;continue}let i=this.types.get(s);if(i){for(let o of i.extensions)if(r.endsWith(o))return!0;for(let o of i.globs)if(o.includes("*")){let a=o.replace(/\./g,"\\.").replace(/\*/g,".*");if(Q(`^${a}$`,"i").test(t))return!0}else if(r===o.toLowerCase())return!0}}return!1}matchesAnyType(t){let n=t.toLowerCase();for(let r of this.types.values()){for(let s of r.extensions)if(n.endsWith(s))return!0;for(let s of r.globs)if(s.includes("*")){let i=s.replace(/\./g,"\\.").replace(/\*/g,".*");if(Q(`^${i}$`,"i").test(t))return!0}else if(n===s.toLowerCase())return!0}return!1}}});function bp(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}var xp=v(()=>{"use strict"});function l8(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let n=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return n*1024;case"M":return n*1024*1024;case"G":return n*1024*1024*1024;default:return n}}function c8(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} -`,exitCode:1}}function Ep(e){return null}function p8(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function h8(e,t,n){let r=e[t];for(let s of Ap){if(r.startsWith(`--${s.long}=`)){let i=r.slice(`--${s.long}=`.length),o=to(n,s,i);return o?{newIndex:t,error:o}:{newIndex:t}}if(s.short&&r.startsWith(`-${s.short}`)&&r.length>2){let i=r.slice(2),o=to(n,s,i);return o?{newIndex:t,error:o}:{newIndex:t}}if(s.short&&r===`-${s.short}`||r===`--${s.long}`){if(t+1>=e.length)return null;let i=e[t+1],o=to(n,s,i);return o?{newIndex:t+1,error:o}:{newIndex:t+1}}}return null}function d8(e){return Ap.find(t=>t.short===e)}function to(e,t,n){if(t.validate){let s=t.validate(n);if(s)return s}if(t.ignored||!t.target)return;let r=t.parse?t.parse(n):n;t.multi?e[t.target].push(r):e[t.target]=r}function m8(e,t){let n=e[t];if(n==="--sort"&&t+1=e.length)return{success:!1,error:K("rg",`-${g}`)};let b=to(t,w,e[l+1]);if(b)return{success:!1,error:b};l++,m=!0;continue}}let y=u8.get(g);if(y){y(t);continue}if(g.startsWith("--"))return{success:!1,error:K("rg",g)};if(g.length===1)return{success:!1,error:K("rg",`-${g}`)}}}else n===null&&t.patterns.length===0&&t.patternFiles.length===0?n=c:r.push(c)}return(s>=0||o>=0)&&(t.afterContext=Math.max(s>=0?s:0,o>=0?o:0)),(i>=0||o>=0)&&(t.beforeContext=Math.max(i>=0?i:0,o>=0?o:0)),n!==null&&t.patterns.push(n),(t.column||t.vimgrep)&&(a=!0),{success:!0,options:t,paths:r,explicitLineNumbers:a}}var Ap,u8,f8,Cp=v(()=>{"use strict";oe();xp();Ap=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:Ep},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:Ep},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:l8,validate:c8},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],u8=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),f8=new Set(["n","--line-number"])});function w8(e){return`'${e.replace(/'/g,"'\\''")}'`}function rn(e){return e.map(w8).join(" ")}var Rr=v(()=>{"use strict"});async function vl(e,t,n=!1,r=!1,s=[]){let i=new ri(e,t,n,r);await i.load(t);for(let o of s)try{let a=e.resolvePath(t,o),l=await e.readFile(a);i.addPatternsFromContent(l,t)}catch{}return i}var ni,ri,vp=v(()=>{"use strict";Ze();ni=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let n=t.split(` -`);for(let r of n){let s=r.replace(/\s+$/,"");if(!s||s.startsWith("#"))continue;let i=!1;s.startsWith("!")&&(i=!0,s=s.slice(1));let o=!1;s.endsWith("/")&&(o=!0,s=s.slice(0,-1));let a=!1;s.startsWith("/")?(a=!0,s=s.slice(1)):s.includes("/")&&!s.startsWith("**/")&&(a=!0);let l=this.patternToRegex(s,a);this.patterns.push({pattern:r,regex:l,negated:i,directoryOnly:o,rooted:a})}}patternToRegex(t,n){let r="";n?r="^":r="(?:^|/)";let s=0;for(;s=t.length,r+=".*",s+=2):(r+="[^/]*",s++);else if(i==="?")r+="[^/]",s++;else if(i==="["){let o=s+1;for(o=2&&e[0]===31&&e[1]===139}function E8(e){let t=!1;for(let n=0;nb.length>0);i.push(...w)}catch{return{stdout:"",stderr:`rg: ${g}: No such file or directory +`}var H1,Ls,il=O(()=>{"use strict";Ze();gn();H1=z1({js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}}),Ls=class{types;constructor(){this.types=new Map(Object.entries(H1).map(([t,n])=>[t,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(t){let n=t.indexOf(":");if(n===-1)return;let r=t.slice(0,n),s=t.slice(n+1);if(s.startsWith("include:")){let i=s.slice(8),o=this.types.get(i);if(o){let a=this.types.get(r)||{extensions:[],globs:[]};a.extensions.push(...o.extensions),a.globs.push(...o.globs),this.types.set(r,a)}}else{let i=this.types.get(r)||{extensions:[],globs:[]};if(s.startsWith("*.")&&!s.slice(2).includes("*")){let o=s.slice(1);i.extensions.includes(o)||i.extensions.push(o)}else i.globs.includes(s)||i.globs.push(s);this.types.set(r,i)}}clearType(t){let n=this.types.get(t);n&&(n.extensions=[],n.globs=[])}getType(t){return this.types.get(t)}getAllTypes(){return this.types}matchesType(t,n){let r=t.toLowerCase();for(let s of n){if(s==="all"){if(this.matchesAnyType(t))return!0;continue}let i=this.types.get(s);if(i){for(let o of i.extensions)if(r.endsWith(o))return!0;for(let o of i.globs)if(o.includes("*")){let a=o.replace(/\./g,"\\.").replace(/\*/g,".*");if(Q(`^${a}$`,"i").test(t))return!0}else if(r===o.toLowerCase())return!0}}return!1}matchesAnyType(t){let n=t.toLowerCase();for(let r of this.types.values()){for(let s of r.extensions)if(n.endsWith(s))return!0;for(let s of r.globs)if(s.includes("*")){let i=s.replace(/\./g,"\\.").replace(/\*/g,".*");if(Q(`^${i}$`,"i").test(t))return!0}else if(n===s.toLowerCase())return!0}return!1}}});function G1(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:256,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}var V1=O(()=>{"use strict"});function m3(e){let t=e.match(/^(\d+)([KMG])?$/i);if(!t)return 0;let n=parseInt(t[1],10);switch((t[2]||"").toUpperCase()){case"K":return n*1024;case"M":return n*1024*1024;case"G":return n*1024*1024*1024;default:return n}}function g3(e){return/^\d+[KMG]?$/i.test(e)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${e} +`,exitCode:1}}function q1(e){return null}function b3(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function x3(e,t,n){let r=e[t];for(let s of Z1){if(r.startsWith(`--${s.long}=`)){let i=r.slice(`--${s.long}=`.length),o=Li(n,s,i);return o?{newIndex:t,error:o}:{newIndex:t}}if(s.short&&r.startsWith(`-${s.short}`)&&r.length>2){let i=r.slice(2),o=Li(n,s,i);return o?{newIndex:t,error:o}:{newIndex:t}}if(s.short&&r===`-${s.short}`||r===`--${s.long}`){if(t+1>=e.length)return null;let i=e[t+1],o=Li(n,s,i);return o?{newIndex:t+1,error:o}:{newIndex:t+1}}}return null}function E3(e){return Z1.find(t=>t.short===e)}function Li(e,t,n){if(t.validate){let s=t.validate(n);if(s)return s}if(t.ignored||!t.target)return;let r=t.parse?t.parse(n):n;t.multi?e[t.target].push(r):e[t.target]=r}function A3(e,t){let n=e[t];if(n==="--sort"&&t+1=e.length)return{success:!1,error:K("rg",`-${g}`)};let b=Li(t,w,e[l+1]);if(b)return{success:!1,error:b};l++,m=!0;continue}}let y=y3.get(g);if(y){y(t);continue}if(g.startsWith("--"))return{success:!1,error:K("rg",g)};if(g.length===1)return{success:!1,error:K("rg",`-${g}`)}}}else n===null&&t.patterns.length===0&&t.patternFiles.length===0?n=c:r.push(c)}return(s>=0||o>=0)&&(t.afterContext=Math.max(s>=0?s:0,o>=0?o:0)),(i>=0||o>=0)&&(t.beforeContext=Math.max(i>=0?i:0,o>=0?o:0)),n!==null&&t.patterns.push(n),(t.column||t.vimgrep)&&(a=!0),{success:!0,options:t,paths:r,explicitLineNumbers:a}}var Z1,y3,w3,Q1=O(()=>{"use strict";oe();V1();Z1=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:q1},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:q1},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:m3,validate:g3},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",ignored:!0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],y3=new Map([["i",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["--ignore-case",e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1}],["s",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["--case-sensitive",e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1}],["S",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["--smart-case",e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1}],["F",e=>{e.fixedStrings=!0}],["--fixed-strings",e=>{e.fixedStrings=!0}],["w",e=>{e.wordRegexp=!0}],["--word-regexp",e=>{e.wordRegexp=!0}],["x",e=>{e.lineRegexp=!0}],["--line-regexp",e=>{e.lineRegexp=!0}],["v",e=>{e.invertMatch=!0}],["--invert-match",e=>{e.invertMatch=!0}],["U",e=>{e.multiline=!0}],["--multiline",e=>{e.multiline=!0}],["--multiline-dotall",e=>{e.multilineDotall=!0,e.multiline=!0}],["c",e=>{e.count=!0}],["--count",e=>{e.count=!0}],["--count-matches",e=>{e.countMatches=!0}],["l",e=>{e.filesWithMatches=!0}],["--files",e=>{e.files=!0}],["--files-with-matches",e=>{e.filesWithMatches=!0}],["--files-without-match",e=>{e.filesWithoutMatch=!0}],["--stats",e=>{e.stats=!0}],["o",e=>{e.onlyMatching=!0}],["--only-matching",e=>{e.onlyMatching=!0}],["q",e=>{e.quiet=!0}],["--quiet",e=>{e.quiet=!0}],["N",e=>{e.lineNumber=!1}],["--no-line-number",e=>{e.lineNumber=!1}],["H",e=>{e.withFilename=!0}],["--with-filename",e=>{e.withFilename=!0}],["I",e=>{e.noFilename=!0}],["--no-filename",e=>{e.noFilename=!0}],["0",e=>{e.nullSeparator=!0}],["--null",e=>{e.nullSeparator=!0}],["b",e=>{e.byteOffset=!0}],["--byte-offset",e=>{e.byteOffset=!0}],["--column",e=>{e.column=!0,e.lineNumber=!0}],["--no-column",e=>{e.column=!1}],["--vimgrep",e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0}],["--json",e=>{e.json=!0}],["--hidden",e=>{e.hidden=!0}],["--no-ignore",e=>{e.noIgnore=!0}],["--no-ignore-dot",e=>{e.noIgnoreDot=!0}],["--no-ignore-vcs",e=>{e.noIgnoreVcs=!0}],["L",e=>{e.followSymlinks=!0}],["--follow",e=>{e.followSymlinks=!0}],["z",e=>{e.searchZip=!0}],["--search-zip",e=>{e.searchZip=!0}],["a",e=>{e.searchBinary=!0}],["--text",e=>{e.searchBinary=!0}],["--heading",e=>{e.heading=!0}],["--passthru",e=>{e.passthru=!0}],["--include-zero",e=>{e.includeZero=!0}],["--glob-case-insensitive",e=>{e.globCaseInsensitive=!0}]]),w3=new Set(["n","--line-number"])});function v3(e){return`'${e.replace(/'/g,"'\\''")}'`}function Xt(e){return e.map(v3).join(" ")}var Ar=O(()=>{"use strict"});async function ol(e,t,n=!1,r=!1,s=[]){let i=new Us(e,t,n,r);await i.load(t);for(let o of s)try{let a=e.resolvePath(t,o),l=await e.readFile(a);i.addPatternsFromContent(l,t)}catch{}return i}var Ms,Us,X1=O(()=>{"use strict";Ze();Ms=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let n=t.split(` +`);for(let r of n){let s=r.replace(/\s+$/,"");if(!s||s.startsWith("#"))continue;let i=!1;s.startsWith("!")&&(i=!0,s=s.slice(1));let o=!1;s.endsWith("/")&&(o=!0,s=s.slice(0,-1));let a=!1;s.startsWith("/")?(a=!0,s=s.slice(1)):s.includes("/")&&!s.startsWith("**/")&&(a=!0);let l=this.patternToRegex(s,a);this.patterns.push({pattern:r,regex:l,negated:i,directoryOnly:o,rooted:a})}}patternToRegex(t,n){let r="";n?r="^":r="(?:^|/)";let s=0;for(;s=t.length,r+=".*",s+=2):(r+="[^/]*",s++);else if(i==="?")r+="[^/]",s++;else if(i==="["){let o=s+1;for(o=2&&e[0]===31&&e[1]===139}function I3(e){let t=!1;for(let n=0;nA.length>0);i.push(...x)}catch{return{stdout:"",stderr:`rg: ${w}: No such file or directory `,exitCode:2}}if(i.length===0)return n.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given -`,exitCode:2};let o=r.length===0?["."]:r,a=A8(n,i),l,c;try{let g=S8(i,n,a);l=g.regex,c=g.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${i.join(", ")} -`,exitCode:2}}let u=null;n.noIgnore||(u=await vl(t.fs,t.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let f=new ti;for(let g of n.typeClear)f.clearType(g);for(let g of n.typeAdd)f.addType(g);let{files:p,singleExplicitFile:h}=await Np(t,o,n,u,f);if(p.length===0)return{stdout:"",stderr:"",exitCode:1};let d=!n.noFilename&&(n.withFilename||!h||p.length>1),m=n.lineNumber;return s||(h&&p.length===1&&(m=!1),n.onlyMatching&&(m=!1)),N8(t,p,l,n,d,m,c)}function A8(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(n=>/[A-Z]/.test(n)):!1}function S8(e,t,n){let r;return e.length===1?r=e[0]:r=e.map(s=>t.fixedStrings?s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${s})`).join("|"),ei(r,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:n,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function Np(e,t,n,r,s){let i=[],o=0,a=0;for(let c of t){let u=e.fs.resolvePath(e.cwd,c);try{let f=await e.fs.stat(u);if(f.isFile){if(o++,n.maxFilesize>0&&f.size>n.maxFilesize)continue;$p(c,n,r,u,s)&&i.push(c)}else f.isDirectory&&(a++,await Ip(e,c,u,0,n,r,s,i))}catch{}}return{files:n.sort==="path"?i.sort():i,singleExplicitFile:o===1&&a===0}}async function Ip(e,t,n,r,s,i,o,a){if(!(r>=s.maxDepth)){i&&await i.loadForDirectory(n);try{let l=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(n):(await e.fs.readdir(n)).map(c=>({name:c,isFile:void 0}));for(let c of l){let u=c.name;if(!s.noIgnore&&ri.isCommonIgnored(u))continue;let f=u.startsWith("."),p=t==="."?u:t==="./"?`./${u}`:t.endsWith("/")?`${t}${u}`:`${t}/${u}`,h=e.fs.resolvePath(n,u),d,m,g=!1;if(c.isFile!==void 0&&"isDirectory"in c){let b=c;if(g=b.isSymbolicLink===!0,g&&!s.followSymlinks)continue;if(g&&s.followSymlinks)try{let x=await e.fs.stat(h);d=x.isFile,m=x.isDirectory}catch{continue}else d=b.isFile,m=b.isDirectory}else try{let b=e.fs.lstat?await e.fs.lstat(h):await e.fs.stat(h);if(g=b.isSymbolicLink===!0,g&&!s.followSymlinks)continue;let x=g&&s.followSymlinks?await e.fs.stat(h):b;d=x.isFile,m=x.isDirectory}catch{continue}if(!i?.matches(h,m)&&!(f&&!s.hidden&&!i?.isWhitelisted(h,m))){if(m)await Ip(e,p,h,r+1,s,i,o,a);else if(d){if(s.maxFilesize>0)try{if((await e.fs.stat(h)).size>s.maxFilesize)continue}catch{continue}$p(p,s,i,h,o)&&a.push(p)}}}}catch{}}}function $p(e,t,n,r,s){let i=e.split("/").pop()||e;if(n?.matches(r,!1)||t.types.length>0&&!s.matchesType(i,t.types)||t.typesNot.length>0&&s.matchesType(i,t.typesNot))return!1;if(t.globs.length>0){let o=t.globCaseInsensitive,a=t.globs.filter(c=>!c.startsWith("!")),l=t.globs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(a.length>0){let c=!1;for(let u of a)if(Cn(i,u,o)||Cn(e,u,o)){c=!0;break}if(!c)return!1}for(let c of l)if(c.startsWith("/")){let u=c.slice(1);if(Cn(e,u,o))return!1}else if(Cn(i,c,o)||Cn(e,c,o))return!1}if(t.iglobs.length>0){let o=t.iglobs.filter(l=>!l.startsWith("!")),a=t.iglobs.filter(l=>l.startsWith("!")).map(l=>l.slice(1));if(o.length>0){let l=!1;for(let c of o)if(Cn(i,c,!0)||Cn(e,c,!0)){l=!0;break}if(!l)return!1}for(let l of a)if(l.startsWith("/")){let c=l.slice(1);if(Cn(e,c,!0))return!1}else if(Cn(i,l,!0)||Cn(e,l,!0))return!1}return!0}function Cn(e,t,n=!1){let r="^";for(let s=0;sc+a).join(""),stderr:"",exitCode:0}}function v8(e,t){if(t.length===0)return!0;for(let n of t)if(Cn(e,n,!1))return!0;return!1}async function k8(e,t,n,r){try{if(r.preprocessor&&e.exec){let o=n.split("/").pop()||n;if(v8(o,r.preprocessorGlobs)){let a=await e.exec(rn([r.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(a.exitCode===0&&a.stdout){let l=le(a.stdout),c=l.slice(0,8192);return{content:l,isBinary:c.includes("\0")}}}}if(r.searchZip&&n.endsWith(".gz")){let o=await e.fs.readFileBuffer(t);if(x8(o))try{let a=b8(o),l=new TextDecoder().decode(a),c=l.slice(0,8192);return{content:l,isBinary:c.includes("\0")}}catch{return null}}let s=await e.fs.readFile(t),i=s.slice(0,8192);return{content:s,isBinary:i.includes("\0")}}catch{return null}}async function N8(e,t,n,r,s,i,o){let a="",l=!1,c=[],u=0,f=0,p=0,h=50;e:for(let g=0;g{let x=e.fs.resolvePath(e.cwd,b),A=await k8(e,x,b,r);if(!A)return null;let{content:I,isBinary:O}=A;if(p+=I.length,O&&!r.searchBinary)return null;let M=s&&!r.heading?b:"",R=fs(I,n,{invertMatch:r.invertMatch,showLineNumbers:i,countOnly:r.count,countMatches:r.countMatches,filename:M,onlyMatching:r.onlyMatching,beforeContext:r.beforeContext,afterContext:r.afterContext,maxCount:r.maxCount,contextSeparator:r.contextSeparator,showColumn:r.column,vimgrep:r.vimgrep,showByteOffset:r.byteOffset,replace:r.replace!==null?xl(r.replace):null,passthru:r.passthru,multiline:r.multiline,kResetGroup:o});return r.json&&R.matched?{file:b,result:R,content:I,isBinary:!1}:{file:b,result:R}}));for(let b of w){if(!b)continue;let{file:x,result:A}=b;if(A.matched){if(l=!0,f++,u+=A.matchCount,r.quiet&&!r.json)break e;if(r.json&&!r.quiet){let I=b.content||"";c.push(JSON.stringify({type:"begin",data:{path:{text:x}}}));let O=I.split(` -`);n.lastIndex=0;let M=0;for(let R=0;R0){let C={type:"match",data:{path:{text:x},lines:{text:`${L} -`},line_number:R+1,absolute_offset:M,submatches:$}};c.push(JSON.stringify(C))}M+=L.length+1}c.push(JSON.stringify({type:"end",data:{path:{text:x},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:I.length,bytes_printed:0,matched_lines:A.matchCount,matches:A.matchCount}}}))}else if(r.filesWithMatches){let I=r.nullSeparator?"\0":` -`;a+=`${x}${I}`}else r.filesWithoutMatch||(r.heading&&!r.noFilename&&(a+=`${x} -`),a+=A.output)}else if(r.filesWithoutMatch){let I=r.nullSeparator?"\0":` -`;a+=`${x}${I}`}else r.includeZero&&(r.count||r.countMatches)&&(a+=A.output)}}r.json&&(c.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:f,bytes_searched:p,bytes_printed:0,matched_lines:u,matches:u}}})),a=`${c.join(` +`,exitCode:2};let o=$3(n,i),a,l;try{let w=T3(i,n,o);a=w.regex,l=w.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${i.join(", ")} +`,exitCode:2}}let c=n.patternFiles.includes("-"),u=ae(t.stdin);if(r.length===0&&u.length>0&&!c){let b=Er(u,a,{invertMatch:n.invertMatch,showLineNumbers:n.lineNumber,countOnly:n.count,countMatches:n.countMatches,filename:"",onlyMatching:n.onlyMatching,beforeContext:n.beforeContext,afterContext:n.afterContext,maxCount:n.maxCount,contextSeparator:n.contextSeparator,showColumn:n.column,vimgrep:n.vimgrep,showByteOffset:n.byteOffset,replace:n.replace!==null?Pi(n.replace):null,passthru:n.passthru,multiline:n.multiline,kResetGroup:l});return n.quiet?{stdout:"",stderr:"",exitCode:b.matched?0:1}:n.filesWithMatches?{stdout:b.matched?`(standard input) +`:"",stderr:"",exitCode:b.matched?0:1}:n.filesWithoutMatch?{stdout:b.matched?"":`(standard input) +`,stderr:"",exitCode:b.matched?1:0}:{stdout:b.output,stderr:"",exitCode:b.matched?0:1}}let f=r.length===0?["."]:r,p=null;n.noIgnore||(p=await ol(t.fs,t.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let h=new Ls;for(let w of n.typeClear)h.clearType(w);for(let w of n.typeAdd)h.addType(w);let{files:d,singleExplicitFile:m}=await J1(t,f,n,p,h);if(d.length===0)return{stdout:"",stderr:"",exitCode:1};let g=!n.noFilename&&(n.withFilename||!m||d.length>1),y=n.lineNumber;return s||(m&&d.length===1&&(y=!1),n.onlyMatching&&(y=!1)),D3(t,d,a,n,g,y,l)}function $3(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(n=>/[A-Z]/.test(n)):!1}function T3(e,t,n){let r;return e.length===1?r=e[0]:r=e.map(s=>t.fixedStrings?s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${s})`).join("|"),Fs(r,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:n,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline,multilineDotall:t.multilineDotall})}async function J1(e,t,n,r,s){let i=[],o=0,a=0;for(let c of t){let u=e.fs.resolvePath(e.cwd,c);try{let f=await e.fs.stat(u);if(f.isFile){if(o++,n.maxFilesize>0&&f.size>n.maxFilesize)continue;tp(c,n,r,u,s)&&i.push(c)}else f.isDirectory&&(a++,await ep(e,c,u,0,n,r,s,i))}catch{}}return{files:n.sort==="path"?i.sort():i,singleExplicitFile:o===1&&a===0}}async function ep(e,t,n,r,s,i,o,a){if(!(r>=s.maxDepth)){i&&await i.loadForDirectory(n);try{let l=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(n):(await e.fs.readdir(n)).map(c=>({name:c,isFile:void 0}));for(let c of l){let u=c.name;if(!s.noIgnore&&Us.isCommonIgnored(u))continue;let f=u.startsWith("."),p=t==="."?u:t==="./"?`./${u}`:t.endsWith("/")?`${t}${u}`:`${t}/${u}`,h=e.fs.resolvePath(n,u),d,m,g=!1;if(c.isFile!==void 0&&"isDirectory"in c){let b=c;if(g=b.isSymbolicLink===!0,g&&!s.followSymlinks)continue;if(g&&s.followSymlinks)try{let x=await e.fs.stat(h);d=x.isFile,m=x.isDirectory}catch{continue}else d=b.isFile,m=b.isDirectory}else try{let b=e.fs.lstat?await e.fs.lstat(h):await e.fs.stat(h);if(g=b.isSymbolicLink===!0,g&&!s.followSymlinks)continue;let x=g&&s.followSymlinks?await e.fs.stat(h):b;d=x.isFile,m=x.isDirectory}catch{continue}if(!i?.matches(h,m)&&!(f&&!s.hidden&&!i?.isWhitelisted(h,m))){if(m)await ep(e,p,h,r+1,s,i,o,a);else if(d){if(s.maxFilesize>0)try{if((await e.fs.stat(h)).size>s.maxFilesize)continue}catch{continue}tp(p,s,i,h,o)&&a.push(p)}}}}catch{}}}function tp(e,t,n,r,s){let i=e.split("/").pop()||e;if(n?.matches(r,!1)||t.types.length>0&&!s.matchesType(i,t.types)||t.typesNot.length>0&&s.matchesType(i,t.typesNot))return!1;if(t.globs.length>0){let o=t.globCaseInsensitive,a=t.globs.filter(c=>!c.startsWith("!")),l=t.globs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(a.length>0){let c=!1;for(let u of a)if(yn(i,u,o)||yn(e,u,o)){c=!0;break}if(!c)return!1}for(let c of l)if(c.startsWith("/")){let u=c.slice(1);if(yn(e,u,o))return!1}else if(yn(i,c,o)||yn(e,c,o))return!1}if(t.iglobs.length>0){let o=t.iglobs.filter(l=>!l.startsWith("!")),a=t.iglobs.filter(l=>l.startsWith("!")).map(l=>l.slice(1));if(o.length>0){let l=!1;for(let c of o)if(yn(i,c,!0)||yn(e,c,!0)){l=!0;break}if(!l)return!1}for(let l of a)if(l.startsWith("/")){let c=l.slice(1);if(yn(e,c,!0))return!1}else if(yn(i,l,!0)||yn(e,l,!0))return!1}return!0}function yn(e,t,n=!1){let r="^";for(let s=0;sc+a).join(""),stderr:"",exitCode:0}}function R3(e,t){if(t.length===0)return!0;for(let n of t)if(yn(e,n,!1))return!0;return!1}async function P3(e,t,n,r){try{if(r.preprocessor&&e.exec){let o=n.split("/").pop()||n;if(R3(o,r.preprocessorGlobs)){let a=await e.exec(Xt([r.preprocessor]),{cwd:e.cwd,signal:e.signal,args:[t]});if(a.exitCode===0&&a.stdout){let l=ae(a.stdout),c=l.slice(0,8192);return{content:l,isBinary:c.includes("\0")}}}}if(r.searchZip&&n.endsWith(".gz")){let o=await e.fs.readFileBuffer(t);if(N3(o))try{let a=k3(o),l=new TextDecoder().decode(a),c=l.slice(0,8192);return{content:l,isBinary:c.includes("\0")}}catch{return null}}let s=await e.fs.readFile(t),i=s.slice(0,8192);return{content:s,isBinary:i.includes("\0")}}catch{return null}}async function D3(e,t,n,r,s,i,o){let a="",l=!1,c=[],u=0,f=0,p=0,h=50;e:for(let g=0;g{let x=e.fs.resolvePath(e.cwd,b),A=await P3(e,x,b,r);if(!A)return null;let{content:v,isBinary:$}=A;if(p+=v.length,$&&!r.searchBinary)return null;let F=s&&!r.heading?b:"",R=Er(v,n,{invertMatch:r.invertMatch,showLineNumbers:i,countOnly:r.count,countMatches:r.countMatches,filename:F,onlyMatching:r.onlyMatching,beforeContext:r.beforeContext,afterContext:r.afterContext,maxCount:r.maxCount,contextSeparator:r.contextSeparator,showColumn:r.column,vimgrep:r.vimgrep,showByteOffset:r.byteOffset,replace:r.replace!==null?Pi(r.replace):null,passthru:r.passthru,multiline:r.multiline,kResetGroup:o});return r.json&&R.matched?{file:b,result:R,content:v,isBinary:!1}:{file:b,result:R}}));for(let b of w){if(!b)continue;let{file:x,result:A}=b;if(A.matched){if(l=!0,f++,u+=A.matchCount,r.quiet&&!r.json)break e;if(r.json&&!r.quiet){let v=b.content||"";c.push(JSON.stringify({type:"begin",data:{path:{text:x}}}));let $=v.split(` +`);n.lastIndex=0;let F=0;for(let R=0;R<$.length;R++){let M=$[R];n.lastIndex=0;let I=[];for(let C=n.exec(M);C!==null;C=n.exec(M)){let T={match:{text:C[0]},start:C.index,end:C.index+C[0].length};r.replace!==null&&(T.replacement={text:r.replace}),I.push(T),C[0].length===0&&n.lastIndex++}if(I.length>0){let C={type:"match",data:{path:{text:x},lines:{text:`${M} +`},line_number:R+1,absolute_offset:F,submatches:I}};c.push(JSON.stringify(C))}F+=M.length+1}c.push(JSON.stringify({type:"end",data:{path:{text:x},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:v.length,bytes_printed:0,matched_lines:A.matchCount,matches:A.matchCount}}}))}else if(r.filesWithMatches){let v=r.nullSeparator?"\0":` +`;a+=`${x}${v}`}else r.filesWithoutMatch||(r.heading&&!r.noFilename&&(a+=`${x} +`),a+=A.output)}else if(r.filesWithoutMatch){let v=r.nullSeparator?"\0":` +`;a+=`${x}${v}`}else r.includeZero&&(r.count||r.countMatches)&&(a+=A.output)}}r.json&&(c.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:f,bytes_searched:p,bytes_printed:0,matched_lines:u,matches:u}}})),a=`${c.join(` `)} `);let d=r.quiet&&!r.json?"":a;if(r.stats&&!r.json){let g=["",`${u} matches`,`${u} matched lines`,`${f} files contained matches`,`${t.length} files searched`,`${p} bytes searched`].join(` `);d+=`${g} -`}let m;return r.filesWithoutMatch?m=a.length>0?0:1:m=l?0:1,{stdout:d,stderr:"",exitCode:m}}var Tp=v(()=>{"use strict";ye();Rr();Ze();El();Cl();vp()});var Op={};ee(Op,{flagsForFuzzing:()=>T8,rgCommand:()=>$8});var I8,$8,T8,Rp=v(()=>{"use strict";oe();Cl();Cp();Tp();I8={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. +`}let m;return r.filesWithoutMatch?m=a.length>0?0:1:m=l?0:1,{stdout:d,stderr:"",exitCode:m}}var np=O(()=>{"use strict";ye();Ar();Ze();nl();il();X1()});var rp={};te(rp,{flagsForFuzzing:()=>L3,rgCommand:()=>F3});var _3,F3,L3,sp=O(()=>{"use strict";oe();il();Q1();np();_3={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern. Unlike grep, rg is recursive by default and respects .gitignore files. EXAMPLES: @@ -232,19 +234,19 @@ EXAMPLES: rg -t js foo Search only JavaScript files rg -g '*.ts' foo Search files matching glob rg --hidden foo Include hidden files - rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},$8={name:"rg",async execute(e,t){if(B(e))return U(I8);if(e.includes("--type-list"))return{stdout:wp(),stderr:"",exitCode:0};let n=Sp(e);return n.success?kp({ctx:t,options:n.options,paths:n.paths,explicitLineNumbers:n.explicitLineNumbers}):n.error}},T8={name:"rg",flags:[{flag:"-i",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-N",type:"boolean"},{flag:"--hidden",type:"boolean"},{flag:"--no-ignore",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-g",type:"value",valueHint:"pattern"},{flag:"-t",type:"value",valueHint:"string"},{flag:"-T",type:"value",valueHint:"string"}],needsArgs:!0}});function lt(e,t,n){if(!e||Et.isInSandboxedContext())return;let r=`${t} ${n} attempted outside defense context`;throw new me(r,{timestamp:Date.now(),type:"missing_defense_context",message:r,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Et.getCurrentExecutionId()})}async function _t(e,t,n,r){lt(e,t,`${n} (pre-await)`);let s=await r();return lt(e,t,`${n} (post-await)`),s}var Bn=v(()=>{"use strict";cn()});function Il(e){let t="",n=0,r=!1;for(;n