@noppu-labs/opencode-permission-reviewer 3.4.3 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,26 +1,26 @@
1
+ import { parse as parse$1, satisfies } from "semver";
1
2
  import { createHash, randomBytes, randomUUID } from "node:crypto";
2
- import { basename, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
3
- import { lstat, mkdir, mkdtemp, open, readlink, realpath, rm, stat, writeFile } from "node:fs/promises";
3
+ import { basename as basename$1, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
4
+ import { lstat, mkdir, mkdtemp, open as open$2, readlink, realpath, rm, stat, writeFile } from "node:fs/promises";
4
5
  import { execFile } from "node:child_process";
5
6
  import { promisify } from "node:util";
6
7
  import { closeSync, constants, fchmodSync, fstatSync, openSync, readSync, realpathSync, rmSync, writeSync } from "node:fs";
7
8
  import { homedir, tmpdir } from "node:os";
8
9
  import { TypeSafeClient } from "@typesafe-ai/sdk";
9
- import { satisfies } from "semver";
10
10
  import { z } from "zod";
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { Buffer as Buffer$1 } from "node:buffer";
13
13
  import { OpenCode } from "@opencode/client";
14
14
  // \0rolldown/runtime.js
15
15
  var __defProp = Object.defineProperty;
16
- var __exportAll = (all, no_symbols) => {
17
- let target = {};
16
+ var __exportAll = (all, flags) => {
17
+ let target = Object.setPrototypeOf({}, null);
18
18
  for (var name in all) __defProp(target, name, {
19
19
  get: all[name],
20
20
  enumerable: true
21
21
  });
22
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
23
- return target;
22
+ if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
23
+ return flags & 2 ? target : Object.preventExtensions(target);
24
24
  };
25
25
  // src/utils/is-record.ts
26
26
  /** A non-null object that is not an array. */
@@ -76,6 +76,37 @@ function extractPermissionRequest(event) {
76
76
  ...tool === void 0 ? {} : { tool }
77
77
  };
78
78
  }
79
+ // src/adapters/opencode/host-guard.ts
80
+ /**
81
+ * OpenCode V2 host versions accepted at setup. A host outside this range
82
+ * fails setup loudly instead of running against an unknown contract.
83
+ */
84
+ const SUPPORTED_V2_RANGE = ">=2.0.22 <3";
85
+ /**
86
+ * Guard the legacy adapter against incompatible client shapes.
87
+ *
88
+ * A client exposing only permission.reply does not satisfy the legacy
89
+ * transport contract. Product V2 uses its own setup entrypoint and adapter.
90
+ */
91
+ function assertV1Host(client) {
92
+ const record = client ?? {};
93
+ const permission = record.permission ?? {};
94
+ const raw = record._client ?? {};
95
+ if (typeof permission.reply === "function" && typeof raw.post !== "function") throw new Error("The V1 adapter requires the authenticated legacy transport. Use the setup entrypoint for OpenCode V2; refusing this incompatible client.");
96
+ }
97
+ /**
98
+ * Why the V1 entrypoint must refuse a host that reports a V2 version, or
99
+ * undefined when the version is V1 or unknown.
100
+ *
101
+ * The V1 reviewer isolates its sessions with a single-file local plugin, and
102
+ * V2 skips plugin paths that name a file. Every review would then fail closed
103
+ * with no visible cause, so the plugin fails at load and says how to fix it.
104
+ */
105
+ function v1HostVersionRefusal(version) {
106
+ const parsed = version === void 0 ? null : parse$1(version);
107
+ if (parsed === null || parsed.major < 2) return;
108
+ return `OpenCode ${parsed.version} loaded the V1 entrypoint of opencode-permission-reviewer, whose reviewer isolation V2 does not load. Register the plugin under the V2 "plugins" key (see "Configure" in the README) so the host uses its setup entrypoint.`;
109
+ }
79
110
  // src/utils/with-timeout.ts
80
111
  function withTimeout(promise, timeoutMs) {
81
112
  let timer;
@@ -108,7 +139,7 @@ function invariant(condition, message) {
108
139
  if (!condition) throw new Error(message);
109
140
  }
110
141
  // package.json
111
- var version = "3.4.3";
142
+ var version = "3.6.0";
112
143
  // src/utils/redact.ts
113
144
  const REDACT = (type) => `[REDACTED:${type}]`;
114
145
  const OPENCODE_SESSION_KEY = /^(?:session[_-]?id|session|sid)$/i;
@@ -917,6 +948,9 @@ const OPENROUTER_DECISION_MODELS = {
917
948
  "cloudflare/clef": { benchmarked: false },
918
949
  "cloudflare/clef-flash": { benchmarked: false },
919
950
  "cloudflare/clef-omni": { benchmarked: false },
951
+ "google/gemini-decision-1": { benchmarked: false },
952
+ "heygen/heygen-decision-1": { benchmarked: false },
953
+ "heygen/heygen-decision-1-turbo": { benchmarked: false },
920
954
  "jaredpalmer/kev-4b": { benchmarked: false },
921
955
  "liquid/d1": { benchmarked: true },
922
956
  "liquid/d1-ultra": { benchmarked: true },
@@ -924,12 +958,15 @@ const OPENROUTER_DECISION_MODELS = {
924
958
  "microsoft/microsoft-decision-1": { benchmarked: false },
925
959
  "morph/reflex": { benchmarked: false },
926
960
  "nace-ai/drex-max": { benchmarked: false },
961
+ "nace-ai/drex-max-finance": { benchmarked: false },
927
962
  "nace-ai/drex-v1.5": { benchmarked: false },
928
963
  "nace-ai/drex-v2.0": { benchmarked: false },
929
964
  "openai/gpt-6-luna-decisions": { benchmarked: false },
930
- "parallel/decisions-fast:free": { benchmarked: false },
965
+ "parallel/decisions-fast": { benchmarked: false },
931
966
  "perplexity/pplx-decider-flash-v1.2": { benchmarked: false },
967
+ "perplexity/pplx-decider-flash-v1.3:free": { benchmarked: false },
932
968
  "perplexity/pplx-decider-v1.2": { benchmarked: false },
969
+ "perplexity/pplx-decider-v1.3:free": { benchmarked: false },
933
970
  "respan/span-02": { benchmarked: false },
934
971
  "togethercomputer/tev1-4b-experimental": { benchmarked: false },
935
972
  "typesafe/jev-1.13": { benchmarked: true },
@@ -1627,12 +1664,127 @@ function splitTokens(tokens, split) {
1627
1664
  tokenIndex += 1;
1628
1665
  }
1629
1666
  }
1667
+ // src/modules/analysis/capability/heredoc/ansi-c-numeric.ts
1668
+ const HEX_DIGITS = /* @__PURE__ */ new Map([
1669
+ ["x", /[0-9a-f]{1,2}/iy],
1670
+ ["u", /[0-9a-f]{1,4}/iy],
1671
+ ["U", /[0-9a-f]{1,8}/iy]
1672
+ ]);
1673
+ const OCTAL_DIGITS = /[0-7]{1,3}/y;
1674
+ /** The octal escape at `index`, whose first digit is at `index + 1`. */
1675
+ function decodeAnsiCOctal(inner, index) {
1676
+ const digits = digitsAt(inner, index + 1, OCTAL_DIGITS);
1677
+ return {
1678
+ text: String.fromCharCode(Number.parseInt(digits, 8) & 255),
1679
+ end: index + 1 + digits.length
1680
+ };
1681
+ }
1682
+ /** The `\x`, `\u` or `\U` escape at `index`; undefined for another letter or
1683
+ * without a hex digit. */
1684
+ function decodeAnsiCHex(inner, index, letter) {
1685
+ const pattern = HEX_DIGITS.get(letter);
1686
+ if (pattern === void 0) return void 0;
1687
+ const digits = digitsAt(inner, index + 2, pattern);
1688
+ if (digits === "") return void 0;
1689
+ const end = index + 2 + digits.length;
1690
+ const value = Number.parseInt(digits, 16);
1691
+ if (letter === "x") return {
1692
+ text: String.fromCharCode(value),
1693
+ end
1694
+ };
1695
+ return {
1696
+ text: codePointText(value),
1697
+ end
1698
+ };
1699
+ }
1700
+ /** The text bash gives a `\u` or `\U` code point. Values above 0x7fffffff
1701
+ * are dropped; surrogates and values past U+10FFFF are not JavaScript code
1702
+ * points and become U+FFFD. */
1703
+ function codePointText(value) {
1704
+ if (value > 2147483647) return "";
1705
+ if (value >= 55296 && value <= 57343 || value > 1114111) return "�";
1706
+ return String.fromCodePoint(value);
1707
+ }
1708
+ /** `\cX` is the control character of X. In bash 4.4 and later `\c?` is DEL and
1709
+ * `\c\\` takes both backslashes; bash 3.2 reads each like any other X. */
1710
+ function decodeAnsiCControl(inner, index, dialect) {
1711
+ const target = inner.charAt(index + 2);
1712
+ if (target === "") return {
1713
+ text: "\\c",
1714
+ end: index + 2
1715
+ };
1716
+ const modern = dialect === "bash";
1717
+ if (target === "\\" && modern) return {
1718
+ text: "",
1719
+ end: inner.charAt(index + 3) === "\\" ? index + 4 : index + 3
1720
+ };
1721
+ const code = target === "?" && modern ? 127 : target.charCodeAt(0) & 31;
1722
+ return {
1723
+ text: String.fromCharCode(code),
1724
+ end: index + 3
1725
+ };
1726
+ }
1727
+ /** The digits matched by the sticky `pattern` at `start`. */
1728
+ function digitsAt(text, start, pattern) {
1729
+ pattern.lastIndex = start;
1730
+ return pattern.exec(text)?.[0] ?? "";
1731
+ }
1732
+ // src/modules/analysis/capability/heredoc/ansi-c-zsh.ts
1733
+ /** `\C` clears bits 5 and 6 (`?` becomes DEL); `\M` sets bit 7. */
1734
+ const MODIFIERS = {
1735
+ C: (code) => code === 63 ? 127 : code & 159,
1736
+ M: (code) => code | 128
1737
+ };
1738
+ /** An escape zsh reads without a backslash: `\x`, `\u` and `\U` without a
1739
+ * hex digit are NUL, a run of `\C[-]` and `\M[-]` modifies the first
1740
+ * character of the escape or character after it (innermost first, nothing
1741
+ * at the end of the text), and anything else (`\cX` included) is the
1742
+ * character itself. `decodeEscape` decodes the escape at an index. */
1743
+ function decodeZshOther(inner, index, escaped, decodeEscape) {
1744
+ if (/^[xuU]$/.test(escaped)) return {
1745
+ text: "\0",
1746
+ end: index + 2
1747
+ };
1748
+ if (MODIFIERS[escaped] === void 0) return {
1749
+ text: escaped,
1750
+ end: index + 2
1751
+ };
1752
+ const modifiers = [];
1753
+ let position = index;
1754
+ let modify = MODIFIERS[inner.charAt(position + 1)];
1755
+ while (inner.charAt(position) === "\\" && modify !== void 0) {
1756
+ modifiers.push(modify);
1757
+ position += inner.charAt(position + 2) === "-" ? 3 : 2;
1758
+ modify = MODIFIERS[inner.charAt(position + 1)];
1759
+ }
1760
+ const operand = operandAt(inner, position, decodeEscape);
1761
+ if (operand.text === "") return operand;
1762
+ let code = operand.text.charCodeAt(0);
1763
+ for (const apply of modifiers.reverse()) code = apply(code);
1764
+ return {
1765
+ text: String.fromCharCode(code) + operand.text.slice(1),
1766
+ end: operand.end
1767
+ };
1768
+ }
1769
+ /** The escape or character a modifier run applies to. */
1770
+ function operandAt(inner, position, decodeEscape) {
1771
+ if (position >= inner.length) return {
1772
+ text: "",
1773
+ end: position
1774
+ };
1775
+ if (inner.charAt(position) === "\\" && position + 1 < inner.length) return decodeEscape(inner, position);
1776
+ return {
1777
+ text: inner.charAt(position),
1778
+ end: position + 1
1779
+ };
1780
+ }
1630
1781
  // src/modules/analysis/capability/heredoc/ansi-c-quoting.ts
1631
- /** Unescape an ANSI-C quoted region (`$'...'`), the subset bash defines for
1632
- * here-document delimiter words: standard escapes, `\xHH` hex, and up to
1633
- * three octal digits. Unknown escapes drop the backslash, like bash. A
1634
- * delimiter containing a newline can never match a body line; it stays
1635
- * resolved and the body scan reports the heredoc as unterminated. */
1782
+ /** Unescape the `$'...'` region of a here-document delimiter word. Unknown
1783
+ * escapes drop the backslash as zsh does, so the text is right for every
1784
+ * shell only when `ansiCShellDependent` accepts the part; `scanDollarQuoted`
1785
+ * marks the word unresolved otherwise. A delimiter containing a newline can
1786
+ * never match a body line; it stays resolved and the body scan reports the
1787
+ * heredoc as unterminated. */
1636
1788
  function unescapeAnsiC(command, start) {
1637
1789
  let text = "";
1638
1790
  let index = start;
@@ -1702,10 +1854,37 @@ function ansiCEscape(command, index, escaped) {
1702
1854
  end: index + 2
1703
1855
  };
1704
1856
  }
1705
- /** The value bash gives a `$'...'` word whose text between the quotes is
1706
- * `inner`, as written: escapes decoded, cut at the first NUL. Unknown
1707
- * escapes and a bare `\x`, `\u` or `\U` keep their backslash. */
1708
- function decodeAnsiCWord(inner) {
1857
+ /** Whether an escape in `inner` (the text between `$'` and the closing `'`, as
1858
+ * written) is read differently by bash, bash 3.2 and zsh: anything but a
1859
+ * simple escape, an octal escape, or `\x` with a hex digit. `\c`, `\u` and
1860
+ * `\U` always count, and so does a NUL with text after it, where bash ends
1861
+ * the word and zsh keeps the rest. A NUL that ends the word gives the same
1862
+ * argument in both; a heredoc delimiter checks for one itself. */
1863
+ function ansiCShellDependent(inner) {
1864
+ let index = 0;
1865
+ while (index < inner.length) {
1866
+ if (inner.charAt(index) !== "\\") {
1867
+ index += 1;
1868
+ continue;
1869
+ }
1870
+ const bash = decodeAnsiCEscape(inner, index, "bash");
1871
+ if (textAfterNul(bash.text, inner.slice(bash.end)) || bash.text !== decodeAnsiCEscape(inner, index, "zsh").text || bash.text !== decodeAnsiCEscape(inner, index, "bash32").text) return true;
1872
+ index = bash.end;
1873
+ }
1874
+ return false;
1875
+ }
1876
+ /** Whether an escape's `text` has a NUL with more text after it, in the
1877
+ * escape or in the `rest` of the word. */
1878
+ function textAfterNul(text, rest) {
1879
+ const nul = text.indexOf("\0");
1880
+ return nul !== -1 && (nul < text.length - 1 || rest !== "");
1881
+ }
1882
+ /** The value a `$'...'` word whose text between the quotes is `inner`, as
1883
+ * written, has in `dialect` as a command's argument: escapes decoded, cut
1884
+ * at the first NUL. In bash, unknown escapes and a bare `\x`, `\u` or `\U`
1885
+ * keep their backslash, and bash 3.2 also keeps it for every `\u` and
1886
+ * `\U`. */
1887
+ function decodeAnsiCWord(inner, dialect = "bash") {
1709
1888
  let value = "";
1710
1889
  let index = 0;
1711
1890
  while (index < inner.length) {
@@ -1714,101 +1893,51 @@ function decodeAnsiCWord(inner) {
1714
1893
  index += 1;
1715
1894
  continue;
1716
1895
  }
1717
- const decoded = decodeAnsiCEscape(inner, index);
1896
+ const decoded = decodeAnsiCEscape(inner, index, dialect);
1718
1897
  value += decoded.text;
1719
1898
  index = decoded.end;
1720
1899
  }
1721
- const nul = value.indexOf("\0");
1722
- return nul === -1 ? value : value.slice(0, nul);
1900
+ return value.split("\0", 1).join("");
1723
1901
  }
1724
- const HEX_DIGITS = /* @__PURE__ */ new Map([
1725
- ["x", /[0-9a-f]{1,2}/iy],
1726
- ["u", /[0-9a-f]{1,4}/iy],
1727
- ["U", /[0-9a-f]{1,8}/iy]
1728
- ]);
1729
- const OCTAL_DIGITS = /[0-7]{1,3}/y;
1730
1902
  /** The decoded escape whose backslash is at `index`, and the index just past it. */
1731
- function decodeAnsiCEscape(inner, index) {
1903
+ function decodeAnsiCEscape(inner, index, dialect) {
1732
1904
  const escaped = inner.charAt(index + 1);
1733
1905
  const simple = ANSI_C_SIMPLE_ESCAPES[escaped];
1734
1906
  if (simple !== void 0) return {
1735
1907
  text: simple,
1736
1908
  end: index + 2
1737
1909
  };
1738
- if (/^[0-7]$/.test(escaped)) {
1739
- const digits = digitsAt(inner, index + 1, OCTAL_DIGITS);
1740
- const value = Number.parseInt(digits, 8) & 255;
1741
- return {
1742
- text: String.fromCharCode(value),
1743
- end: index + 1 + digits.length
1744
- };
1745
- }
1746
- if (escaped === "c") return decodeAnsiCControl(inner, index);
1747
- const hex = HEX_DIGITS.get(escaped);
1748
- if (hex !== void 0) return decodeAnsiCHex(inner, index, escaped, hex);
1910
+ if (/^[0-7]$/.test(escaped)) return decodeAnsiCOctal(inner, index);
1911
+ if (escaped === "c" && dialect !== "zsh") return decodeAnsiCControl(inner, index, dialect);
1912
+ const decoded = (dialect !== "bash32" || escaped === "x") && decodeAnsiCHex(inner, index, escaped);
1913
+ if (decoded) return decoded;
1914
+ if (dialect === "zsh") return decodeZshOther(inner, index, escaped, (text, at) => decodeAnsiCEscape(text, at, "zsh"));
1749
1915
  return {
1750
1916
  text: `\\${escaped}`,
1751
1917
  end: index + 2
1752
1918
  };
1753
1919
  }
1754
- function decodeAnsiCHex(inner, index, letter, pattern) {
1755
- const digits = digitsAt(inner, index + 2, pattern);
1756
- if (digits === "") return {
1757
- text: `\\${letter}`,
1758
- end: index + 2
1759
- };
1760
- const end = index + 2 + digits.length;
1761
- const value = Number.parseInt(digits, 16);
1762
- if (letter === "x") return {
1763
- text: String.fromCharCode(value),
1764
- end
1765
- };
1766
- return {
1767
- text: codePointText(value),
1768
- end
1769
- };
1770
- }
1771
- /** The text bash gives a `\u` or `\U` code point. Values above 0x7fffffff
1772
- * are dropped; surrogates and values past U+10FFFF are not JavaScript code
1773
- * points and become U+FFFD. */
1774
- function codePointText(value) {
1775
- if (value > 2147483647) return "";
1776
- if (value >= 55296 && value <= 57343 || value > 1114111) return "�";
1777
- return String.fromCodePoint(value);
1778
- }
1779
- /** `\cX` is the control character of X, `\c?` is DEL, and `\c\\` is the
1780
- * control character of a backslash. */
1781
- function decodeAnsiCControl(inner, index) {
1782
- const target = inner.charAt(index + 2);
1783
- if (target === "") return {
1784
- text: "\\c",
1785
- end: index + 2
1786
- };
1787
- if (target === "\\") return {
1788
- text: "",
1789
- end: inner.charAt(index + 3) === "\\" ? index + 4 : index + 3
1790
- };
1791
- const code = target === "?" ? 127 : target.charCodeAt(0) & 31;
1792
- return {
1793
- text: String.fromCharCode(code),
1794
- end: index + 3
1795
- };
1920
+ // src/modules/analysis/shell/shell-lex-state.ts
1921
+ /** Whether the reading is `finder` with only a `$'…'` word's value changed. */
1922
+ function readsAsFinder(quoting = "bash") {
1923
+ return quoting === "finder" || quoting === "zsh" || quoting === "bash32";
1796
1924
  }
1797
- /** The digits matched by the sticky `pattern` at `start`. */
1798
- function digitsAt(text, start, pattern) {
1799
- pattern.lastIndex = start;
1800
- return pattern.exec(text)?.[0] ?? "";
1925
+ /** The dialect a reading decodes a `$'…'` word in. */
1926
+ function ansiCDialectOf(quoting = "bash") {
1927
+ return quoting === "zsh" || quoting === "bash32" ? quoting : "bash";
1801
1928
  }
1802
- // src/modules/analysis/shell/shell-lex-state.ts
1803
- /** Whether the reading decodes quotes the way bash does. */
1929
+ /** Whether the reading has bash's quote structure: `$'…'` strings and the
1930
+ * quote spans that follow from it. The readings that read as `finder` does
1931
+ * differ from `bash` only in how an escape decodes. */
1804
1932
  function readsBashQuotes(quoting = "bash") {
1805
- return quoting === "bash" || quoting === "rescan" || quoting === "finder";
1933
+ return quoting === "bash" || quoting === "rescan" || readsAsFinder(quoting);
1806
1934
  }
1807
- /** The substitution scan a reading uses. Only `bash` and `finder` end a body
1808
- * where the shell does, and their outer scan then jumps past the body; every
1809
- * other reading ends it where the previous release did and walks it again. */
1935
+ /** The substitution scan a reading uses. Only `bash` and the readings that
1936
+ * read as `finder` does end a body where the shell does, and their outer
1937
+ * scan then jumps past the body; every other reading ends it where the
1938
+ * previous release did and walks it again. */
1810
1939
  function substitutionScanOf(quoting = "bash") {
1811
- return quoting === "bash" || quoting === "finder" ? "bash" : "previous";
1940
+ return quoting === "bash" || readsAsFinder(quoting) ? "bash" : "previous";
1812
1941
  }
1813
1942
  /** Ceiling on the substitution text one scan re-lexes by default: nested
1814
1943
  * substitutions re-lex their body once per level. */
@@ -1860,7 +1989,7 @@ function lastValueChar(lex) {
1860
1989
  * joins the value as quoted text. Nothing was collected under the
1861
1990
  * `undecoded` reading, which appends the text as it scans. */
1862
1991
  function closeAnsiC(lex) {
1863
- appendValue(lex, decodeAnsiCWord(lex.ansiCText), true);
1992
+ appendValue(lex, decodeAnsiCWord(lex.ansiCText, ansiCDialectOf(lex.budget.quoting)), true);
1864
1993
  lex.ansiCText = "";
1865
1994
  lex.ansiC = false;
1866
1995
  }
@@ -2273,6 +2402,7 @@ function consumeBodies(scan, bodyStart, lineEnd) {
2273
2402
  const read = readBody(scan.command, position, start, bound);
2274
2403
  position = read.position;
2275
2404
  if (read.unterminated) scan.unterminated = true;
2405
+ noteDelimiter(scan, start);
2276
2406
  const record = bodyRecord(scan.command, start, read, lineEnd, targets);
2277
2407
  if (record.dynamic) scan.hasDynamicConstructs = true;
2278
2408
  keepBody(scan.bodies, start, read, record.sha256);
@@ -2284,6 +2414,10 @@ function consumeBodies(scan, bodyStart, lineEnd) {
2284
2414
  scan.pieces = [];
2285
2415
  return position;
2286
2416
  }
2417
+ function noteDelimiter(scan, start) {
2418
+ if (!start.resolved) scan.delimiterUnresolved = true;
2419
+ if (start.shellDependent) scan.delimiterShellDependent = true;
2420
+ }
2287
2421
  /** Keeps what one read body gives the collector: the commands its
2288
2422
  * substitutions run, when its delimiter is unquoted, and the text the command
2289
2423
  * that reads it gets, when it has its terminator line. */
@@ -2337,8 +2471,10 @@ function scanSingleQuoted(command, scan) {
2337
2471
  scan.index = end + 1;
2338
2472
  return true;
2339
2473
  }
2340
- /** `$'...'` is unescaped here; for `$"..."` only the `$` is consumed, and
2341
- * the double-quoted part follows. */
2474
+ /** `$'...'` is unescaped here. A part with an escape the shells read
2475
+ * differently, or with a NUL (bash ends the delimiter there, zsh keeps it),
2476
+ * leaves the word unresolved and shell-dependent. For `$"..."` only the `$`
2477
+ * is consumed, and the double-quoted part follows. */
2342
2478
  function scanDollarQuoted(command, scan) {
2343
2479
  scan.quoted = true;
2344
2480
  scan.sawAny = true;
@@ -2351,6 +2487,10 @@ function scanDollarQuoted(command, scan) {
2351
2487
  scan.resolved = false;
2352
2488
  return false;
2353
2489
  }
2490
+ if (ansiCShellDependent(command.slice(scan.index + 2, parsed.end - 1)) || parsed.text.includes("\0")) {
2491
+ scan.resolved = false;
2492
+ scan.shellDependent = true;
2493
+ }
2354
2494
  scan.delimiter += parsed.text;
2355
2495
  scan.index = parsed.end;
2356
2496
  return true;
@@ -2422,14 +2562,16 @@ const BARE_WORD_STOP = /* @__PURE__ */ new Set([
2422
2562
  * inside a backtick substitution, which the shell cuts out before it reads
2423
2563
  * the operator's word. A bare carriage return ends the word when
2424
2564
  * `stopAtCarriageReturn` is set, as the previous release read it.
2425
- * The word is `resolved: false` only when its quoting never terminates or
2426
- * the word is empty: then no line can be proven to be the terminator. */
2565
+ * The word is `resolved: false` when its quoting never terminates, the word
2566
+ * is empty, or a `$'...'` part is shell-dependent: then no line can be
2567
+ * proven to be the terminator. */
2427
2568
  function parseDelimiterWord(command, start, options = {}) {
2428
2569
  const scan = {
2429
2570
  index: start,
2430
2571
  delimiter: "",
2431
2572
  quoted: false,
2432
2573
  resolved: true,
2574
+ shellDependent: false,
2433
2575
  sawAny: false
2434
2576
  };
2435
2577
  while (scan.index < command.length) {
@@ -2442,13 +2584,15 @@ function parseDelimiterWord(command, start, options = {}) {
2442
2584
  wordEnd: start,
2443
2585
  delimiter: "",
2444
2586
  quoted: false,
2445
- resolved: false
2587
+ resolved: false,
2588
+ shellDependent: false
2446
2589
  };
2447
2590
  return {
2448
2591
  wordEnd: scan.index,
2449
2592
  delimiter: scan.delimiter,
2450
2593
  quoted: scan.quoted,
2451
- resolved: scan.resolved
2594
+ resolved: scan.resolved,
2595
+ shellDependent: scan.shellDependent
2452
2596
  };
2453
2597
  }
2454
2598
  /** Consume the word part at `scan.index`. Returns false when the word ends
@@ -2858,6 +3002,7 @@ function scanHeredocOperator(scan) {
2858
3002
  rawWord: command.slice(j, word.wordEnd),
2859
3003
  quoted: word.quoted,
2860
3004
  resolved: word.resolved,
3005
+ shellDependent: word.shellDependent,
2861
3006
  opStart: i,
2862
3007
  wordEnd: word.wordEnd,
2863
3008
  lineStart: scan.lineStart,
@@ -2878,6 +3023,8 @@ function legacySanitizedCommand(command) {
2878
3023
  hasDynamicConstructs: false,
2879
3024
  unterminated: false,
2880
3025
  framed: false,
3026
+ delimiterUnresolved: false,
3027
+ delimiterShellDependent: false,
2881
3028
  out: "",
2882
3029
  cursor: 0,
2883
3030
  i: 0,
@@ -2953,6 +3100,8 @@ function extractHeredocs(command, options = {}) {
2953
3100
  hasDynamicConstructs: false,
2954
3101
  unterminated: false,
2955
3102
  framed: false,
3103
+ delimiterUnresolved: false,
3104
+ delimiterShellDependent: false,
2956
3105
  out: "",
2957
3106
  cursor: 0,
2958
3107
  i: 0,
@@ -2975,6 +3124,8 @@ function extractHeredocs(command, options = {}) {
2975
3124
  return {
2976
3125
  unterminated: scan.unterminated,
2977
3126
  framed: scan.framed,
3127
+ delimiterUnresolved: scan.delimiterUnresolved,
3128
+ delimiterShellDependent: scan.delimiterShellDependent,
2978
3129
  sanitizedCommand: scan.out,
2979
3130
  heredocs: scan.heredocs,
2980
3131
  hasDynamicConstructs: scan.hasDynamicConstructs,
@@ -2987,6 +3138,8 @@ function unchanged(command) {
2987
3138
  return {
2988
3139
  unterminated: false,
2989
3140
  framed: false,
3141
+ delimiterUnresolved: false,
3142
+ delimiterShellDependent: false,
2990
3143
  sanitizedCommand: command,
2991
3144
  heredocs: [],
2992
3145
  hasDynamicConstructs: false,
@@ -3026,7 +3179,8 @@ function sanitizedText(text) {
3026
3179
  return {
3027
3180
  text: extraction.sanitizedCommand,
3028
3181
  bodyCommands: extraction.bodyCommands,
3029
- bodyUnresolved: extraction.bodyUnresolved,
3182
+ bodyUnresolved: extraction.bodyUnresolved || extraction.delimiterUnresolved,
3183
+ delimiterShellDependent: extraction.delimiterShellDependent,
3030
3184
  scripts: extraction.scripts
3031
3185
  };
3032
3186
  }
@@ -3377,7 +3531,7 @@ function advance(scan) {
3377
3531
  scan.index += 1;
3378
3532
  return false;
3379
3533
  }
3380
- function open$2(scan, frame, width) {
3534
+ function open$1(scan, frame, width) {
3381
3535
  scan.frames.push(frame);
3382
3536
  scan.starts.push(scan.index);
3383
3537
  scan.prefix = void 0;
@@ -3401,8 +3555,8 @@ function close$1(scan) {
3401
3555
  }
3402
3556
  function stepCommand(scan, c, insideCase) {
3403
3557
  if (c === ")" || c === "(") return stepParenthesis(scan, c, insideCase);
3404
- if (c === "\"") return open$2(scan, "double", 1);
3405
- if (c === "`") return open$2(scan, "backtick", 1);
3558
+ if (c === "\"") return open$1(scan, "double", 1);
3559
+ if (c === "`") return open$1(scan, "backtick", 1);
3406
3560
  if (c === "'" || c === "$" && scan.text[scan.index + 1] === "'") {
3407
3561
  skipSingleQuoted(scan, c === "$");
3408
3562
  return false;
@@ -3427,7 +3581,7 @@ function stepParenthesis(scan, c, insideCase) {
3427
3581
  /** A `(` opens a subshell, unless it is the `()` of a function header. */
3428
3582
  function openParenthesis(scan) {
3429
3583
  const end = scan.mode === "bash" ? functionHeaderEnd(scan) : -1;
3430
- if (end < 0) return open$2(scan, "command", 1);
3584
+ if (end < 0) return open$1(scan, "command", 1);
3431
3585
  scan.index = end;
3432
3586
  scan.headStart = -1;
3433
3587
  scan.commandPosition = true;
@@ -3436,7 +3590,7 @@ function openParenthesis(scan) {
3436
3590
  /** `${` opens an expansion that holds a `)` as text; `$$` is one parameter. */
3437
3591
  function stepDollar$2(scan) {
3438
3592
  const next = scan.text[scan.index + 1];
3439
- if (next === "{") return open$2(scan, "brace", 2);
3593
+ if (next === "{") return open$1(scan, "brace", 2);
3440
3594
  scan.commandPosition = false;
3441
3595
  scan.index += next === "$" ? 2 : 1;
3442
3596
  return false;
@@ -3461,8 +3615,8 @@ function stepBrace$1(scan, c) {
3461
3615
  /** It ends at `closer`; substitutions inside open frames of their own. */
3462
3616
  function stepQuoted$1(scan, c, closer, singleQuotes) {
3463
3617
  if (c === closer) return close$1(scan);
3464
- if (c === "\"") return open$2(scan, "double", 1);
3465
- if (c === "`") return open$2(scan, "backtick", 1);
3618
+ if (c === "\"") return open$1(scan, "double", 1);
3619
+ if (c === "`") return open$1(scan, "backtick", 1);
3466
3620
  if (c === "'" && singleQuotes) return skip(scan, false);
3467
3621
  return c === "$" ? stepDollar$1(scan, singleQuotes) : advance(scan);
3468
3622
  }
@@ -3471,11 +3625,11 @@ function stepQuoted$1(scan, c, closer, singleQuotes) {
3471
3625
  function stepDollar$1(scan, singleQuotes) {
3472
3626
  const next = scan.text[scan.index + 1];
3473
3627
  if (next !== "(") return stepParameter(scan, next, singleQuotes);
3474
- return open$2(scan, scan.mode === "bash" && scan.text[scan.index + 2] === "(" ? "arith" : "command", 2);
3628
+ return open$1(scan, scan.mode === "bash" && scan.text[scan.index + 2] === "(" ? "arith" : "command", 2);
3475
3629
  }
3476
3630
  function stepParameter(scan, next, singleQuotes) {
3477
3631
  if (scan.mode !== "bash") return advance(scan);
3478
- if (next === "{") return open$2(scan, "brace", 2);
3632
+ if (next === "{") return open$1(scan, "brace", 2);
3479
3633
  if (next === "$") scan.index += 1;
3480
3634
  else if (next === "'" && singleQuotes) return skip(scan, true);
3481
3635
  return advance(scan);
@@ -3755,14 +3909,14 @@ function openGroup(scan, c) {
3755
3909
  if (!scan.commandPosition && !dollar && scan.words !== "forName") return void 0;
3756
3910
  if (!dollar && !closesAsArithmetic(text, index, scan.probes)) return void 0;
3757
3911
  const forLoop = scan.words === "forName";
3758
- open$2(scan, "arith", 1);
3759
- open$2(scan, "arith", 1);
3912
+ open$1(scan, "arith", 1);
3913
+ open$1(scan, "arith", 1);
3760
3914
  scan.commandPosition = false;
3761
3915
  if (forLoop) scan.saved[scan.saved.length - 2] = ["forAfterName", void 0];
3762
3916
  return false;
3763
3917
  }
3764
3918
  function openArray(scan) {
3765
- open$2(scan, "array", 1);
3919
+ open$1(scan, "array", 1);
3766
3920
  scan.commandPosition = false;
3767
3921
  return false;
3768
3922
  }
@@ -3770,7 +3924,7 @@ function openTest(scan) {
3770
3924
  const { text, index } = scan;
3771
3925
  if (!scan.commandPosition || !text.startsWith("[[", index)) return void 0;
3772
3926
  if (!/\s/.test(text.charAt(index + 2))) return void 0;
3773
- open$2(scan, "test", 2);
3927
+ open$1(scan, "test", 2);
3774
3928
  scan.commandPosition = false;
3775
3929
  return false;
3776
3930
  }
@@ -3784,7 +3938,7 @@ function stepArith(scan, c) {
3784
3938
  const group = c === "(" ? openGroup(scan, c) : void 0;
3785
3939
  if (group !== void 0) return group;
3786
3940
  if (c === "(" && scan.text[scan.index - 1] !== "$") {
3787
- open$2(scan, "arith", 1);
3941
+ open$1(scan, "arith", 1);
3788
3942
  scan.commandPosition = false;
3789
3943
  return false;
3790
3944
  }
@@ -3857,12 +4011,12 @@ function substitutionBodyEnd(text, start, opener, reading = "default", mode = "b
3857
4011
  escapedEnd: -1,
3858
4012
  probes
3859
4013
  };
3860
- while (scan.index < text.length) if (step$1(scan)) return scan.index;
4014
+ while (scan.index < text.length) if (step$2(scan)) return scan.index;
3861
4015
  return text.length;
3862
4016
  }
3863
4017
  /** Advance past one character or construct; true once the opener's frame
3864
4018
  * closes at `scan.index`. */
3865
- function step$1(scan) {
4019
+ function step$2(scan) {
3866
4020
  const c = scan.text.charAt(scan.index);
3867
4021
  if (c === "\\") {
3868
4022
  const joins = scan.mode === "bash" && scan.text[scan.index + 1] === "\n";
@@ -3934,6 +4088,7 @@ function commandBody(text, end, reading, sanitize) {
3934
4088
  text: sanitize ? legacySanitizedCommand(text) : text,
3935
4089
  bodyCommands: [],
3936
4090
  bodyUnresolved: false,
4091
+ delimiterShellDependent: false,
3937
4092
  scripts: NO_SCRIPTS,
3938
4093
  end
3939
4094
  };
@@ -3943,6 +4098,7 @@ function commandBody(text, end, reading, sanitize) {
3943
4098
  text: read.text,
3944
4099
  bodyCommands: read.bodyCommands,
3945
4100
  bodyUnresolved: read.bodyUnresolved,
4101
+ delimiterShellDependent: read.delimiterShellDependent,
3946
4102
  scripts: read.scripts,
3947
4103
  end
3948
4104
  };
@@ -4033,10 +4189,10 @@ function stepFrame(scan, index) {
4033
4189
  * every other character plain. */
4034
4190
  function stepCount(scan, index) {
4035
4191
  const c = scan.text.charAt(index);
4036
- if (c === "(") return open$1(scan, "count", index + 1);
4192
+ if (c === "(") return open(scan, "count", index + 1);
4037
4193
  if (c === ")") return close(scan, index);
4038
4194
  if (c === "\\") return index + 2;
4039
- if (c === "\"") return open$1(scan, "double", index + 1);
4195
+ if (c === "\"") return open(scan, "double", index + 1);
4040
4196
  if (c !== "'") return index + 1;
4041
4197
  const end = scan.text.indexOf("'", index + 1);
4042
4198
  return end < 0 ? -1 : end + 1;
@@ -4054,7 +4210,7 @@ function stepParen(scan, index) {
4054
4210
  return index + 1;
4055
4211
  }
4056
4212
  if (c === "\\" || c === "") return index + 2;
4057
- if (c === "(" || c === "$" && text.charAt(index + 1) === "(") return open$1(scan, "paren", index + (c === "(" ? 1 : 2));
4213
+ if (c === "(" || c === "$" && text.charAt(index + 1) === "(") return open(scan, "paren", index + (c === "(" ? 1 : 2));
4058
4214
  if (c === ")") return close(scan, index);
4059
4215
  return stepQuoted(scan, index);
4060
4216
  }
@@ -4075,7 +4231,7 @@ function stepBrace(scan, index) {
4075
4231
  function stepQuoted(scan, index) {
4076
4232
  const c = scan.text.charAt(index);
4077
4233
  if (c === "`") return pastBacktick(scan.text, index);
4078
- if (c === "\"") return open$1(scan, "double", index + 1);
4234
+ if (c === "\"") return open(scan, "double", index + 1);
4079
4235
  if (c !== "'") return stepDollar(scan, index);
4080
4236
  const end = scan.text.indexOf("'", index + 1);
4081
4237
  return end < 0 ? -1 : end + 1;
@@ -4085,11 +4241,11 @@ function stepQuoted(scan, index) {
4085
4241
  function stepDollar(scan, index) {
4086
4242
  const next = scan.text.charAt(index + 1);
4087
4243
  if (scan.text.charAt(index) !== "$") return index + 1;
4088
- if (next === "(") return open$1(scan, "paren", index + 2);
4089
- if (next === "{" && scan.frames.at(-1) !== "paren") return open$1(scan, "brace", index + 2);
4244
+ if (next === "(") return open(scan, "paren", index + 2);
4245
+ if (next === "{" && scan.frames.at(-1) !== "paren") return open(scan, "brace", index + 2);
4090
4246
  return index + 1;
4091
4247
  }
4092
- function open$1(scan, frame, after) {
4248
+ function open(scan, frame, after) {
4093
4249
  scan.frames.push(frame);
4094
4250
  scan.starts.push(after);
4095
4251
  return after;
@@ -4317,7 +4473,7 @@ function scanBody(text) {
4317
4473
  ends: /* @__PURE__ */ new Map()
4318
4474
  };
4319
4475
  let index = 0;
4320
- while (index < text.length && !scan.unresolved) index = step(scan, index);
4476
+ while (index < text.length && !scan.unresolved) index = step$1(scan, index);
4321
4477
  if (scan.unresolved) return {
4322
4478
  commands: scan.commands,
4323
4479
  unresolved: true
@@ -4334,7 +4490,7 @@ function scanBody(text) {
4334
4490
  };
4335
4491
  }
4336
4492
  /** The index after the character or construct at `index`. */
4337
- function step(scan, index) {
4493
+ function step$1(scan, index) {
4338
4494
  const after = bodyTextStep(scan.text, index);
4339
4495
  return after < 0 ? substitute(scan, index) : after;
4340
4496
  }
@@ -4369,12 +4525,14 @@ function keepCommand(scan, found, backtick) {
4369
4525
  scan.unresolved ||= read.bodyUnresolved;
4370
4526
  }
4371
4527
  // src/modules/analysis/capability/heredoc/heredoc-body-collector.ts
4372
- /** Adds commands to `into`, with whether their bodies were unresolved. A
4373
- * collector that is not there is a reading that keeps none. */
4374
- function keepBodyCommands(into, commands, unresolved) {
4528
+ /** Adds commands to `into`, with whether their bodies were unresolved and
4529
+ * whether a delimiter of theirs was shell-dependent. A collector that is not
4530
+ * there is a reading that keeps none. */
4531
+ function keepBodyCommands(into, commands, unresolved, shellDependent = false) {
4375
4532
  if (into === void 0 || commands.length === 0 && !unresolved) return;
4376
4533
  for (const command of commands) into.commands.push(command);
4377
4534
  into.unresolved ||= unresolved;
4535
+ if (shellDependent) into.shellDependent = true;
4378
4536
  }
4379
4537
  /** Adds the commands of one unquoted body to `into`, with the scripts of the
4380
4538
  * heredocs in them. */
@@ -4422,7 +4580,7 @@ function uncertainRegion(lex, from, to) {
4422
4580
  if (pair < to && nextMark(marks, 2, pair, () => commentFrom(text, pair)) < to) return true;
4423
4581
  const open = nextMark(marks, 3, from, () => find(text, "$(", from));
4424
4582
  if (open < to && nextMark(marks, 4, open, () => closingComment(text, open)) < to) return true;
4425
- if (lex.budget.quoting === "finder") return false;
4583
+ if (readsAsFinder(lex.budget.quoting)) return false;
4426
4584
  if (nextMark(marks, 5, from, () => find(text, "<<", from)) >= to) return false;
4427
4585
  return nextMark(marks, 7, from, () => heredocGroupFrom(lex, from)) < to;
4428
4586
  }
@@ -4507,7 +4665,7 @@ function commentStart(text, at) {
4507
4665
  * the same budget, and keep the commands its heredocs run. */
4508
4666
  function lexBody(lex, budget, body) {
4509
4667
  const { text, end } = body;
4510
- keepBodyCommands(budget.bodies, body.bodyCommands, body.bodyUnresolved);
4668
+ keepBodyCommands(budget.bodies, body.bodyCommands, body.bodyUnresolved, body.delimiterShellDependent);
4511
4669
  keepBodyScripts(budget.bodies, body.scripts);
4512
4670
  lex.substitutionEnd = end;
4513
4671
  budget.substitutionCharsRemaining -= text.length;
@@ -4829,7 +4987,7 @@ function shellCommandSegmentsWithDirectory(command, initialDirectory) {
4829
4987
  ...tracker.directory === void 0 ? { directoryReason: tracker.directoryReason ?? "working directory is unresolved" } : { directory: tracker.directory }
4830
4988
  });
4831
4989
  const [head] = segment.tokens;
4832
- if (head !== void 0 && basename(head) === "cd") recordCd(tracker, segment.tokens);
4990
+ if (head !== void 0 && basename$1(head) === "cd") recordCd(tracker, segment.tokens);
4833
4991
  applyGrouping(tracker, segment.endedBy);
4834
4992
  }
4835
4993
  return result;
@@ -4855,7 +5013,7 @@ function newAnalysisBudget(reading = "default", quoting = "bash", bodies) {
4855
5013
  if (bodies !== void 0) budget.bodies = bodies;
4856
5014
  return budget;
4857
5015
  }
4858
- function basename$1(exe) {
5016
+ function basename(exe) {
4859
5017
  const slash = exe.lastIndexOf("/");
4860
5018
  return slash >= 0 ? exe.slice(slash + 1) : exe;
4861
5019
  }
@@ -4865,6 +5023,7 @@ function lexSegmentsBounded(command, reading = "default", quoting = "bash") {
4865
5023
  truncated: true,
4866
5024
  bodyCommands: [],
4867
5025
  bodyUnresolved: false,
5026
+ delimiterShellDependent: false,
4868
5027
  scripts: NO_SCRIPTS
4869
5028
  };
4870
5029
  const bodies = {
@@ -4884,6 +5043,7 @@ function lexSegmentsBounded(command, reading = "default", quoting = "bash") {
4884
5043
  truncated: state.tokensRemaining <= 0,
4885
5044
  bodyCommands: bodies.commands,
4886
5045
  bodyUnresolved: bodies.unresolved,
5046
+ delimiterShellDependent: bodies.shellDependent === true,
4887
5047
  scripts: bodies.scripts ?? NO_SCRIPTS
4888
5048
  };
4889
5049
  }
@@ -4915,7 +5075,7 @@ function splitArguments(command) {
4915
5075
  * command. */
4916
5076
  function commandName(command) {
4917
5077
  const first = command[0];
4918
- return first === void 0 ? void 0 : basename$1(first.value);
5078
+ return first === void 0 ? void 0 : basename(first.value);
4919
5079
  }
4920
5080
  // src/modules/analysis/shell/shell-lexer-tables.ts
4921
5081
  const TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
@@ -5252,7 +5412,7 @@ const CAT_PLAIN_WORDS = /* @__PURE__ */ new Set([
5252
5412
  * Where shells disagree on a form, it counts. */
5253
5413
  function shellReadsStdin(words, from = 0) {
5254
5414
  const head = words[from]?.value ?? "";
5255
- if (!STDIN_SCRIPT_SHELLS.has(basename$1(head))) return false;
5415
+ if (!STDIN_SCRIPT_SHELLS.has(basename(head))) return false;
5256
5416
  const scan = scanOptions(words, from + 1);
5257
5417
  if (scan.noRun || scan.noExec) return false;
5258
5418
  return scan.stdinFlag || !scan.command && !scan.operand;
@@ -5260,7 +5420,7 @@ function shellReadsStdin(words, from = 0) {
5260
5420
  /** Whether `words` are a `cat` that passes its stdin on unchanged: no
5261
5421
  * options, or `-u`, with no file operand but `-`. */
5262
5422
  function catPassesStdin(words) {
5263
- if (basename$1(words[0]?.value ?? "") !== "cat") return false;
5423
+ if (basename(words[0]?.value ?? "") !== "cat") return false;
5264
5424
  return words.slice(1).every((word) => CAT_PLAIN_WORDS.has(word.value));
5265
5425
  }
5266
5426
  function scanOptions(words, from) {
@@ -5292,12 +5452,12 @@ function scanWord(words, index, scan) {
5292
5452
  scan.operand = index + 1 < words.length;
5293
5453
  return;
5294
5454
  }
5295
- if (word.startsWith("--")) return longOption(word, scan);
5455
+ if (word.startsWith("--")) return longOption$1(word, scan);
5296
5456
  if (word.length > 1 && (word.startsWith("-") || word.startsWith("+"))) return optionCluster(words, index, scan);
5297
5457
  scan.operand = true;
5298
5458
  }
5299
5459
  /** The words a long option takes after itself. */
5300
- function longOption(word, scan) {
5460
+ function longOption$1(word, scan) {
5301
5461
  if (SHELL_NO_RUN_LONG_OPTIONS.has(word)) scan.noRun = true;
5302
5462
  return SHELL_LONG_VALUE_OPTIONS.has(word) ? 1 : 0;
5303
5463
  }
@@ -6903,7 +7063,7 @@ const SCRIPT_READER = /\b(?:sh|bash|zsh|dash|ksh|ash|mksh|ssh|busybox)\b/;
6903
7063
  function keepStringBodies(bodies, text) {
6904
7064
  if (bodies === void 0 || !text.includes("<<")) return;
6905
7065
  const read = sanitizedText(text);
6906
- keepBodyCommands(bodies, read.bodyCommands, read.bodyUnresolved);
7066
+ keepBodyCommands(bodies, read.bodyCommands, read.bodyUnresolved, read.delimiterShellDependent);
6907
7067
  keepBodyScripts(bodies, read.scripts);
6908
7068
  if (read.scripts.size > 0 && SCRIPT_READER.test(read.text)) feedsOf(bodies).commands.push(text);
6909
7069
  }
@@ -7031,7 +7191,7 @@ function walk(tokens, sink, inheritedRedirections, depth, remote = false, readin
7031
7191
  function peel(words, i, level) {
7032
7192
  const word = elementAt(words, i, "tokens").value;
7033
7193
  if (word === "--") return void 0;
7034
- const base = basename$1(word);
7194
+ const base = basename(word);
7035
7195
  level.sink.heads?.push({
7036
7196
  head: base,
7037
7197
  tokens: words,
@@ -7153,7 +7313,7 @@ function localExecutableCommand(tokens) {
7153
7313
  if (offset < 0 || command.some((value, index) => normalized[offset + index]?.value !== value)) return;
7154
7314
  const prefix = normalized.slice(0, offset).map((token) => token.value);
7155
7315
  if (prefix.some((token) => ["--help", "--version"].includes(token))) return;
7156
- if (prefix.some((token) => basename(token) === "command") && prefix.some((token) => /^-[vV]+$/.test(token))) return;
7316
+ if (prefix.some((token) => basename$1(token) === "command") && prefix.some((token) => /^-[vV]+$/.test(token))) return;
7157
7317
  if (prefix.some((token) => [
7158
7318
  "ssh",
7159
7319
  "chroot",
@@ -7173,7 +7333,7 @@ function localExecutableCommand(tokens) {
7173
7333
  "ash",
7174
7334
  "mksh",
7175
7335
  "fish"
7176
- ].includes(basename(token)))) return;
7336
+ ].includes(basename$1(token)))) return;
7177
7337
  if (prefix.some((token) => /^-(?!-)[^-]*[CDR]/.test(token) || /^--(?:chdir|chroot|working-directory)(?:=|$)/.test(token))) return;
7178
7338
  return {
7179
7339
  tokens: command,
@@ -7225,7 +7385,7 @@ const PLANNED_SUBCOMMANDS = [
7225
7385
  * tokens and prefix, and its planned subcommand. */
7226
7386
  function plannedInvocation(segmentTokens) {
7227
7387
  const local = localExecutableCommand(segmentTokens);
7228
- if (!local || basename(local.tokens[0] ?? "") !== "git") return void 0;
7388
+ if (!local || basename$1(local.tokens[0] ?? "") !== "git") return void 0;
7229
7389
  const { command: subcommand, index } = gitSubcommand(local.tokens, 0);
7230
7390
  if (!subcommand || !PLANNED_SUBCOMMANDS.includes(subcommand)) return void 0;
7231
7391
  return {
@@ -8508,7 +8668,7 @@ async function includeFileOnce(source, directory, rootDirectory, worktree, maxCh
8508
8668
  const actualBlock = resolvedPathBlock(actual, roots, "outside approved enrichment roots");
8509
8669
  if (actualBlock !== void 0) return blocked(resolved, actualBlock);
8510
8670
  const limit = Math.max(1, maxChars);
8511
- const handle = await open(actual, O_RDONLY$1 | O_NOFOLLOW$1 | O_NONBLOCK$1);
8671
+ const handle = await open$2(actual, O_RDONLY$1 | O_NOFOLLOW$1 | O_NONBLOCK$1);
8512
8672
  try {
8513
8673
  return await readOpenedFile(handle, resolved, roots, limit);
8514
8674
  } finally {
@@ -8610,8 +8770,8 @@ const INTERPRETERS = /* @__PURE__ */ new Set([
8610
8770
  function interpreterScript(tokens) {
8611
8771
  const command = localExecutableCommand(tokens)?.tokens;
8612
8772
  const executable = command?.[0];
8613
- if (command === void 0 || executable === void 0 || !INTERPRETERS.has(basename(executable))) return;
8614
- const interpreter = basename(executable);
8773
+ if (command === void 0 || executable === void 0 || !INTERPRETERS.has(basename$1(executable))) return;
8774
+ const interpreter = basename$1(executable);
8615
8775
  const path = scriptPath(command, 0, interpreter);
8616
8776
  return path ? {
8617
8777
  interpreter,
@@ -8700,7 +8860,7 @@ function isScriptName(script) {
8700
8860
  return script !== void 0 && script !== "" && !script.startsWith("-") && !/[/$`*?{}<>]/.test(script) && !/\.[cm]?[jt]sx?$/.test(script);
8701
8861
  }
8702
8862
  function invocation(tokens) {
8703
- const manager = basename(tokens[0] ?? "");
8863
+ const manager = basename$1(tokens[0] ?? "");
8704
8864
  if (!MANAGERS.has(manager)) return;
8705
8865
  const scan = {
8706
8866
  cursor: 1,
@@ -8737,9 +8897,9 @@ const REMOTE_OR_PRIVILEGED = [
8737
8897
  "systemd-run"
8738
8898
  ];
8739
8899
  function scriptCalls(tokens) {
8740
- const managerIndex = tokens.findIndex((token) => MANAGERS.has(basename(token)));
8900
+ const managerIndex = tokens.findIndex((token) => MANAGERS.has(basename$1(token)));
8741
8901
  const prefix = managerIndex < 0 ? tokens : tokens.slice(0, managerIndex);
8742
- if (prefix.some((token) => REMOTE_OR_PRIVILEGED.includes(basename(token)))) return [];
8902
+ if (prefix.some((token) => REMOTE_OR_PRIVILEGED.includes(basename$1(token)))) return [];
8743
8903
  const redirected = prefix.some((token) => token === "-C" || token.startsWith("--chdir"));
8744
8904
  const commands = effectiveCommands({ tokens: tokens.map((value) => ({
8745
8905
  raw: value,
@@ -9103,7 +9263,7 @@ function sshLoginUser(words, start) {
9103
9263
  }
9104
9264
  // src/modules/evidence/ssh/ssh-command-segments.ts
9105
9265
  function findSshIndex(tokens) {
9106
- return tokens.findIndex((token) => basename(token) === "ssh");
9266
+ return tokens.findIndex((token) => basename$1(token) === "ssh");
9107
9267
  }
9108
9268
  function parseSsh(tokens, sshIndex) {
9109
9269
  const { destination, index, options } = scanSshArguments(tokens, sshIndex);
@@ -9149,7 +9309,7 @@ function remoteCommand(tokens) {
9149
9309
  }
9150
9310
  function catSource(tokens) {
9151
9311
  const [head] = tokens;
9152
- if (tokens.length < 2 || head === void 0 || basename(head) !== "cat") return;
9312
+ if (tokens.length < 2 || head === void 0 || basename$1(head) !== "cat") return;
9153
9313
  const positional = tokens.slice(1).filter((value) => value !== "--" && !value.startsWith("-"));
9154
9314
  const [source] = positional;
9155
9315
  if (positional.length !== 1 || source === void 0) return;
@@ -9965,7 +10125,7 @@ function hasInlineCodeOption(tokens) {
9965
10125
  interpreter: "",
9966
10126
  inline: false
9967
10127
  };
9968
- const base = basename$1(first.value);
10128
+ const base = basename(first.value);
9969
10129
  if (!INTERPRETERS$1.has(base)) return {
9970
10130
  interpreter: base,
9971
10131
  inline: false
@@ -9995,14 +10155,15 @@ function analysisWarnings(parsed, heredocTruncated) {
9995
10155
  if (parsed.heredocs.some((h) => h.dynamic)) warnings.push("one or more heredoc bodies have unresolvable expansion");
9996
10156
  if (heredocTruncated) warnings.push("one or more heredoc bodies were truncated or never terminated");
9997
10157
  if (parsed.analysisTruncated) warnings.push("command structure exceeded the static analysis depth or expansion budget");
10158
+ if (parsed.shellDependentQuoting) warnings.push("command contains a $'…' escape whose value depends on the shell");
9998
10159
  return warnings;
9999
10160
  }
10000
10161
  function parserCompleteness(parsed, heredocTruncated) {
10001
10162
  if (parsed.hasDynamicConstructs) return hasCommandSubstitution(parsed.sanitizedCommand) || parsed.heredocs.some((h) => h.dynamic) ? "opaque" : "partial";
10002
- return parsed.analysisTruncated || heredocTruncated ? "partial" : "complete-for-supported-form";
10163
+ return parsed.analysisTruncated || heredocTruncated || parsed.shellDependentQuoting ? "partial" : "complete-for-supported-form";
10003
10164
  }
10004
- function summaryOf(facts) {
10005
- const summaryParts = [facts.dominantClass];
10165
+ function summaryOf(facts, actionClass) {
10166
+ const summaryParts = [actionClass];
10006
10167
  if (facts.createsAdHocCode) summaryParts.push("ad-hoc code");
10007
10168
  if (facts.executesRepositoryCode) summaryParts.push("repository code");
10008
10169
  if (facts.invokesPackageLifecycle) summaryParts.push("package lifecycle scripts");
@@ -10012,17 +10173,24 @@ function summaryOf(facts) {
10012
10173
  if (facts.privilegeEscalation) summaryParts.push("privilege escalation");
10013
10174
  return summaryParts.join(", ");
10014
10175
  }
10176
+ /** The class the facts give. A shell-dependent word can hide an effect the
10177
+ * facts missed, so it turns `read-only` into `unknown`; any other class
10178
+ * stays, so a rule that matches it still does. */
10179
+ function actionClassOf$1(parsed, facts) {
10180
+ return parsed.shellDependentQuoting && facts.dominantClass === "read-only" ? "unknown" : facts.dominantClass;
10181
+ }
10015
10182
  function assessmentFrom(parsed, facts) {
10183
+ const actionClass = actionClassOf$1(parsed, facts);
10016
10184
  const heredocTruncated = parsed.heredocs.some((h) => h.truncated);
10017
10185
  const warnings = analysisWarnings(parsed, heredocTruncated);
10018
10186
  const networkPossible = facts.networkObserved || facts.networkPossible;
10019
10187
  return {
10020
10188
  actionClass: {
10021
- value: facts.dominantClass,
10189
+ value: actionClass,
10022
10190
  source: "static-analysis",
10023
- confidence: facts.classConfidence
10191
+ confidence: parsed.shellDependentQuoting ? "low" : facts.classConfidence
10024
10192
  },
10025
- summary: summaryOf(facts),
10193
+ summary: summaryOf(facts, actionClass),
10026
10194
  executesCode: staticFlag(facts.executesCode),
10027
10195
  executesRepositoryCode: staticFlag(facts.executesRepositoryCode),
10028
10196
  createsAdHocCode: staticFlag(facts.createsAdHocCode),
@@ -10061,13 +10229,275 @@ function assessmentFrom(parsed, facts) {
10061
10229
  analysisWarnings: warnings
10062
10230
  };
10063
10231
  }
10232
+ // src/modules/analysis/capability/getopt-long-option.ts
10233
+ /** A getopt_long option word: `--name` or `--name=value`, where `name` may be
10234
+ * any unambiguous prefix of the full option name. `minimum` is the length of
10235
+ * the shortest such prefix, `--` included, so a shorter prefix that another
10236
+ * option of the same tool shares never matches. */
10237
+ function longOption(value, name, minimum) {
10238
+ if (!value.startsWith("--")) return void 0;
10239
+ const equals = value.indexOf("=");
10240
+ const word = equals === -1 ? value : value.slice(0, equals);
10241
+ if (word.length < minimum || !name.startsWith(word)) return void 0;
10242
+ return equals === -1 ? {} : { inline: value.slice(equals + 1) };
10243
+ }
10244
+ // src/modules/analysis/capability/output-operand-mutations.ts
10245
+ /** uniq's long options with a required value, with the length of each one's
10246
+ * shortest unambiguous prefix. */
10247
+ const UNIQ_VALUED_LONG = [
10248
+ ["--skip-fields", 8],
10249
+ ["--skip-chars", 8],
10250
+ ["--check-chars", 4]
10251
+ ];
10252
+ const UNIQ_OPTIONS = {
10253
+ takesNextWord(value) {
10254
+ if (value.startsWith("--")) return !value.includes("=") && UNIQ_VALUED_LONG.some(([name, minimum]) => longOption(value, name, minimum) !== void 0);
10255
+ const at = value.slice(1).search(/[fsw]/);
10256
+ return at !== -1 && at + 2 === value.length;
10257
+ },
10258
+ permute: true
10259
+ };
10260
+ /** xxd's options that take a value, by letter, with the tails of their long
10261
+ * spellings (`-c`, `-cols`). Such a word takes the next word as its value;
10262
+ * any other text after the letter is the value itself (`-c8`). */
10263
+ const XXD_VALUED = /* @__PURE__ */ new Map([
10264
+ ["c", ["ols"]],
10265
+ ["g", ["roup"]],
10266
+ ["o", ["ffset"]],
10267
+ ["s", ["kip", "eek"]],
10268
+ ["l", ["en"]],
10269
+ ["n", ["ame"]],
10270
+ ["R", []]
10271
+ ]);
10272
+ const XXD_OPTIONS = {
10273
+ takesNextWord(value) {
10274
+ const word = value.startsWith("--") && value.length > 2 ? value.slice(1) : value;
10275
+ const rest = word.slice(2);
10276
+ if (word.charAt(1) === "c" && rest.startsWith("apitalize")) return false;
10277
+ const tails = XXD_VALUED.get(word.charAt(1));
10278
+ if (tails === void 0) return false;
10279
+ return rest === "" || tails.some((tail) => rest.startsWith(tail));
10280
+ },
10281
+ permute: false
10282
+ };
10283
+ /** `TOOL [OPTION]... [INPUT [OUTPUT]]` (uniq, xxd): a second operand is a file
10284
+ * the command writes ("-" is standard output). */
10285
+ function outputOperandMutation(cmd, tool) {
10286
+ const output = operandsOf(cmd, tool)[1];
10287
+ return output !== void 0 && output !== "-" ? { writeTargets: [output] } : void 0;
10288
+ }
10289
+ function operandsOf(cmd, tool) {
10290
+ const operands = [];
10291
+ let options = true;
10292
+ for (let index = 1; index < cmd.length; index += 1) {
10293
+ const value = elementAt(cmd, index, "cmd").value;
10294
+ if (options && value === "--") options = false;
10295
+ else if (options && value.startsWith("-") && value !== "-") {
10296
+ if (tool.takesNextWord(value)) index += 1;
10297
+ } else {
10298
+ operands.push(value);
10299
+ options &&= tool.permute;
10300
+ }
10301
+ }
10302
+ return operands;
10303
+ }
10304
+ // src/modules/analysis/capability/sort-mutation.ts
10305
+ /** GNU sort short options that take a value. The value is the rest of the
10306
+ * cluster, or the next word when the letter ends it. */
10307
+ const SORT_VALUED_LETTERS = "kotST";
10308
+ /** GNU sort: `-o FILE` writes FILE and `--compress-program=PROG` runs PROG.
10309
+ * Short options cluster getopt-style (`-uo FILE`, `-nruoFILE`), and long
10310
+ * options may be abbreviated (`--out=FILE`). */
10311
+ function sortMutation(cmd) {
10312
+ const result = { writeTargets: [] };
10313
+ let index = 1;
10314
+ while (index < cmd.length) {
10315
+ const value = elementAt(cmd, index, "cmd").value;
10316
+ if (value === "--") break;
10317
+ index += value.startsWith("--") ? sortLongOption(cmd, index, result) : sortShortOptions(cmd, index, result);
10318
+ }
10319
+ return result.writeTargets.length > 0 || result.executesCode === true ? result : void 0;
10320
+ }
10321
+ /** Record a long option's effect; returns the words it spans. */
10322
+ function sortLongOption(cmd, index, result) {
10323
+ const value = elementAt(cmd, index, "cmd").value;
10324
+ const output = longOption(value, "--output", 3);
10325
+ if (output !== void 0) {
10326
+ const target = output.inline ?? cmd[index + 1]?.value;
10327
+ if (target !== void 0) result.writeTargets.push(target);
10328
+ return output.inline === void 0 ? 2 : 1;
10329
+ }
10330
+ if (longOption(value, "--compress-program", 4) !== void 0) result.executesCode = true;
10331
+ return 1;
10332
+ }
10333
+ /** Record a short-option cluster's output file; returns the words it spans. */
10334
+ function sortShortOptions(cmd, index, result) {
10335
+ const value = elementAt(cmd, index, "cmd").value;
10336
+ if (!value.startsWith("-") || value === "-") return 1;
10337
+ for (let at = 1; at < value.length; at += 1) {
10338
+ const letter = value.charAt(at);
10339
+ if (!SORT_VALUED_LETTERS.includes(letter)) continue;
10340
+ const attached = value.slice(at + 1);
10341
+ const argument = attached === "" ? cmd[index + 1]?.value : attached;
10342
+ if (letter === "o" && argument !== void 0) result.writeTargets.push(argument);
10343
+ return attached === "" ? 2 : 1;
10344
+ }
10345
+ return 1;
10346
+ }
10347
+ // src/modules/analysis/capability/tree-mutation.ts
10348
+ /** tree's short options whose value is the next unused word. `-L` also takes
10349
+ * its value as digits attached inside the cluster (`-L2`). */
10350
+ const TREE_VALUED_LETTERS = /* @__PURE__ */ new Set([
10351
+ "L",
10352
+ "P",
10353
+ "I",
10354
+ "H",
10355
+ "T",
10356
+ "o"
10357
+ ]);
10358
+ /** tree's long options with a value, which is inline (`--sort=name`) or the
10359
+ * next word. tree matches each by prefix. */
10360
+ const TREE_VALUED_LONG = [
10361
+ "--authority",
10362
+ "--charset",
10363
+ "--compress",
10364
+ "--filelimit",
10365
+ "--gitfile",
10366
+ "--hintro",
10367
+ "--houtro",
10368
+ "--infofile",
10369
+ "--scheme",
10370
+ "--sort",
10371
+ "--timefmt"
10372
+ ];
10373
+ /** tree: `-o FILE` writes FILE, and `-R` writes an `00Tree.html` listing into
10374
+ * each directory it visits. Options may follow the roots. */
10375
+ function treeMutation(cmd) {
10376
+ const scan = {
10377
+ roots: [],
10378
+ outputs: [],
10379
+ recursive: false
10380
+ };
10381
+ let index = 1;
10382
+ while (index < cmd.length) {
10383
+ if (elementAt(cmd, index, "cmd").value === "--") {
10384
+ scan.roots.push(...cmd.slice(index + 1).map((token) => token.value));
10385
+ break;
10386
+ }
10387
+ index += treeWord(cmd, index, scan);
10388
+ }
10389
+ const writeTargets = [...scan.outputs];
10390
+ if (scan.recursive) writeTargets.push(...scan.roots.length > 0 ? scan.roots : ["."]);
10391
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
10392
+ }
10393
+ /** Scan the word at `index`; returns the words it spans. */
10394
+ function treeWord(cmd, index, scan) {
10395
+ const value = elementAt(cmd, index, "cmd").value;
10396
+ if (value.startsWith("--")) return TREE_VALUED_LONG.some((name) => value.startsWith(name) && value.charAt(name.length) !== "=") ? 2 : 1;
10397
+ if (!value.startsWith("-") || value === "-") {
10398
+ scan.roots.push(value);
10399
+ return 1;
10400
+ }
10401
+ return 1 + treeShortOptions(cmd, index, scan);
10402
+ }
10403
+ /** Scan a short-option cluster. Each letter that takes a value consumes the
10404
+ * next unused word, in order (`-Lo 2 out.txt`). Returns how many it used. */
10405
+ function treeShortOptions(cmd, index, scan) {
10406
+ const value = elementAt(cmd, index, "cmd").value;
10407
+ let consumed = 0;
10408
+ let at = 1;
10409
+ while (at < value.length) {
10410
+ const letter = value.charAt(at);
10411
+ const digits = letter === "L" ? attachedDigits(value, at + 1) : 0;
10412
+ if (letter === "R") scan.recursive = true;
10413
+ else if (digits === 0 && TREE_VALUED_LETTERS.has(letter)) {
10414
+ consumed += 1;
10415
+ recordTreeValue(letter, cmd[index + consumed]?.value, scan);
10416
+ }
10417
+ at += 1 + digits;
10418
+ }
10419
+ return consumed;
10420
+ }
10421
+ /** How many digits start `value` at `from`. */
10422
+ function attachedDigits(value, from) {
10423
+ return value.slice(from).match(/^\d*/)?.[0].length ?? 0;
10424
+ }
10425
+ function recordTreeValue(letter, argument, scan) {
10426
+ if (letter === "o" && argument !== void 0) scan.outputs.push(argument);
10427
+ }
10428
+ // src/modules/analysis/capability/yq-mutation.ts
10429
+ /** yq's short flags that take a value. The value is the rest of the cluster,
10430
+ * so a later letter is not a flag (`-oi` is output format "i"). */
10431
+ const YQ_VALUED_LETTERS = "poIsf";
10432
+ /** The values a Go boolean flag parses as false. */
10433
+ const FALSE_VALUES = /* @__PURE__ */ new Set([
10434
+ "0",
10435
+ "f",
10436
+ "F",
10437
+ "false",
10438
+ "FALSE",
10439
+ "False"
10440
+ ]);
10441
+ /** yq: `-i` rewrites its file operands, and `-s` writes a file per result.
10442
+ * For an in-place edit every non-option word, the expression included, is
10443
+ * recorded as a write target. */
10444
+ function yqMutation(cmd) {
10445
+ const writes = yqWrites(cmd);
10446
+ const writeTargets = [];
10447
+ if (writes.inPlace) writeTargets.push(...cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-")));
10448
+ if (writes.split) writeTargets.push(writes.anyPath ? "/" : ".");
10449
+ if (writes.inPlace && writeTargets.length === 0) writeTargets.push(".");
10450
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
10451
+ }
10452
+ /** Scan yq's flags (pflag syntax: no abbreviations, booleans may carry
10453
+ * `=value`, short booleans cluster). */
10454
+ function yqWrites(cmd) {
10455
+ const writes = {
10456
+ inPlace: false,
10457
+ split: false,
10458
+ anyPath: false
10459
+ };
10460
+ for (const token of cmd.slice(1)) {
10461
+ const value = token.value;
10462
+ if (value === "--") break;
10463
+ if (value.startsWith("--")) yqLongFlag(value, writes);
10464
+ else if (value.startsWith("-")) yqShortFlags(value, writes);
10465
+ }
10466
+ return writes;
10467
+ }
10468
+ function yqLongFlag(value, writes) {
10469
+ const equals = value.indexOf("=");
10470
+ const name = equals === -1 ? value : value.slice(0, equals);
10471
+ const enabled = equals === -1 || !FALSE_VALUES.has(value.slice(equals + 1));
10472
+ if (name === "--inplace") writes.inPlace ||= enabled;
10473
+ else if (name === "--split-exp" || name === "--split-exp-file") writes.split = true;
10474
+ else if (name === "--security-allow-write-any-path") writes.anyPath ||= enabled;
10475
+ }
10476
+ function yqShortFlags(value, writes) {
10477
+ for (let at = 1; at < value.length; at += 1) {
10478
+ const letter = value.charAt(at);
10479
+ if (letter === "i") {
10480
+ if (yqInPlaceFlag(value, at, writes)) return;
10481
+ } else if (YQ_VALUED_LETTERS.includes(letter)) {
10482
+ writes.split ||= letter === "s";
10483
+ return;
10484
+ }
10485
+ }
10486
+ }
10487
+ /** Record the `-i` at `at`. pflag reads `-i=false` as the flag with a value,
10488
+ * which ends the cluster; returns whether it did. */
10489
+ function yqInPlaceFlag(value, at, writes) {
10490
+ const inline = value.charAt(at + 1) === "=" ? value.slice(at + 2) : void 0;
10491
+ writes.inPlace ||= inline === void 0 || !FALSE_VALUES.has(inline);
10492
+ return inline !== void 0;
10493
+ }
10064
10494
  // src/modules/analysis/capability/read-only-tool-mutations.ts
10065
- /** Placeholder target when a mutating form names no operand: conservatively
10066
- * treated as a workspace write (the current directory). */
10067
- const directoryFallback = ".";
10068
10495
  function readOnlyToolMutation(cmd, base) {
10069
10496
  if (base === "find") return findMutation(cmd);
10070
10497
  if (base === "sort") return sortMutation(cmd);
10498
+ if (base === "uniq") return outputOperandMutation(cmd, UNIQ_OPTIONS);
10499
+ if (base === "xxd") return outputOperandMutation(cmd, XXD_OPTIONS);
10500
+ if (base === "tree") return treeMutation(cmd);
10071
10501
  if (base === "yq") return yqMutation(cmd);
10072
10502
  }
10073
10503
  function findMutation(cmd) {
@@ -10127,22 +10557,6 @@ function pushOptionValue(cmd, index, targets) {
10127
10557
  const target = cmd[index + 1]?.value;
10128
10558
  if (target !== void 0 && !target.startsWith("-")) targets.push(target);
10129
10559
  }
10130
- function sortMutation(cmd) {
10131
- const result = { writeTargets: [] };
10132
- for (let index = 1; index < cmd.length; index += 1) {
10133
- const value = elementAt(cmd, index, "cmd").value;
10134
- if (value === "-o" || value === "--output") pushOptionValue(cmd, index, result.writeTargets);
10135
- else if (value.startsWith("--output=")) result.writeTargets.push(value.slice(9));
10136
- else if (value.startsWith("-o") && value.length > 2) result.writeTargets.push(value.slice(2));
10137
- }
10138
- return result.writeTargets.length > 0 ? result : void 0;
10139
- }
10140
- /** In-place edit: every non-option operand, the expression included, is recorded as a write target. */
10141
- function yqMutation(cmd) {
10142
- if (!cmd.some((token) => token.value === "-i" || token.value === "--inplace")) return void 0;
10143
- const targets = cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-"));
10144
- return targets.length > 0 ? { writeTargets: targets } : { writeTargets: [directoryFallback] };
10145
- }
10146
10560
  // src/modules/analysis/capability/executable-recognition.ts
10147
10561
  /** Effect families that keep a read-only or no-effect executable from
10148
10562
  * counting as read-only. */
@@ -10491,7 +10905,7 @@ function classifyPersistenceTool(base, facts) {
10491
10905
  function classifyEffectiveCommand(cmd, facts, context) {
10492
10906
  const first = cmd[0];
10493
10907
  if (first === void 0) return;
10494
- const base = basename$1(first.value);
10908
+ const base = basename(first.value);
10495
10909
  classifyRecognition(base, classifyReadOnlyToolMutation(cmd, base, facts, context), facts);
10496
10910
  classifyInterpreter(cmd, base, facts, context);
10497
10911
  classifyTestRunner(base, facts);
@@ -10566,7 +10980,7 @@ function classifyCredentialReads(parsed, facts) {
10566
10980
  function classifyCredentialCommand(cmd, redirects, facts) {
10567
10981
  const first = cmd[0];
10568
10982
  if (first === void 0) return;
10569
- const base = basename$1(first.value);
10983
+ const base = basename(first.value);
10570
10984
  for (const r of redirects) if (inputRedirectReadsCredential(r)) facts.credentialRead = true;
10571
10985
  if (!CREDENTIAL_READERS.has(base)) return;
10572
10986
  for (let i = 1; i < cmd.length; i += 1) if (operandReadsCredential(elementAt(cmd, i - 1, "cmd"), elementAt(cmd, i, "cmd").value)) facts.credentialRead = true;
@@ -10594,7 +11008,7 @@ function classifyTruncatedSegmentHeads(segments, facts) {
10594
11008
  for (const { tokens } of segments) {
10595
11009
  let k = commandStart$1(tokens);
10596
11010
  while (k !== void 0 && k < tokens.length) {
10597
- const head = basename$1(valueAt(tokens, k));
11011
+ const head = basename(valueAt(tokens, k));
10598
11012
  classifyWrapperHead(head, facts);
10599
11013
  if (SSH_TOOLS.has(head) && tailMutates(tokens, k + 1)) facts.remoteMutation = true;
10600
11014
  k = wrappedCommandIndex(tokens, k, head);
@@ -10660,6 +11074,7 @@ function newWalked() {
10660
11074
  effective: [],
10661
11075
  redirections: [],
10662
11076
  truncated: false,
11077
+ delimiterShellDependent: false,
10663
11078
  parts: [],
10664
11079
  remote: [],
10665
11080
  stdinCode: false,
@@ -10927,7 +11342,7 @@ function isPipe(separator) {
10927
11342
  * operand, so an option whose grammar is not known leaves stdin as data.
10928
11343
  */
10929
11344
  function interpreterReadsStdin(words) {
10930
- const name = basename$1(words[0]?.value ?? "");
11345
+ const name = basename(words[0]?.value ?? "");
10931
11346
  const spec = INTERPRETER_SPECS[name];
10932
11347
  const valued = (option) => OPTIONS_WITH_VALUE.has(option) || spec?.valueOptions?.has(option) === true;
10933
11348
  for (let index = 1; index < words.length; index += 1) {
@@ -10966,7 +11381,7 @@ function analyzeFeeds(parts, scripts) {
10966
11381
  * file or command string for a shell, without a script operand for the
10967
11382
  * rest. */
10968
11383
  function runsStdinCode(words) {
10969
- const head = basename$1(words[0]?.value ?? "");
11384
+ const head = basename(words[0]?.value ?? "");
10970
11385
  if (!INTERPRETERS$1.has(head)) return false;
10971
11386
  return STDIN_SCRIPT_SHELLS.has(head) ? shellReadsStdin(words) : interpreterReadsStdin(words);
10972
11387
  }
@@ -11055,6 +11470,7 @@ function addAll(into, scripts) {
11055
11470
  function walkBodyCommands(commands, unresolved, budget, into, feeds = [], scripts = []) {
11056
11471
  const strings = takeBodies(budget);
11057
11472
  into.truncated = into.truncated || unresolved || strings.unresolved;
11473
+ into.delimiterShellDependent ||= strings.shellDependent === true;
11058
11474
  const queue = [...[...commands, ...strings.commands].map((command) => ({
11059
11475
  command,
11060
11476
  level: 1,
@@ -11075,6 +11491,7 @@ function walkBodyCommands(commands, unresolved, budget, into, feeds = [], script
11075
11491
  if (next.remote) into.remote.push(...into.effective.slice(first.effective));
11076
11492
  const deeper = takeBodies(budget);
11077
11493
  into.truncated = into.truncated || lex.bodyUnresolved || deeper.unresolved;
11494
+ into.delimiterShellDependent ||= lex.delimiterShellDependent || deeper.shellDependent === true;
11078
11495
  if (lex.truncated || stopped) {
11079
11496
  into.truncated = true;
11080
11497
  return;
@@ -11092,9 +11509,11 @@ function takeBodies(budget) {
11092
11509
  };
11093
11510
  const taken = {
11094
11511
  commands: bodies.commands.splice(0),
11095
- unresolved: bodies.unresolved
11512
+ unresolved: bodies.unresolved,
11513
+ shellDependent: bodies.shellDependent === true
11096
11514
  };
11097
11515
  bodies.unresolved = false;
11516
+ bodies.shellDependent = false;
11098
11517
  return taken;
11099
11518
  }
11100
11519
  /** Queue the commands and feeds one level below `from`; true when that is
@@ -11115,6 +11534,46 @@ function queueDeeper(queue, commands, feeds, from) {
11115
11534
  });
11116
11535
  return false;
11117
11536
  }
11537
+ // src/modules/analysis/capability/heredoc/shell-dependent-word.ts
11538
+ /** Index of the first `close` at or after `from` that no backslash escapes,
11539
+ * or -1. */
11540
+ function closingIndex(raw, from, close) {
11541
+ for (let i = from; i < raw.length; i++) if (raw[i] === "\\") i++;
11542
+ else if (raw[i] === close) return i;
11543
+ return -1;
11544
+ }
11545
+ /** Index of the quote that ends a `'…'` or `"…"` region opened before `from`.
11546
+ * Inside single quotes a backslash is literal. */
11547
+ function quoteEnd(raw, from, quote) {
11548
+ return quote === "'" ? raw.indexOf("'", from) : closingIndex(raw, from, quote);
11549
+ }
11550
+ const FOUND = -1;
11551
+ const UNTERMINATED = -2;
11552
+ /** Index where the scan resumes after the part at `i`, FOUND for a
11553
+ * shell-dependent `$'…'`, or UNTERMINATED when a quote never closes. */
11554
+ function step(raw, i) {
11555
+ const ch = raw[i];
11556
+ if (ch === "\\") return i + 2;
11557
+ if (ch === "'" || ch === "\"") {
11558
+ const close = quoteEnd(raw, i + 1, ch);
11559
+ return close < 0 ? UNTERMINATED : close + 1;
11560
+ }
11561
+ if (ch === "$" && raw[i + 1] === "'") {
11562
+ const close = closingIndex(raw, i + 2, "'");
11563
+ if (close < 0) return UNTERMINATED;
11564
+ return ansiCShellDependent(raw.slice(i + 2, close)) ? FOUND : close + 1;
11565
+ }
11566
+ return i + 1;
11567
+ }
11568
+ /** Whether a word has an unquoted `$'…'` part whose escapes the shells
11569
+ * decode differently (`ansiCShellDependent`). One left-to-right pass: `'…'`,
11570
+ * `"…"` and backslash pairs are skipped, so `"$'\q'"` doesn't count. */
11571
+ function hasShellDependentWord(raw) {
11572
+ if (!raw.includes("\\")) return false;
11573
+ let i = 0;
11574
+ while (i >= 0 && i < raw.length) i = step(raw, i);
11575
+ return i === FOUND;
11576
+ }
11118
11577
  // src/modules/analysis/capability/command-parser.ts
11119
11578
  /** Parse a raw bash command into the reusable structure. */
11120
11579
  function parseCommand(rawCommand) {
@@ -11145,6 +11604,7 @@ function parse(rawCommand) {
11145
11604
  analysisTruncated: walked.truncated,
11146
11605
  heads: walked.heads,
11147
11606
  segmentRedirections: walked.parts.map((part) => part.segmentRedirections),
11607
+ shellDependentQuoting: extraction.delimiterShellDependent || lex.delimiterShellDependent || walked.delimiterShellDependent || [...walked.segments.flatMap((segment) => segment.tokens), ...walked.effective.flat()].some((token) => hasShellDependentWord(token.raw)),
11148
11608
  ...walked.remote.length > 0 && { remoteCommands: walked.remote },
11149
11609
  ...walked.stdinCode && { stdinCode: true }
11150
11610
  };
@@ -11579,15 +12039,16 @@ function renderActionPurpose(purpose, max, intentReference = false) {
11579
12039
  ...purpose.text === void 0 ? {} : { text: intentReference && purpose.source === "intent-derived" ? "<see literal intent sections>" : purpose.text }
11580
12040
  }, max)}`;
11581
12041
  }
11582
- /** Compact rendering of ask decisions, one line each (UTC time, question,
11583
- * answer). `undefined` when there is nothing to show so the whole section is
11584
- * omitted rather than padded with a placeholder. */
12042
+ /** Compact rendering of ask decisions, one line each (full UTC timestamp,
12043
+ * question, answer). The date keeps answers apart in sessions that span
12044
+ * several days. `undefined` when there is nothing to show so the whole
12045
+ * section is omitted rather than padded with a placeholder. */
11585
12046
  function renderAskDecisions(decisions) {
11586
12047
  if (decisions === void 0 || decisions.length === 0) return;
11587
12048
  const lines = [];
11588
12049
  for (const decision of decisions) {
11589
- const time = new Date(decision.at).toISOString().slice(11, 19);
11590
- lines.push(`[${time}Z] Q: ${decision.question} A: ${decision.answer}`);
12050
+ const time = new Date(decision.at).toISOString().replace(/\.\d{3}Z$/, "Z");
12051
+ lines.push(`[${time}] Q: ${decision.question} A: ${decision.answer}`);
11591
12052
  }
11592
12053
  const maxChars = 1500;
11593
12054
  while (lines.length > 1 && lines.join("\n").length > maxChars) lines.shift();
@@ -14584,7 +15045,7 @@ function commandReason(command, depth, budget, scripts) {
14584
15045
  * least as strict as the release before the substitution step, and the
14585
15046
  * undecoded reading as strict as the previous release, on every input. */
14586
15047
  function readingsReason(command, bodies) {
14587
- return brakeReadingsReason(command, "finder", bodies) ?? brakeReadingsReason(command, "rescan", bodies) ?? brakeReadingsReason(command, "undecoded", bodies) ?? brakeReadingsReason(command, "previous", bodies);
15048
+ return brakeReadingsReason(command, "finder", bodies) ?? brakeReadingsReason(command, "rescan", bodies) ?? brakeReadingsReason(command, "undecoded", bodies) ?? brakeReadingsReason(command, "previous", bodies) ?? (command.includes("\\") ? brakeReadingsReason(command, "zsh", bodies) ?? brakeReadingsReason(command, "bash32", bodies) : void 0);
14588
15049
  }
14589
15050
  // src/modules/policy/policy-conditions.ts
14590
15051
  /** Whether every field of a condition matches the observed facts. A missing
@@ -16172,24 +16633,6 @@ function probeCapabilities(client) {
16172
16633
  tuiPublish: typeof tui.publish === "function"
16173
16634
  };
16174
16635
  }
16175
- // src/adapters/opencode/host-guard.ts
16176
- /**
16177
- * OpenCode V2 host versions accepted at setup. A host outside this range
16178
- * fails setup loudly instead of running against an unknown contract.
16179
- */
16180
- const SUPPORTED_V2_RANGE = ">=2.0.22 <3";
16181
- /**
16182
- * Guard the legacy adapter against incompatible client shapes.
16183
- *
16184
- * A client exposing only permission.reply does not satisfy the legacy
16185
- * transport contract. Product V2 uses its own setup entrypoint and adapter.
16186
- */
16187
- function assertV1Host(client) {
16188
- const record = client ?? {};
16189
- const permission = record.permission ?? {};
16190
- const raw = record._client ?? {};
16191
- if (typeof permission.reply === "function" && typeof raw.post !== "function") throw new Error("The V1 adapter requires the authenticated legacy transport. Use the setup entrypoint for OpenCode V2; refusing this incompatible client.");
16192
- }
16193
16636
  // src/adapters/opencode/reply-transport.ts
16194
16637
  /**
16195
16638
  * Resolve how a permission reply is sent. The priority is: a public SDK reply
@@ -18755,6 +19198,11 @@ const server = async (input, options) => {
18755
19198
  const writeAudit = createAuditWriter(config, config.debug ? logger : debugLogger);
18756
19199
  const probe = probeHostVersion(input.client);
18757
19200
  const hostVersion = probe === void 0 ? void 0 : await probe;
19201
+ const refusal = v1HostVersionRefusal(hostVersion);
19202
+ if (refusal !== void 0) {
19203
+ debugLogger(refusal);
19204
+ throw new Error(refusal);
19205
+ }
18758
19206
  const ctx = {
18759
19207
  ...hostVersion ? { hostVersion } : {},
18760
19208
  ...createV1Adapter({