@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/CHANGELOG.md +62 -0
- package/dist/explain.js +583 -154
- package/dist/index.d.ts +4 -0
- package/dist/index.js +654 -206
- package/dist/tui/modules/config/models/openrouter-decision-models.ts +7 -1
- package/package.json +10 -10
package/dist/explain.js
CHANGED
|
@@ -3,7 +3,7 @@ import { parseArgs } from "node:util";
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
5
5
|
import { closeSync, constants, existsSync, fstatSync, fsyncSync, ftruncateSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, writeFileSync, writeSync } from "node:fs";
|
|
6
|
-
import { lstat, mkdir, open, readlink, realpath } from "node:fs/promises";
|
|
6
|
+
import { lstat, mkdir, open as open$2, readlink, realpath } from "node:fs/promises";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { satisfies } from "semver";
|
|
9
9
|
import { OpenCode } from "@opencode/client";
|
|
@@ -332,6 +332,9 @@ const OPENROUTER_DECISION_MODELS = {
|
|
|
332
332
|
"cloudflare/clef": { benchmarked: false },
|
|
333
333
|
"cloudflare/clef-flash": { benchmarked: false },
|
|
334
334
|
"cloudflare/clef-omni": { benchmarked: false },
|
|
335
|
+
"google/gemini-decision-1": { benchmarked: false },
|
|
336
|
+
"heygen/heygen-decision-1": { benchmarked: false },
|
|
337
|
+
"heygen/heygen-decision-1-turbo": { benchmarked: false },
|
|
335
338
|
"jaredpalmer/kev-4b": { benchmarked: false },
|
|
336
339
|
"liquid/d1": { benchmarked: true },
|
|
337
340
|
"liquid/d1-ultra": { benchmarked: true },
|
|
@@ -339,12 +342,15 @@ const OPENROUTER_DECISION_MODELS = {
|
|
|
339
342
|
"microsoft/microsoft-decision-1": { benchmarked: false },
|
|
340
343
|
"morph/reflex": { benchmarked: false },
|
|
341
344
|
"nace-ai/drex-max": { benchmarked: false },
|
|
345
|
+
"nace-ai/drex-max-finance": { benchmarked: false },
|
|
342
346
|
"nace-ai/drex-v1.5": { benchmarked: false },
|
|
343
347
|
"nace-ai/drex-v2.0": { benchmarked: false },
|
|
344
348
|
"openai/gpt-6-luna-decisions": { benchmarked: false },
|
|
345
|
-
"parallel/decisions-fast
|
|
349
|
+
"parallel/decisions-fast": { benchmarked: false },
|
|
346
350
|
"perplexity/pplx-decider-flash-v1.2": { benchmarked: false },
|
|
351
|
+
"perplexity/pplx-decider-flash-v1.3:free": { benchmarked: false },
|
|
347
352
|
"perplexity/pplx-decider-v1.2": { benchmarked: false },
|
|
353
|
+
"perplexity/pplx-decider-v1.3:free": { benchmarked: false },
|
|
348
354
|
"respan/span-02": { benchmarked: false },
|
|
349
355
|
"togethercomputer/tev1-4b-experimental": { benchmarked: false },
|
|
350
356
|
"typesafe/jev-1.13": { benchmarked: true },
|
|
@@ -1533,9 +1539,9 @@ function fmtCounts(map) {
|
|
|
1533
1539
|
* validates to nothing. */
|
|
1534
1540
|
function conditionMatches(cond, cap, actor, config) {
|
|
1535
1541
|
if (cond === void 0 || cond.always === true) return true;
|
|
1536
|
-
return listConditionHolds(cond.actionClass, cap, actionClassOf) && listConditionHolds(cond.actorProfile, actor, profileOf) && capabilityFlagsHold(cond, cap) && listConditionHolds(cond.repositoryTrust, config, repositoryTrustOf);
|
|
1542
|
+
return listConditionHolds(cond.actionClass, cap, actionClassOf$1) && listConditionHolds(cond.actorProfile, actor, profileOf) && capabilityFlagsHold(cond, cap) && listConditionHolds(cond.repositoryTrust, config, repositoryTrustOf);
|
|
1537
1543
|
}
|
|
1538
|
-
const actionClassOf = (cap) => cap.actionClass.value;
|
|
1544
|
+
const actionClassOf$1 = (cap) => cap.actionClass.value;
|
|
1539
1545
|
const profileOf = (actor) => actor.profile.value;
|
|
1540
1546
|
const repositoryTrustOf = (config) => config.repositoryTrust;
|
|
1541
1547
|
/** An enum-list condition holds when it is absent or lists the observed value.
|
|
@@ -1978,12 +1984,127 @@ function addScript(into, placeholder, text) {
|
|
|
1978
1984
|
function invariant(condition, message) {
|
|
1979
1985
|
if (!condition) throw new Error(message);
|
|
1980
1986
|
}
|
|
1987
|
+
// src/modules/analysis/capability/heredoc/ansi-c-numeric.ts
|
|
1988
|
+
const HEX_DIGITS = /* @__PURE__ */ new Map([
|
|
1989
|
+
["x", /[0-9a-f]{1,2}/iy],
|
|
1990
|
+
["u", /[0-9a-f]{1,4}/iy],
|
|
1991
|
+
["U", /[0-9a-f]{1,8}/iy]
|
|
1992
|
+
]);
|
|
1993
|
+
const OCTAL_DIGITS = /[0-7]{1,3}/y;
|
|
1994
|
+
/** The octal escape at `index`, whose first digit is at `index + 1`. */
|
|
1995
|
+
function decodeAnsiCOctal(inner, index) {
|
|
1996
|
+
const digits = digitsAt(inner, index + 1, OCTAL_DIGITS);
|
|
1997
|
+
return {
|
|
1998
|
+
text: String.fromCharCode(Number.parseInt(digits, 8) & 255),
|
|
1999
|
+
end: index + 1 + digits.length
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
/** The `\x`, `\u` or `\U` escape at `index`; undefined for another letter or
|
|
2003
|
+
* without a hex digit. */
|
|
2004
|
+
function decodeAnsiCHex(inner, index, letter) {
|
|
2005
|
+
const pattern = HEX_DIGITS.get(letter);
|
|
2006
|
+
if (pattern === void 0) return void 0;
|
|
2007
|
+
const digits = digitsAt(inner, index + 2, pattern);
|
|
2008
|
+
if (digits === "") return void 0;
|
|
2009
|
+
const end = index + 2 + digits.length;
|
|
2010
|
+
const value = Number.parseInt(digits, 16);
|
|
2011
|
+
if (letter === "x") return {
|
|
2012
|
+
text: String.fromCharCode(value),
|
|
2013
|
+
end
|
|
2014
|
+
};
|
|
2015
|
+
return {
|
|
2016
|
+
text: codePointText(value),
|
|
2017
|
+
end
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
/** The text bash gives a `\u` or `\U` code point. Values above 0x7fffffff
|
|
2021
|
+
* are dropped; surrogates and values past U+10FFFF are not JavaScript code
|
|
2022
|
+
* points and become U+FFFD. */
|
|
2023
|
+
function codePointText(value) {
|
|
2024
|
+
if (value > 2147483647) return "";
|
|
2025
|
+
if (value >= 55296 && value <= 57343 || value > 1114111) return "�";
|
|
2026
|
+
return String.fromCodePoint(value);
|
|
2027
|
+
}
|
|
2028
|
+
/** `\cX` is the control character of X. In bash 4.4 and later `\c?` is DEL and
|
|
2029
|
+
* `\c\\` takes both backslashes; bash 3.2 reads each like any other X. */
|
|
2030
|
+
function decodeAnsiCControl(inner, index, dialect) {
|
|
2031
|
+
const target = inner.charAt(index + 2);
|
|
2032
|
+
if (target === "") return {
|
|
2033
|
+
text: "\\c",
|
|
2034
|
+
end: index + 2
|
|
2035
|
+
};
|
|
2036
|
+
const modern = dialect === "bash";
|
|
2037
|
+
if (target === "\\" && modern) return {
|
|
2038
|
+
text: "",
|
|
2039
|
+
end: inner.charAt(index + 3) === "\\" ? index + 4 : index + 3
|
|
2040
|
+
};
|
|
2041
|
+
const code = target === "?" && modern ? 127 : target.charCodeAt(0) & 31;
|
|
2042
|
+
return {
|
|
2043
|
+
text: String.fromCharCode(code),
|
|
2044
|
+
end: index + 3
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
/** The digits matched by the sticky `pattern` at `start`. */
|
|
2048
|
+
function digitsAt(text, start, pattern) {
|
|
2049
|
+
pattern.lastIndex = start;
|
|
2050
|
+
return pattern.exec(text)?.[0] ?? "";
|
|
2051
|
+
}
|
|
2052
|
+
// src/modules/analysis/capability/heredoc/ansi-c-zsh.ts
|
|
2053
|
+
/** `\C` clears bits 5 and 6 (`?` becomes DEL); `\M` sets bit 7. */
|
|
2054
|
+
const MODIFIERS = {
|
|
2055
|
+
C: (code) => code === 63 ? 127 : code & 159,
|
|
2056
|
+
M: (code) => code | 128
|
|
2057
|
+
};
|
|
2058
|
+
/** An escape zsh reads without a backslash: `\x`, `\u` and `\U` without a
|
|
2059
|
+
* hex digit are NUL, a run of `\C[-]` and `\M[-]` modifies the first
|
|
2060
|
+
* character of the escape or character after it (innermost first, nothing
|
|
2061
|
+
* at the end of the text), and anything else (`\cX` included) is the
|
|
2062
|
+
* character itself. `decodeEscape` decodes the escape at an index. */
|
|
2063
|
+
function decodeZshOther(inner, index, escaped, decodeEscape) {
|
|
2064
|
+
if (/^[xuU]$/.test(escaped)) return {
|
|
2065
|
+
text: "\0",
|
|
2066
|
+
end: index + 2
|
|
2067
|
+
};
|
|
2068
|
+
if (MODIFIERS[escaped] === void 0) return {
|
|
2069
|
+
text: escaped,
|
|
2070
|
+
end: index + 2
|
|
2071
|
+
};
|
|
2072
|
+
const modifiers = [];
|
|
2073
|
+
let position = index;
|
|
2074
|
+
let modify = MODIFIERS[inner.charAt(position + 1)];
|
|
2075
|
+
while (inner.charAt(position) === "\\" && modify !== void 0) {
|
|
2076
|
+
modifiers.push(modify);
|
|
2077
|
+
position += inner.charAt(position + 2) === "-" ? 3 : 2;
|
|
2078
|
+
modify = MODIFIERS[inner.charAt(position + 1)];
|
|
2079
|
+
}
|
|
2080
|
+
const operand = operandAt(inner, position, decodeEscape);
|
|
2081
|
+
if (operand.text === "") return operand;
|
|
2082
|
+
let code = operand.text.charCodeAt(0);
|
|
2083
|
+
for (const apply of modifiers.reverse()) code = apply(code);
|
|
2084
|
+
return {
|
|
2085
|
+
text: String.fromCharCode(code) + operand.text.slice(1),
|
|
2086
|
+
end: operand.end
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
/** The escape or character a modifier run applies to. */
|
|
2090
|
+
function operandAt(inner, position, decodeEscape) {
|
|
2091
|
+
if (position >= inner.length) return {
|
|
2092
|
+
text: "",
|
|
2093
|
+
end: position
|
|
2094
|
+
};
|
|
2095
|
+
if (inner.charAt(position) === "\\" && position + 1 < inner.length) return decodeEscape(inner, position);
|
|
2096
|
+
return {
|
|
2097
|
+
text: inner.charAt(position),
|
|
2098
|
+
end: position + 1
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
1981
2101
|
// src/modules/analysis/capability/heredoc/ansi-c-quoting.ts
|
|
1982
|
-
/** Unescape
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
* resolved and the body scan reports the
|
|
2102
|
+
/** Unescape the `$'...'` region of a here-document delimiter word. Unknown
|
|
2103
|
+
* escapes drop the backslash as zsh does, so the text is right for every
|
|
2104
|
+
* shell only when `ansiCShellDependent` accepts the part; `scanDollarQuoted`
|
|
2105
|
+
* marks the word unresolved otherwise. A delimiter containing a newline can
|
|
2106
|
+
* never match a body line; it stays resolved and the body scan reports the
|
|
2107
|
+
* heredoc as unterminated. */
|
|
1987
2108
|
function unescapeAnsiC(command, start) {
|
|
1988
2109
|
let text = "";
|
|
1989
2110
|
let index = start;
|
|
@@ -2053,10 +2174,37 @@ function ansiCEscape(command, index, escaped) {
|
|
|
2053
2174
|
end: index + 2
|
|
2054
2175
|
};
|
|
2055
2176
|
}
|
|
2056
|
-
/**
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2059
|
-
|
|
2177
|
+
/** Whether an escape in `inner` (the text between `$'` and the closing `'`, as
|
|
2178
|
+
* written) is read differently by bash, bash 3.2 and zsh: anything but a
|
|
2179
|
+
* simple escape, an octal escape, or `\x` with a hex digit. `\c`, `\u` and
|
|
2180
|
+
* `\U` always count, and so does a NUL with text after it, where bash ends
|
|
2181
|
+
* the word and zsh keeps the rest. A NUL that ends the word gives the same
|
|
2182
|
+
* argument in both; a heredoc delimiter checks for one itself. */
|
|
2183
|
+
function ansiCShellDependent(inner) {
|
|
2184
|
+
let index = 0;
|
|
2185
|
+
while (index < inner.length) {
|
|
2186
|
+
if (inner.charAt(index) !== "\\") {
|
|
2187
|
+
index += 1;
|
|
2188
|
+
continue;
|
|
2189
|
+
}
|
|
2190
|
+
const bash = decodeAnsiCEscape(inner, index, "bash");
|
|
2191
|
+
if (textAfterNul(bash.text, inner.slice(bash.end)) || bash.text !== decodeAnsiCEscape(inner, index, "zsh").text || bash.text !== decodeAnsiCEscape(inner, index, "bash32").text) return true;
|
|
2192
|
+
index = bash.end;
|
|
2193
|
+
}
|
|
2194
|
+
return false;
|
|
2195
|
+
}
|
|
2196
|
+
/** Whether an escape's `text` has a NUL with more text after it, in the
|
|
2197
|
+
* escape or in the `rest` of the word. */
|
|
2198
|
+
function textAfterNul(text, rest) {
|
|
2199
|
+
const nul = text.indexOf("\0");
|
|
2200
|
+
return nul !== -1 && (nul < text.length - 1 || rest !== "");
|
|
2201
|
+
}
|
|
2202
|
+
/** The value a `$'...'` word whose text between the quotes is `inner`, as
|
|
2203
|
+
* written, has in `dialect` as a command's argument: escapes decoded, cut
|
|
2204
|
+
* at the first NUL. In bash, unknown escapes and a bare `\x`, `\u` or `\U`
|
|
2205
|
+
* keep their backslash, and bash 3.2 also keeps it for every `\u` and
|
|
2206
|
+
* `\U`. */
|
|
2207
|
+
function decodeAnsiCWord(inner, dialect = "bash") {
|
|
2060
2208
|
let value = "";
|
|
2061
2209
|
let index = 0;
|
|
2062
2210
|
while (index < inner.length) {
|
|
@@ -2065,101 +2213,51 @@ function decodeAnsiCWord(inner) {
|
|
|
2065
2213
|
index += 1;
|
|
2066
2214
|
continue;
|
|
2067
2215
|
}
|
|
2068
|
-
const decoded = decodeAnsiCEscape(inner, index);
|
|
2216
|
+
const decoded = decodeAnsiCEscape(inner, index, dialect);
|
|
2069
2217
|
value += decoded.text;
|
|
2070
2218
|
index = decoded.end;
|
|
2071
2219
|
}
|
|
2072
|
-
|
|
2073
|
-
return nul === -1 ? value : value.slice(0, nul);
|
|
2220
|
+
return value.split("\0", 1).join("");
|
|
2074
2221
|
}
|
|
2075
|
-
const HEX_DIGITS = /* @__PURE__ */ new Map([
|
|
2076
|
-
["x", /[0-9a-f]{1,2}/iy],
|
|
2077
|
-
["u", /[0-9a-f]{1,4}/iy],
|
|
2078
|
-
["U", /[0-9a-f]{1,8}/iy]
|
|
2079
|
-
]);
|
|
2080
|
-
const OCTAL_DIGITS = /[0-7]{1,3}/y;
|
|
2081
2222
|
/** The decoded escape whose backslash is at `index`, and the index just past it. */
|
|
2082
|
-
function decodeAnsiCEscape(inner, index) {
|
|
2223
|
+
function decodeAnsiCEscape(inner, index, dialect) {
|
|
2083
2224
|
const escaped = inner.charAt(index + 1);
|
|
2084
2225
|
const simple = ANSI_C_SIMPLE_ESCAPES[escaped];
|
|
2085
2226
|
if (simple !== void 0) return {
|
|
2086
2227
|
text: simple,
|
|
2087
2228
|
end: index + 2
|
|
2088
2229
|
};
|
|
2089
|
-
if (/^[0-7]$/.test(escaped))
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
end: index + 1 + digits.length
|
|
2095
|
-
};
|
|
2096
|
-
}
|
|
2097
|
-
if (escaped === "c") return decodeAnsiCControl(inner, index);
|
|
2098
|
-
const hex = HEX_DIGITS.get(escaped);
|
|
2099
|
-
if (hex !== void 0) return decodeAnsiCHex(inner, index, escaped, hex);
|
|
2230
|
+
if (/^[0-7]$/.test(escaped)) return decodeAnsiCOctal(inner, index);
|
|
2231
|
+
if (escaped === "c" && dialect !== "zsh") return decodeAnsiCControl(inner, index, dialect);
|
|
2232
|
+
const decoded = (dialect !== "bash32" || escaped === "x") && decodeAnsiCHex(inner, index, escaped);
|
|
2233
|
+
if (decoded) return decoded;
|
|
2234
|
+
if (dialect === "zsh") return decodeZshOther(inner, index, escaped, (text, at) => decodeAnsiCEscape(text, at, "zsh"));
|
|
2100
2235
|
return {
|
|
2101
2236
|
text: `\\${escaped}`,
|
|
2102
2237
|
end: index + 2
|
|
2103
2238
|
};
|
|
2104
2239
|
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
end: index + 2
|
|
2110
|
-
};
|
|
2111
|
-
const end = index + 2 + digits.length;
|
|
2112
|
-
const value = Number.parseInt(digits, 16);
|
|
2113
|
-
if (letter === "x") return {
|
|
2114
|
-
text: String.fromCharCode(value),
|
|
2115
|
-
end
|
|
2116
|
-
};
|
|
2117
|
-
return {
|
|
2118
|
-
text: codePointText(value),
|
|
2119
|
-
end
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
/** The text bash gives a `\u` or `\U` code point. Values above 0x7fffffff
|
|
2123
|
-
* are dropped; surrogates and values past U+10FFFF are not JavaScript code
|
|
2124
|
-
* points and become U+FFFD. */
|
|
2125
|
-
function codePointText(value) {
|
|
2126
|
-
if (value > 2147483647) return "";
|
|
2127
|
-
if (value >= 55296 && value <= 57343 || value > 1114111) return "�";
|
|
2128
|
-
return String.fromCodePoint(value);
|
|
2129
|
-
}
|
|
2130
|
-
/** `\cX` is the control character of X, `\c?` is DEL, and `\c\\` is the
|
|
2131
|
-
* control character of a backslash. */
|
|
2132
|
-
function decodeAnsiCControl(inner, index) {
|
|
2133
|
-
const target = inner.charAt(index + 2);
|
|
2134
|
-
if (target === "") return {
|
|
2135
|
-
text: "\\c",
|
|
2136
|
-
end: index + 2
|
|
2137
|
-
};
|
|
2138
|
-
if (target === "\\") return {
|
|
2139
|
-
text: "",
|
|
2140
|
-
end: inner.charAt(index + 3) === "\\" ? index + 4 : index + 3
|
|
2141
|
-
};
|
|
2142
|
-
const code = target === "?" ? 127 : target.charCodeAt(0) & 31;
|
|
2143
|
-
return {
|
|
2144
|
-
text: String.fromCharCode(code),
|
|
2145
|
-
end: index + 3
|
|
2146
|
-
};
|
|
2240
|
+
// src/modules/analysis/shell/shell-lex-state.ts
|
|
2241
|
+
/** Whether the reading is `finder` with only a `$'…'` word's value changed. */
|
|
2242
|
+
function readsAsFinder(quoting = "bash") {
|
|
2243
|
+
return quoting === "finder" || quoting === "zsh" || quoting === "bash32";
|
|
2147
2244
|
}
|
|
2148
|
-
/** The
|
|
2149
|
-
function
|
|
2150
|
-
|
|
2151
|
-
return pattern.exec(text)?.[0] ?? "";
|
|
2245
|
+
/** The dialect a reading decodes a `$'…'` word in. */
|
|
2246
|
+
function ansiCDialectOf(quoting = "bash") {
|
|
2247
|
+
return quoting === "zsh" || quoting === "bash32" ? quoting : "bash";
|
|
2152
2248
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2249
|
+
/** Whether the reading has bash's quote structure: `$'…'` strings and the
|
|
2250
|
+
* quote spans that follow from it. The readings that read as `finder` does
|
|
2251
|
+
* differ from `bash` only in how an escape decodes. */
|
|
2155
2252
|
function readsBashQuotes(quoting = "bash") {
|
|
2156
|
-
return quoting === "bash" || quoting === "rescan" || quoting
|
|
2253
|
+
return quoting === "bash" || quoting === "rescan" || readsAsFinder(quoting);
|
|
2157
2254
|
}
|
|
2158
|
-
/** The substitution scan a reading uses. Only `bash` and
|
|
2159
|
-
* where the shell does, and their outer
|
|
2160
|
-
*
|
|
2255
|
+
/** The substitution scan a reading uses. Only `bash` and the readings that
|
|
2256
|
+
* read as `finder` does end a body where the shell does, and their outer
|
|
2257
|
+
* scan then jumps past the body; every other reading ends it where the
|
|
2258
|
+
* previous release did and walks it again. */
|
|
2161
2259
|
function substitutionScanOf(quoting = "bash") {
|
|
2162
|
-
return quoting === "bash" || quoting
|
|
2260
|
+
return quoting === "bash" || readsAsFinder(quoting) ? "bash" : "previous";
|
|
2163
2261
|
}
|
|
2164
2262
|
/** Ceiling on the substitution text one scan re-lexes by default: nested
|
|
2165
2263
|
* substitutions re-lex their body once per level. */
|
|
@@ -2211,7 +2309,7 @@ function lastValueChar(lex) {
|
|
|
2211
2309
|
* joins the value as quoted text. Nothing was collected under the
|
|
2212
2310
|
* `undecoded` reading, which appends the text as it scans. */
|
|
2213
2311
|
function closeAnsiC(lex) {
|
|
2214
|
-
appendValue(lex, decodeAnsiCWord(lex.ansiCText), true);
|
|
2312
|
+
appendValue(lex, decodeAnsiCWord(lex.ansiCText, ansiCDialectOf(lex.budget.quoting)), true);
|
|
2215
2313
|
lex.ansiCText = "";
|
|
2216
2314
|
lex.ansiC = false;
|
|
2217
2315
|
}
|
|
@@ -2509,6 +2607,7 @@ function consumeBodies(scan, bodyStart, lineEnd) {
|
|
|
2509
2607
|
const read = readBody(scan.command, position, start, bound);
|
|
2510
2608
|
position = read.position;
|
|
2511
2609
|
if (read.unterminated) scan.unterminated = true;
|
|
2610
|
+
noteDelimiter(scan, start);
|
|
2512
2611
|
const record = bodyRecord(scan.command, start, read, lineEnd, targets);
|
|
2513
2612
|
if (record.dynamic) scan.hasDynamicConstructs = true;
|
|
2514
2613
|
keepBody(scan.bodies, start, read, record.sha256);
|
|
@@ -2520,6 +2619,10 @@ function consumeBodies(scan, bodyStart, lineEnd) {
|
|
|
2520
2619
|
scan.pieces = [];
|
|
2521
2620
|
return position;
|
|
2522
2621
|
}
|
|
2622
|
+
function noteDelimiter(scan, start) {
|
|
2623
|
+
if (!start.resolved) scan.delimiterUnresolved = true;
|
|
2624
|
+
if (start.shellDependent) scan.delimiterShellDependent = true;
|
|
2625
|
+
}
|
|
2523
2626
|
/** Keeps what one read body gives the collector: the commands its
|
|
2524
2627
|
* substitutions run, when its delimiter is unquoted, and the text the command
|
|
2525
2628
|
* that reads it gets, when it has its terminator line. */
|
|
@@ -2573,8 +2676,10 @@ function scanSingleQuoted(command, scan) {
|
|
|
2573
2676
|
scan.index = end + 1;
|
|
2574
2677
|
return true;
|
|
2575
2678
|
}
|
|
2576
|
-
/** `$'...'` is unescaped here
|
|
2577
|
-
* the
|
|
2679
|
+
/** `$'...'` is unescaped here. A part with an escape the shells read
|
|
2680
|
+
* differently, or with a NUL (bash ends the delimiter there, zsh keeps it),
|
|
2681
|
+
* leaves the word unresolved and shell-dependent. For `$"..."` only the `$`
|
|
2682
|
+
* is consumed, and the double-quoted part follows. */
|
|
2578
2683
|
function scanDollarQuoted(command, scan) {
|
|
2579
2684
|
scan.quoted = true;
|
|
2580
2685
|
scan.sawAny = true;
|
|
@@ -2587,6 +2692,10 @@ function scanDollarQuoted(command, scan) {
|
|
|
2587
2692
|
scan.resolved = false;
|
|
2588
2693
|
return false;
|
|
2589
2694
|
}
|
|
2695
|
+
if (ansiCShellDependent(command.slice(scan.index + 2, parsed.end - 1)) || parsed.text.includes("\0")) {
|
|
2696
|
+
scan.resolved = false;
|
|
2697
|
+
scan.shellDependent = true;
|
|
2698
|
+
}
|
|
2590
2699
|
scan.delimiter += parsed.text;
|
|
2591
2700
|
scan.index = parsed.end;
|
|
2592
2701
|
return true;
|
|
@@ -2658,14 +2767,16 @@ const BARE_WORD_STOP = /* @__PURE__ */ new Set([
|
|
|
2658
2767
|
* inside a backtick substitution, which the shell cuts out before it reads
|
|
2659
2768
|
* the operator's word. A bare carriage return ends the word when
|
|
2660
2769
|
* `stopAtCarriageReturn` is set, as the previous release read it.
|
|
2661
|
-
* The word is `resolved: false`
|
|
2662
|
-
*
|
|
2770
|
+
* The word is `resolved: false` when its quoting never terminates, the word
|
|
2771
|
+
* is empty, or a `$'...'` part is shell-dependent: then no line can be
|
|
2772
|
+
* proven to be the terminator. */
|
|
2663
2773
|
function parseDelimiterWord(command, start, options = {}) {
|
|
2664
2774
|
const scan = {
|
|
2665
2775
|
index: start,
|
|
2666
2776
|
delimiter: "",
|
|
2667
2777
|
quoted: false,
|
|
2668
2778
|
resolved: true,
|
|
2779
|
+
shellDependent: false,
|
|
2669
2780
|
sawAny: false
|
|
2670
2781
|
};
|
|
2671
2782
|
while (scan.index < command.length) {
|
|
@@ -2678,13 +2789,15 @@ function parseDelimiterWord(command, start, options = {}) {
|
|
|
2678
2789
|
wordEnd: start,
|
|
2679
2790
|
delimiter: "",
|
|
2680
2791
|
quoted: false,
|
|
2681
|
-
resolved: false
|
|
2792
|
+
resolved: false,
|
|
2793
|
+
shellDependent: false
|
|
2682
2794
|
};
|
|
2683
2795
|
return {
|
|
2684
2796
|
wordEnd: scan.index,
|
|
2685
2797
|
delimiter: scan.delimiter,
|
|
2686
2798
|
quoted: scan.quoted,
|
|
2687
|
-
resolved: scan.resolved
|
|
2799
|
+
resolved: scan.resolved,
|
|
2800
|
+
shellDependent: scan.shellDependent
|
|
2688
2801
|
};
|
|
2689
2802
|
}
|
|
2690
2803
|
/** Consume the word part at `scan.index`. Returns false when the word ends
|
|
@@ -3094,6 +3207,7 @@ function scanHeredocOperator(scan) {
|
|
|
3094
3207
|
rawWord: command.slice(j, word.wordEnd),
|
|
3095
3208
|
quoted: word.quoted,
|
|
3096
3209
|
resolved: word.resolved,
|
|
3210
|
+
shellDependent: word.shellDependent,
|
|
3097
3211
|
opStart: i,
|
|
3098
3212
|
wordEnd: word.wordEnd,
|
|
3099
3213
|
lineStart: scan.lineStart,
|
|
@@ -3114,6 +3228,8 @@ function legacySanitizedCommand(command) {
|
|
|
3114
3228
|
hasDynamicConstructs: false,
|
|
3115
3229
|
unterminated: false,
|
|
3116
3230
|
framed: false,
|
|
3231
|
+
delimiterUnresolved: false,
|
|
3232
|
+
delimiterShellDependent: false,
|
|
3117
3233
|
out: "",
|
|
3118
3234
|
cursor: 0,
|
|
3119
3235
|
i: 0,
|
|
@@ -3189,6 +3305,8 @@ function extractHeredocs(command, options = {}) {
|
|
|
3189
3305
|
hasDynamicConstructs: false,
|
|
3190
3306
|
unterminated: false,
|
|
3191
3307
|
framed: false,
|
|
3308
|
+
delimiterUnresolved: false,
|
|
3309
|
+
delimiterShellDependent: false,
|
|
3192
3310
|
out: "",
|
|
3193
3311
|
cursor: 0,
|
|
3194
3312
|
i: 0,
|
|
@@ -3211,6 +3329,8 @@ function extractHeredocs(command, options = {}) {
|
|
|
3211
3329
|
return {
|
|
3212
3330
|
unterminated: scan.unterminated,
|
|
3213
3331
|
framed: scan.framed,
|
|
3332
|
+
delimiterUnresolved: scan.delimiterUnresolved,
|
|
3333
|
+
delimiterShellDependent: scan.delimiterShellDependent,
|
|
3214
3334
|
sanitizedCommand: scan.out,
|
|
3215
3335
|
heredocs: scan.heredocs,
|
|
3216
3336
|
hasDynamicConstructs: scan.hasDynamicConstructs,
|
|
@@ -3223,6 +3343,8 @@ function unchanged(command) {
|
|
|
3223
3343
|
return {
|
|
3224
3344
|
unterminated: false,
|
|
3225
3345
|
framed: false,
|
|
3346
|
+
delimiterUnresolved: false,
|
|
3347
|
+
delimiterShellDependent: false,
|
|
3226
3348
|
sanitizedCommand: command,
|
|
3227
3349
|
heredocs: [],
|
|
3228
3350
|
hasDynamicConstructs: false,
|
|
@@ -3262,7 +3384,8 @@ function sanitizedText(text) {
|
|
|
3262
3384
|
return {
|
|
3263
3385
|
text: extraction.sanitizedCommand,
|
|
3264
3386
|
bodyCommands: extraction.bodyCommands,
|
|
3265
|
-
bodyUnresolved: extraction.bodyUnresolved,
|
|
3387
|
+
bodyUnresolved: extraction.bodyUnresolved || extraction.delimiterUnresolved,
|
|
3388
|
+
delimiterShellDependent: extraction.delimiterShellDependent,
|
|
3266
3389
|
scripts: extraction.scripts
|
|
3267
3390
|
};
|
|
3268
3391
|
}
|
|
@@ -3613,7 +3736,7 @@ function advance(scan) {
|
|
|
3613
3736
|
scan.index += 1;
|
|
3614
3737
|
return false;
|
|
3615
3738
|
}
|
|
3616
|
-
function open$
|
|
3739
|
+
function open$1(scan, frame, width) {
|
|
3617
3740
|
scan.frames.push(frame);
|
|
3618
3741
|
scan.starts.push(scan.index);
|
|
3619
3742
|
scan.prefix = void 0;
|
|
@@ -3637,8 +3760,8 @@ function close$1(scan) {
|
|
|
3637
3760
|
}
|
|
3638
3761
|
function stepCommand(scan, c, insideCase) {
|
|
3639
3762
|
if (c === ")" || c === "(") return stepParenthesis(scan, c, insideCase);
|
|
3640
|
-
if (c === "\"") return open$
|
|
3641
|
-
if (c === "`") return open$
|
|
3763
|
+
if (c === "\"") return open$1(scan, "double", 1);
|
|
3764
|
+
if (c === "`") return open$1(scan, "backtick", 1);
|
|
3642
3765
|
if (c === "'" || c === "$" && scan.text[scan.index + 1] === "'") {
|
|
3643
3766
|
skipSingleQuoted(scan, c === "$");
|
|
3644
3767
|
return false;
|
|
@@ -3663,7 +3786,7 @@ function stepParenthesis(scan, c, insideCase) {
|
|
|
3663
3786
|
/** A `(` opens a subshell, unless it is the `()` of a function header. */
|
|
3664
3787
|
function openParenthesis(scan) {
|
|
3665
3788
|
const end = scan.mode === "bash" ? functionHeaderEnd(scan) : -1;
|
|
3666
|
-
if (end < 0) return open$
|
|
3789
|
+
if (end < 0) return open$1(scan, "command", 1);
|
|
3667
3790
|
scan.index = end;
|
|
3668
3791
|
scan.headStart = -1;
|
|
3669
3792
|
scan.commandPosition = true;
|
|
@@ -3672,7 +3795,7 @@ function openParenthesis(scan) {
|
|
|
3672
3795
|
/** `${` opens an expansion that holds a `)` as text; `$$` is one parameter. */
|
|
3673
3796
|
function stepDollar$2(scan) {
|
|
3674
3797
|
const next = scan.text[scan.index + 1];
|
|
3675
|
-
if (next === "{") return open$
|
|
3798
|
+
if (next === "{") return open$1(scan, "brace", 2);
|
|
3676
3799
|
scan.commandPosition = false;
|
|
3677
3800
|
scan.index += next === "$" ? 2 : 1;
|
|
3678
3801
|
return false;
|
|
@@ -3697,8 +3820,8 @@ function stepBrace$1(scan, c) {
|
|
|
3697
3820
|
/** It ends at `closer`; substitutions inside open frames of their own. */
|
|
3698
3821
|
function stepQuoted$1(scan, c, closer, singleQuotes) {
|
|
3699
3822
|
if (c === closer) return close$1(scan);
|
|
3700
|
-
if (c === "\"") return open$
|
|
3701
|
-
if (c === "`") return open$
|
|
3823
|
+
if (c === "\"") return open$1(scan, "double", 1);
|
|
3824
|
+
if (c === "`") return open$1(scan, "backtick", 1);
|
|
3702
3825
|
if (c === "'" && singleQuotes) return skip(scan, false);
|
|
3703
3826
|
return c === "$" ? stepDollar$1(scan, singleQuotes) : advance(scan);
|
|
3704
3827
|
}
|
|
@@ -3707,11 +3830,11 @@ function stepQuoted$1(scan, c, closer, singleQuotes) {
|
|
|
3707
3830
|
function stepDollar$1(scan, singleQuotes) {
|
|
3708
3831
|
const next = scan.text[scan.index + 1];
|
|
3709
3832
|
if (next !== "(") return stepParameter(scan, next, singleQuotes);
|
|
3710
|
-
return open$
|
|
3833
|
+
return open$1(scan, scan.mode === "bash" && scan.text[scan.index + 2] === "(" ? "arith" : "command", 2);
|
|
3711
3834
|
}
|
|
3712
3835
|
function stepParameter(scan, next, singleQuotes) {
|
|
3713
3836
|
if (scan.mode !== "bash") return advance(scan);
|
|
3714
|
-
if (next === "{") return open$
|
|
3837
|
+
if (next === "{") return open$1(scan, "brace", 2);
|
|
3715
3838
|
if (next === "$") scan.index += 1;
|
|
3716
3839
|
else if (next === "'" && singleQuotes) return skip(scan, true);
|
|
3717
3840
|
return advance(scan);
|
|
@@ -3991,14 +4114,14 @@ function openGroup(scan, c) {
|
|
|
3991
4114
|
if (!scan.commandPosition && !dollar && scan.words !== "forName") return void 0;
|
|
3992
4115
|
if (!dollar && !closesAsArithmetic(text, index, scan.probes)) return void 0;
|
|
3993
4116
|
const forLoop = scan.words === "forName";
|
|
3994
|
-
open$
|
|
3995
|
-
open$
|
|
4117
|
+
open$1(scan, "arith", 1);
|
|
4118
|
+
open$1(scan, "arith", 1);
|
|
3996
4119
|
scan.commandPosition = false;
|
|
3997
4120
|
if (forLoop) scan.saved[scan.saved.length - 2] = ["forAfterName", void 0];
|
|
3998
4121
|
return false;
|
|
3999
4122
|
}
|
|
4000
4123
|
function openArray(scan) {
|
|
4001
|
-
open$
|
|
4124
|
+
open$1(scan, "array", 1);
|
|
4002
4125
|
scan.commandPosition = false;
|
|
4003
4126
|
return false;
|
|
4004
4127
|
}
|
|
@@ -4006,7 +4129,7 @@ function openTest(scan) {
|
|
|
4006
4129
|
const { text, index } = scan;
|
|
4007
4130
|
if (!scan.commandPosition || !text.startsWith("[[", index)) return void 0;
|
|
4008
4131
|
if (!/\s/.test(text.charAt(index + 2))) return void 0;
|
|
4009
|
-
open$
|
|
4132
|
+
open$1(scan, "test", 2);
|
|
4010
4133
|
scan.commandPosition = false;
|
|
4011
4134
|
return false;
|
|
4012
4135
|
}
|
|
@@ -4020,7 +4143,7 @@ function stepArith(scan, c) {
|
|
|
4020
4143
|
const group = c === "(" ? openGroup(scan, c) : void 0;
|
|
4021
4144
|
if (group !== void 0) return group;
|
|
4022
4145
|
if (c === "(" && scan.text[scan.index - 1] !== "$") {
|
|
4023
|
-
open$
|
|
4146
|
+
open$1(scan, "arith", 1);
|
|
4024
4147
|
scan.commandPosition = false;
|
|
4025
4148
|
return false;
|
|
4026
4149
|
}
|
|
@@ -4093,12 +4216,12 @@ function substitutionBodyEnd(text, start, opener, reading = "default", mode = "b
|
|
|
4093
4216
|
escapedEnd: -1,
|
|
4094
4217
|
probes
|
|
4095
4218
|
};
|
|
4096
|
-
while (scan.index < text.length) if (step$
|
|
4219
|
+
while (scan.index < text.length) if (step$2(scan)) return scan.index;
|
|
4097
4220
|
return text.length;
|
|
4098
4221
|
}
|
|
4099
4222
|
/** Advance past one character or construct; true once the opener's frame
|
|
4100
4223
|
* closes at `scan.index`. */
|
|
4101
|
-
function step$
|
|
4224
|
+
function step$2(scan) {
|
|
4102
4225
|
const c = scan.text.charAt(scan.index);
|
|
4103
4226
|
if (c === "\\") {
|
|
4104
4227
|
const joins = scan.mode === "bash" && scan.text[scan.index + 1] === "\n";
|
|
@@ -4170,6 +4293,7 @@ function commandBody(text, end, reading, sanitize) {
|
|
|
4170
4293
|
text: sanitize ? legacySanitizedCommand(text) : text,
|
|
4171
4294
|
bodyCommands: [],
|
|
4172
4295
|
bodyUnresolved: false,
|
|
4296
|
+
delimiterShellDependent: false,
|
|
4173
4297
|
scripts: NO_SCRIPTS,
|
|
4174
4298
|
end
|
|
4175
4299
|
};
|
|
@@ -4179,6 +4303,7 @@ function commandBody(text, end, reading, sanitize) {
|
|
|
4179
4303
|
text: read.text,
|
|
4180
4304
|
bodyCommands: read.bodyCommands,
|
|
4181
4305
|
bodyUnresolved: read.bodyUnresolved,
|
|
4306
|
+
delimiterShellDependent: read.delimiterShellDependent,
|
|
4182
4307
|
scripts: read.scripts,
|
|
4183
4308
|
end
|
|
4184
4309
|
};
|
|
@@ -4269,10 +4394,10 @@ function stepFrame(scan, index) {
|
|
|
4269
4394
|
* every other character plain. */
|
|
4270
4395
|
function stepCount(scan, index) {
|
|
4271
4396
|
const c = scan.text.charAt(index);
|
|
4272
|
-
if (c === "(") return open
|
|
4397
|
+
if (c === "(") return open(scan, "count", index + 1);
|
|
4273
4398
|
if (c === ")") return close(scan, index);
|
|
4274
4399
|
if (c === "\\") return index + 2;
|
|
4275
|
-
if (c === "\"") return open
|
|
4400
|
+
if (c === "\"") return open(scan, "double", index + 1);
|
|
4276
4401
|
if (c !== "'") return index + 1;
|
|
4277
4402
|
const end = scan.text.indexOf("'", index + 1);
|
|
4278
4403
|
return end < 0 ? -1 : end + 1;
|
|
@@ -4290,7 +4415,7 @@ function stepParen(scan, index) {
|
|
|
4290
4415
|
return index + 1;
|
|
4291
4416
|
}
|
|
4292
4417
|
if (c === "\\" || c === "") return index + 2;
|
|
4293
|
-
if (c === "(" || c === "$" && text.charAt(index + 1) === "(") return open
|
|
4418
|
+
if (c === "(" || c === "$" && text.charAt(index + 1) === "(") return open(scan, "paren", index + (c === "(" ? 1 : 2));
|
|
4294
4419
|
if (c === ")") return close(scan, index);
|
|
4295
4420
|
return stepQuoted(scan, index);
|
|
4296
4421
|
}
|
|
@@ -4311,7 +4436,7 @@ function stepBrace(scan, index) {
|
|
|
4311
4436
|
function stepQuoted(scan, index) {
|
|
4312
4437
|
const c = scan.text.charAt(index);
|
|
4313
4438
|
if (c === "`") return pastBacktick(scan.text, index);
|
|
4314
|
-
if (c === "\"") return open
|
|
4439
|
+
if (c === "\"") return open(scan, "double", index + 1);
|
|
4315
4440
|
if (c !== "'") return stepDollar(scan, index);
|
|
4316
4441
|
const end = scan.text.indexOf("'", index + 1);
|
|
4317
4442
|
return end < 0 ? -1 : end + 1;
|
|
@@ -4321,11 +4446,11 @@ function stepQuoted(scan, index) {
|
|
|
4321
4446
|
function stepDollar(scan, index) {
|
|
4322
4447
|
const next = scan.text.charAt(index + 1);
|
|
4323
4448
|
if (scan.text.charAt(index) !== "$") return index + 1;
|
|
4324
|
-
if (next === "(") return open
|
|
4325
|
-
if (next === "{" && scan.frames.at(-1) !== "paren") return open
|
|
4449
|
+
if (next === "(") return open(scan, "paren", index + 2);
|
|
4450
|
+
if (next === "{" && scan.frames.at(-1) !== "paren") return open(scan, "brace", index + 2);
|
|
4326
4451
|
return index + 1;
|
|
4327
4452
|
}
|
|
4328
|
-
function open
|
|
4453
|
+
function open(scan, frame, after) {
|
|
4329
4454
|
scan.frames.push(frame);
|
|
4330
4455
|
scan.starts.push(after);
|
|
4331
4456
|
return after;
|
|
@@ -4553,7 +4678,7 @@ function scanBody(text) {
|
|
|
4553
4678
|
ends: /* @__PURE__ */ new Map()
|
|
4554
4679
|
};
|
|
4555
4680
|
let index = 0;
|
|
4556
|
-
while (index < text.length && !scan.unresolved) index = step(scan, index);
|
|
4681
|
+
while (index < text.length && !scan.unresolved) index = step$1(scan, index);
|
|
4557
4682
|
if (scan.unresolved) return {
|
|
4558
4683
|
commands: scan.commands,
|
|
4559
4684
|
unresolved: true
|
|
@@ -4570,7 +4695,7 @@ function scanBody(text) {
|
|
|
4570
4695
|
};
|
|
4571
4696
|
}
|
|
4572
4697
|
/** The index after the character or construct at `index`. */
|
|
4573
|
-
function step(scan, index) {
|
|
4698
|
+
function step$1(scan, index) {
|
|
4574
4699
|
const after = bodyTextStep(scan.text, index);
|
|
4575
4700
|
return after < 0 ? substitute(scan, index) : after;
|
|
4576
4701
|
}
|
|
@@ -4605,12 +4730,14 @@ function keepCommand(scan, found, backtick) {
|
|
|
4605
4730
|
scan.unresolved ||= read.bodyUnresolved;
|
|
4606
4731
|
}
|
|
4607
4732
|
// src/modules/analysis/capability/heredoc/heredoc-body-collector.ts
|
|
4608
|
-
/** Adds commands to `into`, with whether their bodies were unresolved
|
|
4609
|
-
*
|
|
4610
|
-
|
|
4733
|
+
/** Adds commands to `into`, with whether their bodies were unresolved and
|
|
4734
|
+
* whether a delimiter of theirs was shell-dependent. A collector that is not
|
|
4735
|
+
* there is a reading that keeps none. */
|
|
4736
|
+
function keepBodyCommands(into, commands, unresolved, shellDependent = false) {
|
|
4611
4737
|
if (into === void 0 || commands.length === 0 && !unresolved) return;
|
|
4612
4738
|
for (const command of commands) into.commands.push(command);
|
|
4613
4739
|
into.unresolved ||= unresolved;
|
|
4740
|
+
if (shellDependent) into.shellDependent = true;
|
|
4614
4741
|
}
|
|
4615
4742
|
/** Adds the commands of one unquoted body to `into`, with the scripts of the
|
|
4616
4743
|
* heredocs in them. */
|
|
@@ -4658,7 +4785,7 @@ function uncertainRegion(lex, from, to) {
|
|
|
4658
4785
|
if (pair < to && nextMark(marks, 2, pair, () => commentFrom(text, pair)) < to) return true;
|
|
4659
4786
|
const open = nextMark(marks, 3, from, () => find(text, "$(", from));
|
|
4660
4787
|
if (open < to && nextMark(marks, 4, open, () => closingComment(text, open)) < to) return true;
|
|
4661
|
-
if (lex.budget.quoting
|
|
4788
|
+
if (readsAsFinder(lex.budget.quoting)) return false;
|
|
4662
4789
|
if (nextMark(marks, 5, from, () => find(text, "<<", from)) >= to) return false;
|
|
4663
4790
|
return nextMark(marks, 7, from, () => heredocGroupFrom(lex, from)) < to;
|
|
4664
4791
|
}
|
|
@@ -4743,7 +4870,7 @@ function commentStart(text, at) {
|
|
|
4743
4870
|
* the same budget, and keep the commands its heredocs run. */
|
|
4744
4871
|
function lexBody(lex, budget, body) {
|
|
4745
4872
|
const { text, end } = body;
|
|
4746
|
-
keepBodyCommands(budget.bodies, body.bodyCommands, body.bodyUnresolved);
|
|
4873
|
+
keepBodyCommands(budget.bodies, body.bodyCommands, body.bodyUnresolved, body.delimiterShellDependent);
|
|
4747
4874
|
keepBodyScripts(budget.bodies, body.scripts);
|
|
4748
4875
|
lex.substitutionEnd = end;
|
|
4749
4876
|
budget.substitutionCharsRemaining -= text.length;
|
|
@@ -4998,6 +5125,7 @@ function lexSegmentsBounded(command, reading = "default", quoting = "bash") {
|
|
|
4998
5125
|
truncated: true,
|
|
4999
5126
|
bodyCommands: [],
|
|
5000
5127
|
bodyUnresolved: false,
|
|
5128
|
+
delimiterShellDependent: false,
|
|
5001
5129
|
scripts: NO_SCRIPTS
|
|
5002
5130
|
};
|
|
5003
5131
|
const bodies = {
|
|
@@ -5017,6 +5145,7 @@ function lexSegmentsBounded(command, reading = "default", quoting = "bash") {
|
|
|
5017
5145
|
truncated: state.tokensRemaining <= 0,
|
|
5018
5146
|
bodyCommands: bodies.commands,
|
|
5019
5147
|
bodyUnresolved: bodies.unresolved,
|
|
5148
|
+
delimiterShellDependent: bodies.shellDependent === true,
|
|
5020
5149
|
scripts: bodies.scripts ?? NO_SCRIPTS
|
|
5021
5150
|
};
|
|
5022
5151
|
}
|
|
@@ -5647,14 +5776,15 @@ function analysisWarnings(parsed, heredocTruncated) {
|
|
|
5647
5776
|
if (parsed.heredocs.some((h) => h.dynamic)) warnings.push("one or more heredoc bodies have unresolvable expansion");
|
|
5648
5777
|
if (heredocTruncated) warnings.push("one or more heredoc bodies were truncated or never terminated");
|
|
5649
5778
|
if (parsed.analysisTruncated) warnings.push("command structure exceeded the static analysis depth or expansion budget");
|
|
5779
|
+
if (parsed.shellDependentQuoting) warnings.push("command contains a $'…' escape whose value depends on the shell");
|
|
5650
5780
|
return warnings;
|
|
5651
5781
|
}
|
|
5652
5782
|
function parserCompleteness(parsed, heredocTruncated) {
|
|
5653
5783
|
if (parsed.hasDynamicConstructs) return hasCommandSubstitution(parsed.sanitizedCommand) || parsed.heredocs.some((h) => h.dynamic) ? "opaque" : "partial";
|
|
5654
|
-
return parsed.analysisTruncated || heredocTruncated ? "partial" : "complete-for-supported-form";
|
|
5784
|
+
return parsed.analysisTruncated || heredocTruncated || parsed.shellDependentQuoting ? "partial" : "complete-for-supported-form";
|
|
5655
5785
|
}
|
|
5656
|
-
function summaryOf(facts) {
|
|
5657
|
-
const summaryParts = [
|
|
5786
|
+
function summaryOf(facts, actionClass) {
|
|
5787
|
+
const summaryParts = [actionClass];
|
|
5658
5788
|
if (facts.createsAdHocCode) summaryParts.push("ad-hoc code");
|
|
5659
5789
|
if (facts.executesRepositoryCode) summaryParts.push("repository code");
|
|
5660
5790
|
if (facts.invokesPackageLifecycle) summaryParts.push("package lifecycle scripts");
|
|
@@ -5664,17 +5794,24 @@ function summaryOf(facts) {
|
|
|
5664
5794
|
if (facts.privilegeEscalation) summaryParts.push("privilege escalation");
|
|
5665
5795
|
return summaryParts.join(", ");
|
|
5666
5796
|
}
|
|
5797
|
+
/** The class the facts give. A shell-dependent word can hide an effect the
|
|
5798
|
+
* facts missed, so it turns `read-only` into `unknown`; any other class
|
|
5799
|
+
* stays, so a rule that matches it still does. */
|
|
5800
|
+
function actionClassOf(parsed, facts) {
|
|
5801
|
+
return parsed.shellDependentQuoting && facts.dominantClass === "read-only" ? "unknown" : facts.dominantClass;
|
|
5802
|
+
}
|
|
5667
5803
|
function assessmentFrom(parsed, facts) {
|
|
5804
|
+
const actionClass = actionClassOf(parsed, facts);
|
|
5668
5805
|
const heredocTruncated = parsed.heredocs.some((h) => h.truncated);
|
|
5669
5806
|
const warnings = analysisWarnings(parsed, heredocTruncated);
|
|
5670
5807
|
const networkPossible = facts.networkObserved || facts.networkPossible;
|
|
5671
5808
|
return {
|
|
5672
5809
|
actionClass: {
|
|
5673
|
-
value:
|
|
5810
|
+
value: actionClass,
|
|
5674
5811
|
source: "static-analysis",
|
|
5675
|
-
confidence: facts.classConfidence
|
|
5812
|
+
confidence: parsed.shellDependentQuoting ? "low" : facts.classConfidence
|
|
5676
5813
|
},
|
|
5677
|
-
summary: summaryOf(facts),
|
|
5814
|
+
summary: summaryOf(facts, actionClass),
|
|
5678
5815
|
executesCode: staticFlag(facts.executesCode),
|
|
5679
5816
|
executesRepositoryCode: staticFlag(facts.executesRepositoryCode),
|
|
5680
5817
|
createsAdHocCode: staticFlag(facts.createsAdHocCode),
|
|
@@ -5713,13 +5850,275 @@ function assessmentFrom(parsed, facts) {
|
|
|
5713
5850
|
analysisWarnings: warnings
|
|
5714
5851
|
};
|
|
5715
5852
|
}
|
|
5853
|
+
// src/modules/analysis/capability/getopt-long-option.ts
|
|
5854
|
+
/** A getopt_long option word: `--name` or `--name=value`, where `name` may be
|
|
5855
|
+
* any unambiguous prefix of the full option name. `minimum` is the length of
|
|
5856
|
+
* the shortest such prefix, `--` included, so a shorter prefix that another
|
|
5857
|
+
* option of the same tool shares never matches. */
|
|
5858
|
+
function longOption$1(value, name, minimum) {
|
|
5859
|
+
if (!value.startsWith("--")) return void 0;
|
|
5860
|
+
const equals = value.indexOf("=");
|
|
5861
|
+
const word = equals === -1 ? value : value.slice(0, equals);
|
|
5862
|
+
if (word.length < minimum || !name.startsWith(word)) return void 0;
|
|
5863
|
+
return equals === -1 ? {} : { inline: value.slice(equals + 1) };
|
|
5864
|
+
}
|
|
5865
|
+
// src/modules/analysis/capability/output-operand-mutations.ts
|
|
5866
|
+
/** uniq's long options with a required value, with the length of each one's
|
|
5867
|
+
* shortest unambiguous prefix. */
|
|
5868
|
+
const UNIQ_VALUED_LONG = [
|
|
5869
|
+
["--skip-fields", 8],
|
|
5870
|
+
["--skip-chars", 8],
|
|
5871
|
+
["--check-chars", 4]
|
|
5872
|
+
];
|
|
5873
|
+
const UNIQ_OPTIONS = {
|
|
5874
|
+
takesNextWord(value) {
|
|
5875
|
+
if (value.startsWith("--")) return !value.includes("=") && UNIQ_VALUED_LONG.some(([name, minimum]) => longOption$1(value, name, minimum) !== void 0);
|
|
5876
|
+
const at = value.slice(1).search(/[fsw]/);
|
|
5877
|
+
return at !== -1 && at + 2 === value.length;
|
|
5878
|
+
},
|
|
5879
|
+
permute: true
|
|
5880
|
+
};
|
|
5881
|
+
/** xxd's options that take a value, by letter, with the tails of their long
|
|
5882
|
+
* spellings (`-c`, `-cols`). Such a word takes the next word as its value;
|
|
5883
|
+
* any other text after the letter is the value itself (`-c8`). */
|
|
5884
|
+
const XXD_VALUED = /* @__PURE__ */ new Map([
|
|
5885
|
+
["c", ["ols"]],
|
|
5886
|
+
["g", ["roup"]],
|
|
5887
|
+
["o", ["ffset"]],
|
|
5888
|
+
["s", ["kip", "eek"]],
|
|
5889
|
+
["l", ["en"]],
|
|
5890
|
+
["n", ["ame"]],
|
|
5891
|
+
["R", []]
|
|
5892
|
+
]);
|
|
5893
|
+
const XXD_OPTIONS = {
|
|
5894
|
+
takesNextWord(value) {
|
|
5895
|
+
const word = value.startsWith("--") && value.length > 2 ? value.slice(1) : value;
|
|
5896
|
+
const rest = word.slice(2);
|
|
5897
|
+
if (word.charAt(1) === "c" && rest.startsWith("apitalize")) return false;
|
|
5898
|
+
const tails = XXD_VALUED.get(word.charAt(1));
|
|
5899
|
+
if (tails === void 0) return false;
|
|
5900
|
+
return rest === "" || tails.some((tail) => rest.startsWith(tail));
|
|
5901
|
+
},
|
|
5902
|
+
permute: false
|
|
5903
|
+
};
|
|
5904
|
+
/** `TOOL [OPTION]... [INPUT [OUTPUT]]` (uniq, xxd): a second operand is a file
|
|
5905
|
+
* the command writes ("-" is standard output). */
|
|
5906
|
+
function outputOperandMutation(cmd, tool) {
|
|
5907
|
+
const output = operandsOf(cmd, tool)[1];
|
|
5908
|
+
return output !== void 0 && output !== "-" ? { writeTargets: [output] } : void 0;
|
|
5909
|
+
}
|
|
5910
|
+
function operandsOf(cmd, tool) {
|
|
5911
|
+
const operands = [];
|
|
5912
|
+
let options = true;
|
|
5913
|
+
for (let index = 1; index < cmd.length; index += 1) {
|
|
5914
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
5915
|
+
if (options && value === "--") options = false;
|
|
5916
|
+
else if (options && value.startsWith("-") && value !== "-") {
|
|
5917
|
+
if (tool.takesNextWord(value)) index += 1;
|
|
5918
|
+
} else {
|
|
5919
|
+
operands.push(value);
|
|
5920
|
+
options &&= tool.permute;
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
return operands;
|
|
5924
|
+
}
|
|
5925
|
+
// src/modules/analysis/capability/sort-mutation.ts
|
|
5926
|
+
/** GNU sort short options that take a value. The value is the rest of the
|
|
5927
|
+
* cluster, or the next word when the letter ends it. */
|
|
5928
|
+
const SORT_VALUED_LETTERS = "kotST";
|
|
5929
|
+
/** GNU sort: `-o FILE` writes FILE and `--compress-program=PROG` runs PROG.
|
|
5930
|
+
* Short options cluster getopt-style (`-uo FILE`, `-nruoFILE`), and long
|
|
5931
|
+
* options may be abbreviated (`--out=FILE`). */
|
|
5932
|
+
function sortMutation(cmd) {
|
|
5933
|
+
const result = { writeTargets: [] };
|
|
5934
|
+
let index = 1;
|
|
5935
|
+
while (index < cmd.length) {
|
|
5936
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
5937
|
+
if (value === "--") break;
|
|
5938
|
+
index += value.startsWith("--") ? sortLongOption(cmd, index, result) : sortShortOptions(cmd, index, result);
|
|
5939
|
+
}
|
|
5940
|
+
return result.writeTargets.length > 0 || result.executesCode === true ? result : void 0;
|
|
5941
|
+
}
|
|
5942
|
+
/** Record a long option's effect; returns the words it spans. */
|
|
5943
|
+
function sortLongOption(cmd, index, result) {
|
|
5944
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
5945
|
+
const output = longOption$1(value, "--output", 3);
|
|
5946
|
+
if (output !== void 0) {
|
|
5947
|
+
const target = output.inline ?? cmd[index + 1]?.value;
|
|
5948
|
+
if (target !== void 0) result.writeTargets.push(target);
|
|
5949
|
+
return output.inline === void 0 ? 2 : 1;
|
|
5950
|
+
}
|
|
5951
|
+
if (longOption$1(value, "--compress-program", 4) !== void 0) result.executesCode = true;
|
|
5952
|
+
return 1;
|
|
5953
|
+
}
|
|
5954
|
+
/** Record a short-option cluster's output file; returns the words it spans. */
|
|
5955
|
+
function sortShortOptions(cmd, index, result) {
|
|
5956
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
5957
|
+
if (!value.startsWith("-") || value === "-") return 1;
|
|
5958
|
+
for (let at = 1; at < value.length; at += 1) {
|
|
5959
|
+
const letter = value.charAt(at);
|
|
5960
|
+
if (!SORT_VALUED_LETTERS.includes(letter)) continue;
|
|
5961
|
+
const attached = value.slice(at + 1);
|
|
5962
|
+
const argument = attached === "" ? cmd[index + 1]?.value : attached;
|
|
5963
|
+
if (letter === "o" && argument !== void 0) result.writeTargets.push(argument);
|
|
5964
|
+
return attached === "" ? 2 : 1;
|
|
5965
|
+
}
|
|
5966
|
+
return 1;
|
|
5967
|
+
}
|
|
5968
|
+
// src/modules/analysis/capability/tree-mutation.ts
|
|
5969
|
+
/** tree's short options whose value is the next unused word. `-L` also takes
|
|
5970
|
+
* its value as digits attached inside the cluster (`-L2`). */
|
|
5971
|
+
const TREE_VALUED_LETTERS = /* @__PURE__ */ new Set([
|
|
5972
|
+
"L",
|
|
5973
|
+
"P",
|
|
5974
|
+
"I",
|
|
5975
|
+
"H",
|
|
5976
|
+
"T",
|
|
5977
|
+
"o"
|
|
5978
|
+
]);
|
|
5979
|
+
/** tree's long options with a value, which is inline (`--sort=name`) or the
|
|
5980
|
+
* next word. tree matches each by prefix. */
|
|
5981
|
+
const TREE_VALUED_LONG = [
|
|
5982
|
+
"--authority",
|
|
5983
|
+
"--charset",
|
|
5984
|
+
"--compress",
|
|
5985
|
+
"--filelimit",
|
|
5986
|
+
"--gitfile",
|
|
5987
|
+
"--hintro",
|
|
5988
|
+
"--houtro",
|
|
5989
|
+
"--infofile",
|
|
5990
|
+
"--scheme",
|
|
5991
|
+
"--sort",
|
|
5992
|
+
"--timefmt"
|
|
5993
|
+
];
|
|
5994
|
+
/** tree: `-o FILE` writes FILE, and `-R` writes an `00Tree.html` listing into
|
|
5995
|
+
* each directory it visits. Options may follow the roots. */
|
|
5996
|
+
function treeMutation(cmd) {
|
|
5997
|
+
const scan = {
|
|
5998
|
+
roots: [],
|
|
5999
|
+
outputs: [],
|
|
6000
|
+
recursive: false
|
|
6001
|
+
};
|
|
6002
|
+
let index = 1;
|
|
6003
|
+
while (index < cmd.length) {
|
|
6004
|
+
if (elementAt(cmd, index, "cmd").value === "--") {
|
|
6005
|
+
scan.roots.push(...cmd.slice(index + 1).map((token) => token.value));
|
|
6006
|
+
break;
|
|
6007
|
+
}
|
|
6008
|
+
index += treeWord(cmd, index, scan);
|
|
6009
|
+
}
|
|
6010
|
+
const writeTargets = [...scan.outputs];
|
|
6011
|
+
if (scan.recursive) writeTargets.push(...scan.roots.length > 0 ? scan.roots : ["."]);
|
|
6012
|
+
return writeTargets.length > 0 ? { writeTargets } : void 0;
|
|
6013
|
+
}
|
|
6014
|
+
/** Scan the word at `index`; returns the words it spans. */
|
|
6015
|
+
function treeWord(cmd, index, scan) {
|
|
6016
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
6017
|
+
if (value.startsWith("--")) return TREE_VALUED_LONG.some((name) => value.startsWith(name) && value.charAt(name.length) !== "=") ? 2 : 1;
|
|
6018
|
+
if (!value.startsWith("-") || value === "-") {
|
|
6019
|
+
scan.roots.push(value);
|
|
6020
|
+
return 1;
|
|
6021
|
+
}
|
|
6022
|
+
return 1 + treeShortOptions(cmd, index, scan);
|
|
6023
|
+
}
|
|
6024
|
+
/** Scan a short-option cluster. Each letter that takes a value consumes the
|
|
6025
|
+
* next unused word, in order (`-Lo 2 out.txt`). Returns how many it used. */
|
|
6026
|
+
function treeShortOptions(cmd, index, scan) {
|
|
6027
|
+
const value = elementAt(cmd, index, "cmd").value;
|
|
6028
|
+
let consumed = 0;
|
|
6029
|
+
let at = 1;
|
|
6030
|
+
while (at < value.length) {
|
|
6031
|
+
const letter = value.charAt(at);
|
|
6032
|
+
const digits = letter === "L" ? attachedDigits(value, at + 1) : 0;
|
|
6033
|
+
if (letter === "R") scan.recursive = true;
|
|
6034
|
+
else if (digits === 0 && TREE_VALUED_LETTERS.has(letter)) {
|
|
6035
|
+
consumed += 1;
|
|
6036
|
+
recordTreeValue(letter, cmd[index + consumed]?.value, scan);
|
|
6037
|
+
}
|
|
6038
|
+
at += 1 + digits;
|
|
6039
|
+
}
|
|
6040
|
+
return consumed;
|
|
6041
|
+
}
|
|
6042
|
+
/** How many digits start `value` at `from`. */
|
|
6043
|
+
function attachedDigits(value, from) {
|
|
6044
|
+
return value.slice(from).match(/^\d*/)?.[0].length ?? 0;
|
|
6045
|
+
}
|
|
6046
|
+
function recordTreeValue(letter, argument, scan) {
|
|
6047
|
+
if (letter === "o" && argument !== void 0) scan.outputs.push(argument);
|
|
6048
|
+
}
|
|
6049
|
+
// src/modules/analysis/capability/yq-mutation.ts
|
|
6050
|
+
/** yq's short flags that take a value. The value is the rest of the cluster,
|
|
6051
|
+
* so a later letter is not a flag (`-oi` is output format "i"). */
|
|
6052
|
+
const YQ_VALUED_LETTERS = "poIsf";
|
|
6053
|
+
/** The values a Go boolean flag parses as false. */
|
|
6054
|
+
const FALSE_VALUES = /* @__PURE__ */ new Set([
|
|
6055
|
+
"0",
|
|
6056
|
+
"f",
|
|
6057
|
+
"F",
|
|
6058
|
+
"false",
|
|
6059
|
+
"FALSE",
|
|
6060
|
+
"False"
|
|
6061
|
+
]);
|
|
6062
|
+
/** yq: `-i` rewrites its file operands, and `-s` writes a file per result.
|
|
6063
|
+
* For an in-place edit every non-option word, the expression included, is
|
|
6064
|
+
* recorded as a write target. */
|
|
6065
|
+
function yqMutation(cmd) {
|
|
6066
|
+
const writes = yqWrites(cmd);
|
|
6067
|
+
const writeTargets = [];
|
|
6068
|
+
if (writes.inPlace) writeTargets.push(...cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-")));
|
|
6069
|
+
if (writes.split) writeTargets.push(writes.anyPath ? "/" : ".");
|
|
6070
|
+
if (writes.inPlace && writeTargets.length === 0) writeTargets.push(".");
|
|
6071
|
+
return writeTargets.length > 0 ? { writeTargets } : void 0;
|
|
6072
|
+
}
|
|
6073
|
+
/** Scan yq's flags (pflag syntax: no abbreviations, booleans may carry
|
|
6074
|
+
* `=value`, short booleans cluster). */
|
|
6075
|
+
function yqWrites(cmd) {
|
|
6076
|
+
const writes = {
|
|
6077
|
+
inPlace: false,
|
|
6078
|
+
split: false,
|
|
6079
|
+
anyPath: false
|
|
6080
|
+
};
|
|
6081
|
+
for (const token of cmd.slice(1)) {
|
|
6082
|
+
const value = token.value;
|
|
6083
|
+
if (value === "--") break;
|
|
6084
|
+
if (value.startsWith("--")) yqLongFlag(value, writes);
|
|
6085
|
+
else if (value.startsWith("-")) yqShortFlags(value, writes);
|
|
6086
|
+
}
|
|
6087
|
+
return writes;
|
|
6088
|
+
}
|
|
6089
|
+
function yqLongFlag(value, writes) {
|
|
6090
|
+
const equals = value.indexOf("=");
|
|
6091
|
+
const name = equals === -1 ? value : value.slice(0, equals);
|
|
6092
|
+
const enabled = equals === -1 || !FALSE_VALUES.has(value.slice(equals + 1));
|
|
6093
|
+
if (name === "--inplace") writes.inPlace ||= enabled;
|
|
6094
|
+
else if (name === "--split-exp" || name === "--split-exp-file") writes.split = true;
|
|
6095
|
+
else if (name === "--security-allow-write-any-path") writes.anyPath ||= enabled;
|
|
6096
|
+
}
|
|
6097
|
+
function yqShortFlags(value, writes) {
|
|
6098
|
+
for (let at = 1; at < value.length; at += 1) {
|
|
6099
|
+
const letter = value.charAt(at);
|
|
6100
|
+
if (letter === "i") {
|
|
6101
|
+
if (yqInPlaceFlag(value, at, writes)) return;
|
|
6102
|
+
} else if (YQ_VALUED_LETTERS.includes(letter)) {
|
|
6103
|
+
writes.split ||= letter === "s";
|
|
6104
|
+
return;
|
|
6105
|
+
}
|
|
6106
|
+
}
|
|
6107
|
+
}
|
|
6108
|
+
/** Record the `-i` at `at`. pflag reads `-i=false` as the flag with a value,
|
|
6109
|
+
* which ends the cluster; returns whether it did. */
|
|
6110
|
+
function yqInPlaceFlag(value, at, writes) {
|
|
6111
|
+
const inline = value.charAt(at + 1) === "=" ? value.slice(at + 2) : void 0;
|
|
6112
|
+
writes.inPlace ||= inline === void 0 || !FALSE_VALUES.has(inline);
|
|
6113
|
+
return inline !== void 0;
|
|
6114
|
+
}
|
|
5716
6115
|
// src/modules/analysis/capability/read-only-tool-mutations.ts
|
|
5717
|
-
/** Placeholder target when a mutating form names no operand: conservatively
|
|
5718
|
-
* treated as a workspace write (the current directory). */
|
|
5719
|
-
const directoryFallback = ".";
|
|
5720
6116
|
function readOnlyToolMutation(cmd, base) {
|
|
5721
6117
|
if (base === "find") return findMutation(cmd);
|
|
5722
6118
|
if (base === "sort") return sortMutation(cmd);
|
|
6119
|
+
if (base === "uniq") return outputOperandMutation(cmd, UNIQ_OPTIONS);
|
|
6120
|
+
if (base === "xxd") return outputOperandMutation(cmd, XXD_OPTIONS);
|
|
6121
|
+
if (base === "tree") return treeMutation(cmd);
|
|
5723
6122
|
if (base === "yq") return yqMutation(cmd);
|
|
5724
6123
|
}
|
|
5725
6124
|
function findMutation(cmd) {
|
|
@@ -5779,22 +6178,6 @@ function pushOptionValue(cmd, index, targets) {
|
|
|
5779
6178
|
const target = cmd[index + 1]?.value;
|
|
5780
6179
|
if (target !== void 0 && !target.startsWith("-")) targets.push(target);
|
|
5781
6180
|
}
|
|
5782
|
-
function sortMutation(cmd) {
|
|
5783
|
-
const result = { writeTargets: [] };
|
|
5784
|
-
for (let index = 1; index < cmd.length; index += 1) {
|
|
5785
|
-
const value = elementAt(cmd, index, "cmd").value;
|
|
5786
|
-
if (value === "-o" || value === "--output") pushOptionValue(cmd, index, result.writeTargets);
|
|
5787
|
-
else if (value.startsWith("--output=")) result.writeTargets.push(value.slice(9));
|
|
5788
|
-
else if (value.startsWith("-o") && value.length > 2) result.writeTargets.push(value.slice(2));
|
|
5789
|
-
}
|
|
5790
|
-
return result.writeTargets.length > 0 ? result : void 0;
|
|
5791
|
-
}
|
|
5792
|
-
/** In-place edit: every non-option operand, the expression included, is recorded as a write target. */
|
|
5793
|
-
function yqMutation(cmd) {
|
|
5794
|
-
if (!cmd.some((token) => token.value === "-i" || token.value === "--inplace")) return void 0;
|
|
5795
|
-
const targets = cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-"));
|
|
5796
|
-
return targets.length > 0 ? { writeTargets: targets } : { writeTargets: [directoryFallback] };
|
|
5797
|
-
}
|
|
5798
6181
|
// src/modules/analysis/capability/executable-recognition.ts
|
|
5799
6182
|
/** Effect families that keep a read-only or no-effect executable from
|
|
5800
6183
|
* counting as read-only. */
|
|
@@ -7821,7 +8204,7 @@ const SCRIPT_READER = /\b(?:sh|bash|zsh|dash|ksh|ash|mksh|ssh|busybox)\b/;
|
|
|
7821
8204
|
function keepStringBodies(bodies, text) {
|
|
7822
8205
|
if (bodies === void 0 || !text.includes("<<")) return;
|
|
7823
8206
|
const read = sanitizedText(text);
|
|
7824
|
-
keepBodyCommands(bodies, read.bodyCommands, read.bodyUnresolved);
|
|
8207
|
+
keepBodyCommands(bodies, read.bodyCommands, read.bodyUnresolved, read.delimiterShellDependent);
|
|
7825
8208
|
keepBodyScripts(bodies, read.scripts);
|
|
7826
8209
|
if (read.scripts.size > 0 && SCRIPT_READER.test(read.text)) feedsOf(bodies).commands.push(text);
|
|
7827
8210
|
}
|
|
@@ -8039,6 +8422,7 @@ function newWalked() {
|
|
|
8039
8422
|
effective: [],
|
|
8040
8423
|
redirections: [],
|
|
8041
8424
|
truncated: false,
|
|
8425
|
+
delimiterShellDependent: false,
|
|
8042
8426
|
parts: [],
|
|
8043
8427
|
remote: [],
|
|
8044
8428
|
stdinCode: false,
|
|
@@ -8582,6 +8966,7 @@ function addAll(into, scripts) {
|
|
|
8582
8966
|
function walkBodyCommands(commands, unresolved, budget, into, feeds = [], scripts = []) {
|
|
8583
8967
|
const strings = takeBodies(budget);
|
|
8584
8968
|
into.truncated = into.truncated || unresolved || strings.unresolved;
|
|
8969
|
+
into.delimiterShellDependent ||= strings.shellDependent === true;
|
|
8585
8970
|
const queue = [...[...commands, ...strings.commands].map((command) => ({
|
|
8586
8971
|
command,
|
|
8587
8972
|
level: 1,
|
|
@@ -8602,6 +8987,7 @@ function walkBodyCommands(commands, unresolved, budget, into, feeds = [], script
|
|
|
8602
8987
|
if (next.remote) into.remote.push(...into.effective.slice(first.effective));
|
|
8603
8988
|
const deeper = takeBodies(budget);
|
|
8604
8989
|
into.truncated = into.truncated || lex.bodyUnresolved || deeper.unresolved;
|
|
8990
|
+
into.delimiterShellDependent ||= lex.delimiterShellDependent || deeper.shellDependent === true;
|
|
8605
8991
|
if (lex.truncated || stopped) {
|
|
8606
8992
|
into.truncated = true;
|
|
8607
8993
|
return;
|
|
@@ -8619,9 +9005,11 @@ function takeBodies(budget) {
|
|
|
8619
9005
|
};
|
|
8620
9006
|
const taken = {
|
|
8621
9007
|
commands: bodies.commands.splice(0),
|
|
8622
|
-
unresolved: bodies.unresolved
|
|
9008
|
+
unresolved: bodies.unresolved,
|
|
9009
|
+
shellDependent: bodies.shellDependent === true
|
|
8623
9010
|
};
|
|
8624
9011
|
bodies.unresolved = false;
|
|
9012
|
+
bodies.shellDependent = false;
|
|
8625
9013
|
return taken;
|
|
8626
9014
|
}
|
|
8627
9015
|
/** Queue the commands and feeds one level below `from`; true when that is
|
|
@@ -8642,6 +9030,46 @@ function queueDeeper(queue, commands, feeds, from) {
|
|
|
8642
9030
|
});
|
|
8643
9031
|
return false;
|
|
8644
9032
|
}
|
|
9033
|
+
// src/modules/analysis/capability/heredoc/shell-dependent-word.ts
|
|
9034
|
+
/** Index of the first `close` at or after `from` that no backslash escapes,
|
|
9035
|
+
* or -1. */
|
|
9036
|
+
function closingIndex(raw, from, close) {
|
|
9037
|
+
for (let i = from; i < raw.length; i++) if (raw[i] === "\\") i++;
|
|
9038
|
+
else if (raw[i] === close) return i;
|
|
9039
|
+
return -1;
|
|
9040
|
+
}
|
|
9041
|
+
/** Index of the quote that ends a `'…'` or `"…"` region opened before `from`.
|
|
9042
|
+
* Inside single quotes a backslash is literal. */
|
|
9043
|
+
function quoteEnd(raw, from, quote) {
|
|
9044
|
+
return quote === "'" ? raw.indexOf("'", from) : closingIndex(raw, from, quote);
|
|
9045
|
+
}
|
|
9046
|
+
const FOUND = -1;
|
|
9047
|
+
const UNTERMINATED = -2;
|
|
9048
|
+
/** Index where the scan resumes after the part at `i`, FOUND for a
|
|
9049
|
+
* shell-dependent `$'…'`, or UNTERMINATED when a quote never closes. */
|
|
9050
|
+
function step(raw, i) {
|
|
9051
|
+
const ch = raw[i];
|
|
9052
|
+
if (ch === "\\") return i + 2;
|
|
9053
|
+
if (ch === "'" || ch === "\"") {
|
|
9054
|
+
const close = quoteEnd(raw, i + 1, ch);
|
|
9055
|
+
return close < 0 ? UNTERMINATED : close + 1;
|
|
9056
|
+
}
|
|
9057
|
+
if (ch === "$" && raw[i + 1] === "'") {
|
|
9058
|
+
const close = closingIndex(raw, i + 2, "'");
|
|
9059
|
+
if (close < 0) return UNTERMINATED;
|
|
9060
|
+
return ansiCShellDependent(raw.slice(i + 2, close)) ? FOUND : close + 1;
|
|
9061
|
+
}
|
|
9062
|
+
return i + 1;
|
|
9063
|
+
}
|
|
9064
|
+
/** Whether a word has an unquoted `$'…'` part whose escapes the shells
|
|
9065
|
+
* decode differently (`ansiCShellDependent`). One left-to-right pass: `'…'`,
|
|
9066
|
+
* `"…"` and backslash pairs are skipped, so `"$'\q'"` doesn't count. */
|
|
9067
|
+
function hasShellDependentWord(raw) {
|
|
9068
|
+
if (!raw.includes("\\")) return false;
|
|
9069
|
+
let i = 0;
|
|
9070
|
+
while (i >= 0 && i < raw.length) i = step(raw, i);
|
|
9071
|
+
return i === FOUND;
|
|
9072
|
+
}
|
|
8645
9073
|
// src/modules/analysis/capability/command-parser.ts
|
|
8646
9074
|
/** Parse a raw bash command into the reusable structure. */
|
|
8647
9075
|
function parseCommand(rawCommand) {
|
|
@@ -8672,6 +9100,7 @@ function parse(rawCommand) {
|
|
|
8672
9100
|
analysisTruncated: walked.truncated,
|
|
8673
9101
|
heads: walked.heads,
|
|
8674
9102
|
segmentRedirections: walked.parts.map((part) => part.segmentRedirections),
|
|
9103
|
+
shellDependentQuoting: extraction.delimiterShellDependent || lex.delimiterShellDependent || walked.delimiterShellDependent || [...walked.segments.flatMap((segment) => segment.tokens), ...walked.effective.flat()].some((token) => hasShellDependentWord(token.raw)),
|
|
8675
9104
|
...walked.remote.length > 0 && { remoteCommands: walked.remote },
|
|
8676
9105
|
...walked.stdinCode && { stdinCode: true }
|
|
8677
9106
|
};
|
|
@@ -9012,7 +9441,7 @@ async function includeFileOnce(source, directory, rootDirectory, worktree, maxCh
|
|
|
9012
9441
|
const actualBlock = resolvedPathBlock(actual, roots, "outside approved enrichment roots");
|
|
9013
9442
|
if (actualBlock !== void 0) return blocked(resolved, actualBlock);
|
|
9014
9443
|
const limit = Math.max(1, maxChars);
|
|
9015
|
-
const handle = await open(actual, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
9444
|
+
const handle = await open$2(actual, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
9016
9445
|
try {
|
|
9017
9446
|
return await readOpenedFile(handle, resolved, roots, limit);
|
|
9018
9447
|
} finally {
|
|
@@ -9214,7 +9643,7 @@ async function connectedStatus(endpoint, directory) {
|
|
|
9214
9643
|
async function checkWritable(path) {
|
|
9215
9644
|
try {
|
|
9216
9645
|
await mkdir(dirname(path), { recursive: true });
|
|
9217
|
-
await (await open(path, "a", 384)).close();
|
|
9646
|
+
await (await open$2(path, "a", 384)).close();
|
|
9218
9647
|
return { ok: true };
|
|
9219
9648
|
} catch (error) {
|
|
9220
9649
|
return {
|