@kaynooo/cli-guard 0.14.2 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +540 -237
  3. package/package.json +8 -8
package/dist/cli.js CHANGED
@@ -117,11 +117,14 @@ var init_config = __esm(() => {
117
117
  // ../kit/src/user-config.ts
118
118
  import { existsSync as existsSync2, readFileSync } from "fs";
119
119
  import { homedir } from "os";
120
- import { join as join2 } from "path";
120
+ import { isAbsolute, join as join2 } from "path";
121
121
  import process4 from "process";
122
+ function xdgFolder(value, fallback) {
123
+ return value !== undefined && isAbsolute(value) ? value : fallback;
124
+ }
122
125
  function configBase(where = {}) {
123
126
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
124
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
127
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
125
128
  }
126
129
  function userConfigPath(bin, where = {}) {
127
130
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
@@ -815,6 +818,7 @@ init_format();
815
818
  import { constants } from "os";
816
819
  import process11 from "process";
817
820
  var KILL_GRACE_MS = 2000;
821
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
818
822
  function exitCodeOf(code, signal) {
819
823
  if (code !== null)
820
824
  return code;
@@ -865,12 +869,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
865
869
  stop();
866
870
  continue;
867
871
  }
872
+ if (state.truncated)
873
+ continue;
874
+ let kept = data;
868
875
  if (state.kept + data.length > maxBytes) {
876
+ let cut = maxBytes - state.kept;
877
+ while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
878
+ cut--;
879
+ kept = data.subarray(0, cut);
869
880
  state.truncated = true;
870
- continue;
871
881
  }
872
- state.kept += data.length;
873
- chunks.push({ stream: name, data });
882
+ state.kept += kept.length;
883
+ if (kept.length > 0)
884
+ chunks.push({ stream: name, data: kept });
874
885
  }
875
886
  };
876
887
  try {
@@ -887,6 +898,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
887
898
  const joined = () => Buffer.concat(chunks.map(({ data }) => data));
888
899
  let output;
889
900
  let text;
901
+ let stdout;
890
902
  return {
891
903
  code: exitCodeOf(proc.exitCode, proc.signalCode),
892
904
  chunks,
@@ -897,6 +909,9 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs,
897
909
  },
898
910
  get text() {
899
911
  return text ??= (output ??= joined()).toString();
912
+ },
913
+ get stdout() {
914
+ return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
900
915
  }
901
916
  };
902
917
  }
@@ -1046,14 +1061,16 @@ init_text();
1046
1061
  // ../kit/src/usage.ts
1047
1062
  import { appendFileSync, mkdirSync } from "fs";
1048
1063
  import { homedir as homedir3 } from "os";
1049
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1064
+ import { dirname as dirname2, join as join4 } from "path";
1050
1065
  import process14 from "process";
1051
1066
 
1052
1067
  // ../kit/src/logs.ts
1068
+ init_user_config();
1053
1069
  var DAY_MS = 24 * 60 * 60 * 1000;
1054
1070
  var CLI_FOLDER = "kaynooo-cli";
1055
1071
 
1056
1072
  // ../kit/src/usage.ts
1073
+ init_user_config();
1057
1074
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
1058
1075
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
1059
1076
  var LONGEST_NAME = 40;
@@ -1062,8 +1079,7 @@ function noteUsageError(message) {
1062
1079
  usageError = message;
1063
1080
  }
1064
1081
  function stateHome(env = process14.env) {
1065
- const dir = env.XDG_STATE_HOME;
1066
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1082
+ return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
1067
1083
  }
1068
1084
  function usagePath(env = process14.env) {
1069
1085
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
@@ -1137,6 +1153,10 @@ function takeOutputFlags(argv) {
1137
1153
  async function resolveSummary(summary) {
1138
1154
  return typeof summary === "string" ? summary : summary();
1139
1155
  }
1156
+ function lookup({ commands, aliases }, word) {
1157
+ const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
1158
+ return Object.hasOwn(commands, name) ? commands[name] : undefined;
1159
+ }
1140
1160
  function scopeOf(commands, extra, aliases) {
1141
1161
  return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
1142
1162
  }
@@ -1231,12 +1251,12 @@ async function dispatch(level, typed, { version, redact }) {
1231
1251
  console.log(version);
1232
1252
  return 0;
1233
1253
  }
1234
- let command = level.commands[level.aliases?.[name] ?? name];
1254
+ let command = lookup(level, name);
1235
1255
  let rest = args;
1236
1256
  let ran = name;
1237
1257
  if (command === undefined && level.lazy.length > 0) {
1238
1258
  level = await expand(level, [...level.path.slice(1), ...argv]);
1239
- command = level.commands[level.aliases?.[name] ?? name];
1259
+ command = lookup(level, name);
1240
1260
  }
1241
1261
  if (command === undefined && level.defaultCommand !== undefined) {
1242
1262
  command = level.commands[level.defaultCommand];
@@ -1316,18 +1336,19 @@ async function leafCandidates(run, words) {
1316
1336
  async function candidates(scope, defaultCommand, words, before = []) {
1317
1337
  const [word = "", ...rest] = words;
1318
1338
  const listing = rest.length === 0 && !word.startsWith("-");
1319
- let { commands, aliases } = scope;
1320
- let command = commands[aliases?.[word] ?? word];
1339
+ let { commands } = scope;
1340
+ let command = lookup(scope, word);
1321
1341
  if (listing || command === undefined) {
1322
- ({ commands, aliases } = await expand(scope, [...before, ...words]));
1323
- command = commands[aliases?.[word] ?? word];
1342
+ const expanded = await expand(scope, [...before, ...words]);
1343
+ commands = expanded.commands;
1344
+ command = lookup(expanded, word);
1324
1345
  }
1325
1346
  if (listing) {
1326
1347
  const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
1327
1348
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
1328
1349
  const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
1329
1350
  const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
1330
- return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
1351
+ return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
1331
1352
  }
1332
1353
  if (command === undefined) {
1333
1354
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
@@ -1392,8 +1413,7 @@ function commandPath(scope, argv) {
1392
1413
  const path = [];
1393
1414
  let level = scope;
1394
1415
  for (const word of argv.filter((each) => !each.startsWith("-"))) {
1395
- const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
1396
- const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
1416
+ const command = lookup(level, word);
1397
1417
  if (command === undefined)
1398
1418
  break;
1399
1419
  path.push(word);
@@ -1426,7 +1446,17 @@ init_mode();
1426
1446
  init_style();
1427
1447
  init_text();
1428
1448
  // ../kit/src/secrets.ts
1449
+ var SECRET_PART = /token|secret|passw|passphrase|credential|private|dsn|apikey|accesskey|authorization|sess(?:ion)?id|connectionstring|key$/i;
1429
1450
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1451
+ var WORD_BREAKS = /[^a-zA-Z\d]+|(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/;
1452
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
1453
+ function isSecretWord(word) {
1454
+ const lower = word.toLowerCase();
1455
+ return SECRET_WORDS.has(lower) || lower.endsWith("pass") && !NOT_PASSWORDS.has(lower);
1456
+ }
1457
+ function isSecretName(name) {
1458
+ return SECRET_PART.test(name) || name.split(WORD_BREAKS).some(isSecretWord);
1459
+ }
1430
1460
  // ../kit/src/sessions.ts
1431
1461
  var {Glob } = globalThis.Bun;
1432
1462
  var SESSION_FILES = new Glob("*.json");
@@ -1451,7 +1481,7 @@ var PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
1451
1481
  var GLOB_CHARS = new Set(["*", "?", "["]);
1452
1482
  var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
1453
1483
  var WHITESPACE = /\s/;
1454
- var ASSIGNMENT = /^\w+=/;
1484
+ var ASSIGNMENT = /^\w+(?:\[[^\]]*\])?\+?=/;
1455
1485
  var TRAILING_SLASHES = /\/+$/;
1456
1486
  var TRAILING_CR = /\r$/;
1457
1487
  var LEADING_TILDE = /^~(?=\/|$)/;
@@ -1464,14 +1494,17 @@ var REDIRECT_START = /^\d*[<>]|^&>/;
1464
1494
  var SAFE_WORD = /^[\w@%+=:,./-]+$/;
1465
1495
  var LEADING_HEX = /^[\da-f]*/i;
1466
1496
  var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
1467
- var HEREDOC = /^<<(-?)[ \t]*(?:'([^']*)'|"([^"]*)"|([^\s;&|<>()-][^\s;&|<>()]*))/;
1497
+ var HEREDOC = /^<<(-?)[ \t]*((?:'[^']*'|"(?:\\.|[^"\\])*"|\\.|[^\s;&|<>()'"\\-])(?:'[^']*'|"(?:\\.|[^"\\])*"|\\.|[^\s;&|<>()'"\\])*)/;
1498
+ var DELIMITER_QUOTING = /'([^']*)'|"((?:\\.|[^"\\])*)"|\\(.)/g;
1499
+ var DOUBLE_QUOTED_ESCAPE = /\\([$`"\\])/g;
1468
1500
  var ANSI_QUOTE = "$'";
1469
1501
  var ANSI_ESCAPES = { n: `
1470
1502
  `, t: "\t", r: "\r", a: "\x07", b: "\b", f: "\f", v: "\v", e: "\x1B", E: "\x1B", "\\": "\\", "'": "'", '"': '"', "?": "?" };
1471
1503
  var ANSI_DIGITS = { x: 2, u: 4, U: 8 };
1472
1504
  var OCTAL = /^[0-7]{1,3}/;
1473
1505
  var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
1474
- var INPUT_REDIRECT = /^\d*<(?![<&(>])/;
1506
+ var LEADING_REDIRECT = /^(?:\d+|\{\w+\})?(?:<<<|<<-?|<>|<&|<(?!\()|>>|>&|>\||>|&>>|&>)/;
1507
+ var FISH_COMBINERS = new Set(["and", "or", "not"]);
1475
1508
  var MAX_DEPTH = 8;
1476
1509
  var MAX_BRACES = 256;
1477
1510
  var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
@@ -1489,6 +1522,7 @@ var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
1489
1522
  function wrapper(short = "", long = [], operands = 0, runsString = false) {
1490
1523
  return { short, long, operands, runsString };
1491
1524
  }
1525
+ var RUNNER = { ...wrapper(), afterDashes: true };
1492
1526
  var WRAPPERS = new Map([
1493
1527
  ["command", wrapper()],
1494
1528
  ["builtin", wrapper()],
@@ -1510,7 +1544,23 @@ var WRAPPERS = new Map([
1510
1544
  ["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
1511
1545
  ["unbuffer", wrapper()],
1512
1546
  ["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
1513
- ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
1547
+ ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])],
1548
+ ["strace", wrapper("abeEIoOpPsSuUX", ["--trace", "--output", "--attach", "--string-limit", "--user", "--env", "--columns", "--trace-path", "--signal", "--status", "--summary-sort-by", "--summary-columns", "--const-print-style", "--interruptible", "--detach-on"])],
1549
+ ["ltrace", wrapper("aeFlnopsuxX", ["--output", "--user", "--library", "--config", "--align", "--indent"])],
1550
+ ["taskset", wrapper("", [], 1)],
1551
+ ["fakeroot", wrapper("lsib", ["--lib", "--faked"])],
1552
+ ["sshpass", wrapper("pfdP")],
1553
+ ["coproc", wrapper()],
1554
+ ["proxychains", wrapper("f")],
1555
+ ["proxychains4", wrapper("f")],
1556
+ ["torsocks", wrapper("upaP", ["--user", "--pass", "--address", "--port"])],
1557
+ ["chrt", wrapper("TPD", ["--sched-runtime", "--sched-period", "--sched-deadline"], 1)],
1558
+ ["unshare", wrapper("SGRw", ["--setuid", "--setgid", "--root", "--wd", "--map-user", "--map-group", "--map-users", "--map-groups", "--propagation", "--setgroups"])],
1559
+ ["nsenter", wrapper("tSG", ["--target", "--setuid", "--setgid"])],
1560
+ ["out", RUNNER],
1561
+ ["slot", RUNNER],
1562
+ ["waitfor", RUNNER],
1563
+ ["base", RUNNER]
1514
1564
  ]);
1515
1565
  function closerOf(quote) {
1516
1566
  return quote === ANSI_QUOTE ? "'" : quote;
@@ -1567,6 +1617,10 @@ function splitCommand(command) {
1567
1617
  i++;
1568
1618
  continue;
1569
1619
  }
1620
+ if (quote === '"' && isSubstitutionAt(command, i)) {
1621
+ i = substitutionEnd(command, i);
1622
+ continue;
1623
+ }
1570
1624
  if (quote !== null) {
1571
1625
  if (char === closerOf(quote))
1572
1626
  quote = null;
@@ -1602,9 +1656,15 @@ function splitCommand(command) {
1602
1656
  i = end - 1;
1603
1657
  continue;
1604
1658
  }
1605
- const heredoc = char === "<" && command[i + 1] === "<" && command[i + 2] !== "<" && !LET_PIECE.test(command.slice(start, i)) ? HEREDOC.exec(command.slice(i)) : null;
1659
+ if (command.startsWith("<<<", i)) {
1660
+ i += 2;
1661
+ continue;
1662
+ }
1663
+ const heredoc = char === "<" && command[i + 1] === "<" && !LET_PIECE.test(command.slice(start, i)) ? HEREDOC.exec(command.slice(i)) : null;
1606
1664
  if (heredoc) {
1607
- heredocs.push({ word: heredoc[2] ?? heredoc[3] ?? heredoc[4] ?? "", stripsTabs: heredoc[1] === "-", isQuoted: heredoc[4] === undefined });
1665
+ const raw = heredoc[2] ?? "";
1666
+ const word = raw.replace(DELIMITER_QUOTING, (_, single, double, escaped) => single ?? double?.replace(DOUBLE_QUOTED_ESCAPE, (__, kept) => kept) ?? escaped ?? "");
1667
+ heredocs.push({ word, stripsTabs: heredoc[1] === "-", isQuoted: word !== raw });
1608
1668
  i += heredoc[0].length - 1;
1609
1669
  continue;
1610
1670
  }
@@ -1659,7 +1719,10 @@ function isPlain(text) {
1659
1719
  }
1660
1720
  return quote === null;
1661
1721
  }
1662
- function unmatchedClosers(text) {
1722
+ function parenBalance(text) {
1723
+ return balance(text, "(", ")");
1724
+ }
1725
+ function balance(text, open, close) {
1663
1726
  let depth = 0;
1664
1727
  let unmatched = 0;
1665
1728
  let quote = null;
@@ -1676,18 +1739,18 @@ function unmatchedClosers(text) {
1676
1739
  quote = null;
1677
1740
  else if (quote === null && (char === '"' || char === "'"))
1678
1741
  quote = char;
1679
- else if (quote === null && char === "(")
1742
+ else if (quote === null && char === open)
1680
1743
  depth++;
1681
- else if (quote === null && char === ")" && depth > 0)
1744
+ else if (quote === null && char === close && depth > 0)
1682
1745
  depth--;
1683
- else if (quote === null && char === ")")
1746
+ else if (quote === null && char === close)
1684
1747
  unmatched++;
1685
1748
  }
1686
- return unmatched;
1749
+ return { opened: depth, closed: unmatched };
1687
1750
  }
1688
1751
  function withoutSubshell(text) {
1689
1752
  let result = text.trim();
1690
- let closers = unmatchedClosers(result);
1753
+ let closers = parenBalance(result).closed;
1691
1754
  while (result.startsWith("("))
1692
1755
  result = result.slice(1).trimStart();
1693
1756
  while (closers > 0 && result.endsWith(")")) {
@@ -1696,6 +1759,12 @@ function withoutSubshell(text) {
1696
1759
  }
1697
1760
  return result;
1698
1761
  }
1762
+ function isSubstitutionAt(text, i) {
1763
+ return text[i] === "`" || text[i] === "$" && text[i + 1] === "(";
1764
+ }
1765
+ function substitutionEnd(text, i) {
1766
+ return text[i] === "`" ? closingBackquote(text, i) : closingParen(text, i + 1);
1767
+ }
1699
1768
  function closingParen(text, open) {
1700
1769
  let depth = 0;
1701
1770
  let quote = null;
@@ -1703,6 +1772,8 @@ function closingParen(text, open) {
1703
1772
  const char = text[i] ?? "";
1704
1773
  if (char === "\\" && quote !== "'") {
1705
1774
  i++;
1775
+ } else if (quote === '"' && isSubstitutionAt(text, i)) {
1776
+ i = substitutionEnd(text, i);
1706
1777
  } else if (quote !== null) {
1707
1778
  if (char === closerOf(quote))
1708
1779
  quote = null;
@@ -1789,11 +1860,12 @@ function words(text) {
1789
1860
  let quote = null;
1790
1861
  for (let i = 0;i < text.length; i++) {
1791
1862
  const char = text[i] ?? "";
1792
- const isContinuation = char === "\\" && quote !== "'" && text[i + 1] === `
1793
- `;
1794
- if (isContinuation)
1863
+ if (char === "\\" && quote !== "'" && text[i + 1] === `
1864
+ `) {
1795
1865
  i++;
1796
- if (quote === null && (isContinuation || WHITESPACE.test(char))) {
1866
+ continue;
1867
+ }
1868
+ if (quote === null && WHITESPACE.test(char)) {
1797
1869
  if (isStarted)
1798
1870
  found.push({ text: current, isProse, hasGlob, hasBrace });
1799
1871
  current = "";
@@ -1803,8 +1875,6 @@ function words(text) {
1803
1875
  hasBrace = false;
1804
1876
  continue;
1805
1877
  }
1806
- if (isContinuation)
1807
- continue;
1808
1878
  isStarted = true;
1809
1879
  if (char === "\\" && quote === ANSI_QUOTE) {
1810
1880
  const [decoded, last] = ansiEscape(text, i);
@@ -1862,14 +1932,23 @@ function skipOptions(tokens, spec) {
1862
1932
  tokens.shift();
1863
1933
  }
1864
1934
  function parseCommand(text) {
1865
- const tokens = tokenize(text);
1935
+ const found = words(text);
1936
+ const tokens = found.map((word) => word.text);
1937
+ const braced = new Set(found.filter((word) => word.hasBrace).map((word) => word.text));
1866
1938
  const assignments = [];
1867
1939
  const strings = [];
1868
1940
  let isWrapped = false;
1941
+ let opened = 0;
1869
1942
  for (;; ) {
1870
1943
  const first = tokens[0] ?? "";
1871
1944
  const spec = WRAPPERS.get(first.split("/").pop() ?? "");
1872
- if (first === "function" && tokens.length > 1) {
1945
+ const expanded = braced.has(first) ? braceExpand(first) : [];
1946
+ if (expanded.length > 1) {
1947
+ tokens.splice(0, 1, ...expanded);
1948
+ braced.delete(first);
1949
+ } else if (LEADING_REDIRECT.test(first)) {
1950
+ tokens.splice(0, first.replace(LEADING_REDIRECT, "") === "" ? 2 : 1);
1951
+ } else if (first === "function" && tokens.length > 1) {
1873
1952
  isWrapped = true;
1874
1953
  tokens.splice(0, 2);
1875
1954
  if (tokens[0] === "()")
@@ -1883,13 +1962,14 @@ function parseCommand(text) {
1883
1962
  } else if (OPENERS.test(first)) {
1884
1963
  isWrapped = true;
1885
1964
  const rest = first.replace(OPENERS, "");
1965
+ opened += first.length - rest.length;
1886
1966
  if (rest === "")
1887
1967
  tokens.shift();
1888
1968
  else
1889
1969
  tokens[0] = rest;
1890
1970
  } else if (ASSIGNMENT.test(first)) {
1891
1971
  assignments.push(tokens.shift() ?? "");
1892
- } else if (KEYWORDS.has(first)) {
1972
+ } else if (KEYWORDS.has(first) || FISH_COMBINERS.has(first)) {
1893
1973
  isWrapped = true;
1894
1974
  tokens.shift();
1895
1975
  } else if (first === "case") {
@@ -1899,8 +1979,12 @@ function parseCommand(text) {
1899
1979
  } else if (tokens.length > 1 && CASE_LABEL.test(first)) {
1900
1980
  isWrapped = true;
1901
1981
  tokens.shift();
1902
- } else if (INPUT_REDIRECT.test(first)) {
1903
- tokens.splice(0, first.replace(INPUT_REDIRECT, "") === "" ? 2 : 1);
1982
+ } else if (spec?.afterDashes === true) {
1983
+ const dashes = tokens.indexOf("--");
1984
+ if (dashes === -1)
1985
+ break;
1986
+ isWrapped = true;
1987
+ tokens.splice(0, dashes + 1);
1904
1988
  } else if (spec !== undefined) {
1905
1989
  isWrapped = true;
1906
1990
  tokens.shift();
@@ -1911,7 +1995,7 @@ function parseCommand(text) {
1911
1995
  break;
1912
1996
  }
1913
1997
  }
1914
- const closers = CLOSERS.exec(text.trimEnd())?.[0].length ?? 0;
1998
+ const closers = Math.min(CLOSERS.exec(text.trimEnd())?.[0].length ?? 0, opened + parenBalance(text).closed + balance(text, "{", "}").closed);
1915
1999
  const word = tokens.at(-1) ?? "";
1916
2000
  const trimmed = word.length - (CLOSERS.exec(word)?.[0].length ?? 0);
1917
2001
  const last = word.slice(0, Math.max(trimmed, word.length - closers));
@@ -1941,7 +2025,13 @@ function commandStrings(tokens) {
1941
2025
  isValue = false;
1942
2026
  continue;
1943
2027
  }
2028
+ if (name === "fish" && option.startsWith("--init-command=")) {
2029
+ found.push(option.slice("--init-command=".length));
2030
+ continue;
2031
+ }
1944
2032
  if (SHELL_VALUE_OPTIONS.has(option) || name === "fish" && FISH_VALUE_OPTIONS.has(option)) {
2033
+ if (name === "fish" && FISH_VALUE_OPTIONS.has(option))
2034
+ found.push(tokens[j + 1] ?? "");
1945
2035
  isValue = true;
1946
2036
  continue;
1947
2037
  }
@@ -2192,6 +2282,33 @@ var DEFINITION_MODIFIERS = new Set(["or", "replace", "temporary", "temp", "unlog
2192
2282
  var SERVER_OBJECTS = new Set(["database", "user", "role", "server", "tablespace", "extension", "system", "subscription", "publication", "logfile", "instance", "resource"]);
2193
2283
  var FILE_WORDS = new Set(["infile", "outfile", "dumpfile"]);
2194
2284
  var SEQUENCE_FUNCTIONS = new Set(["nextval", "setval"]);
2285
+ function foreignDatabases(statement, database) {
2286
+ const found = [];
2287
+ for (const [index, token] of statement.entries()) {
2288
+ if ((token.kind === "word" || token.kind === "quoted") && !isPunct(statement[index - 1], "@") && isPunct(statement[index + 1], ".") && !isPunct(statement[index - 1], ".") && token.text.toLowerCase() !== database.toLowerCase())
2289
+ found.push(token.text);
2290
+ }
2291
+ return found;
2292
+ }
2293
+ var EXISTENCE_WORDS = new Set(["if", "not", "exists"]);
2294
+ function otherDatabases(sql, dialect, database) {
2295
+ const found = [];
2296
+ for (const statement of splitStatements(tokenize2(sql, dialect))) {
2297
+ if (dialect === "mysql")
2298
+ found.push(...foreignDatabases(statement, database));
2299
+ const first = statement[0]?.text ?? "";
2300
+ const kind = statement.findIndex((token, index) => index > 0 && !DEFINITION_MODIFIERS.has(token.text));
2301
+ const isDatabase = DEFINITION_STARTS.has(first) && (statement[kind]?.text === "database" || dialect === "mysql" && statement[kind]?.text === "schema");
2302
+ let named;
2303
+ if (first === "use")
2304
+ named = statement[1];
2305
+ else if (isDatabase)
2306
+ named = statement.slice(kind + 1).find((token) => !EXISTENCE_WORDS.has(token.text));
2307
+ if (named !== undefined && named.kind !== "punct" && named.text.toLowerCase() !== database.toLowerCase())
2308
+ found.push(named.text);
2309
+ }
2310
+ return found;
2311
+ }
2195
2312
 
2196
2313
  // ../db/src/guard.ts
2197
2314
  var LOCK_KIND = /^(?:update|share|no|key)$/;
@@ -2276,7 +2393,12 @@ var KNOWN_LONGS = [...STATEMENT_LONGS, ...FILE_LONGS, ...DATABASE_LONGS, ...VALU
2276
2393
  var LIST_OPTIONS = new Set(["-l", "--list"]);
2277
2394
  var REDIRECT_ONLY2 = /^\d*(?:>|>>|>&|&>|>\||<&|<>)$/;
2278
2395
  var REDIRECT_START2 = /^\d*>|^&>/;
2279
- var URL_DATABASE = /^[a-z][a-z\d+.-]*:\/\/[^/]*\/([^?#]*)/i;
2396
+ var URL_START = /^[a-z][a-z\d+.-]*:\/\//i;
2397
+ var URL_PATH = /^[a-z][a-z\d+.-]*:\/\/[^/?]*\/?([^?]*)/i;
2398
+ var CONNINFO = /^\s*\w+\s*=/;
2399
+ var CONNINFO_PAIR = /\s*(\w+)\s*=\s*(?:'((?:\\[\s\S]|[^'\\])*)'|(?!')((?:\\[\s\S]?|[^\s\\])*))/gy;
2400
+ var ESCAPED = /\\([\s\S]?)/g;
2401
+ var UNREAD_CONNINFO = "a conninfo string not read to its end";
2280
2402
  var WRITING_CONSOLE = /^(?:doctrine:(?:migrations:(?:migrate|execute|rollup)|schema:(?:update|create|drop)|database:(?:create|drop)|fixtures:load)|migrate(?::\w+)?|db:(?:seed|wipe))$/;
2281
2403
  var TEST_SCOPED = /(?:^|[^a-z])test/i;
2282
2404
  var ASSIGNMENT2 = /^([A-Z_]\w*)=/i;
@@ -2287,6 +2409,7 @@ var SHOT_STACK = /\.worktrees\/[^/\s]+\/shot(?:\/|$)|--shot(?:-|$)/;
2287
2409
  var DEVICE_PATH = /^\/(?:dev|proc|sys)\//;
2288
2410
  var STDIN_PATHS = new Set(["-", "/dev/stdin"]);
2289
2411
  var SQL_WRITE = "Statements that write (INSERT, UPDATE, DELETE, DDL, migrations, fixtures) are handed over: list the exact command for the user to run. Only a clearly test-only database runs them directly.";
2412
+ var SQL_OTHER_DATABASE = "A write naming another database than the test one the client connects to (a qualified name, USE, CREATE or DROP DATABASE) reaches past it: hand the exact command over for the user to run.";
2290
2413
  var SHELL_SYNTAX = /[$`]/;
2291
2414
  function sqlUnreadable(path) {
2292
2415
  let cause = "missing when the command is checked, or too large";
@@ -2302,8 +2425,49 @@ function hasWrite(statement) {
2302
2425
  function programOf(word) {
2303
2426
  return word.split("/").pop() ?? "";
2304
2427
  }
2428
+ function percentDecoded(text) {
2429
+ try {
2430
+ return decodeURIComponent(text);
2431
+ } catch {
2432
+ return text;
2433
+ }
2434
+ }
2435
+ function queryDatabase(operand) {
2436
+ const query = operand.indexOf("?");
2437
+ let database;
2438
+ if (query === -1)
2439
+ return;
2440
+ for (const pair of operand.slice(query + 1).split("&")) {
2441
+ const equals = pair.indexOf("=");
2442
+ if (equals !== -1 && percentDecoded(pair.slice(0, equals)) === "dbname")
2443
+ database = pair.slice(equals + 1);
2444
+ }
2445
+ return database;
2446
+ }
2447
+ function urlDatabase(url) {
2448
+ const raw = queryDatabase(url) ?? URL_PATH.exec(url)?.[1];
2449
+ return raw === undefined || raw === "" ? undefined : percentDecoded(raw);
2450
+ }
2305
2451
  function databaseOf(operand) {
2306
- return URL_DATABASE.exec(operand)?.[1] ?? operand;
2452
+ if (URL_START.test(operand)) {
2453
+ const whole = urlDatabase(operand);
2454
+ const fragment = operand.indexOf("#");
2455
+ if (fragment === -1)
2456
+ return whole;
2457
+ const cut = urlDatabase(operand.slice(0, fragment));
2458
+ return whole !== undefined && TEST_SCOPED.test(whole) ? cut : whole;
2459
+ }
2460
+ if (!CONNINFO.test(operand))
2461
+ return operand;
2462
+ let database;
2463
+ let end = 0;
2464
+ for (const match of operand.matchAll(CONNINFO_PAIR)) {
2465
+ const [whole, key, quoted, bare] = match;
2466
+ end = match.index + whole.length;
2467
+ if (key === "dbname")
2468
+ database = (quoted ?? bare ?? "").replaceAll(ESCAPED, "$1");
2469
+ }
2470
+ return operand.slice(end).trim() === "" ? database : UNREAD_CONNINFO;
2307
2471
  }
2308
2472
  function fullOption(option) {
2309
2473
  if (KNOWN_LONGS.includes(option) || option.length < 4)
@@ -2312,7 +2476,7 @@ function fullOption(option) {
2312
2476
  return candidates.length === 1 ? candidates[0] : option;
2313
2477
  }
2314
2478
  function clientInput(name, args) {
2315
- const input = { statements: [], files: [], databases: [], operands: [] };
2479
+ const input = { statements: [], files: [], operands: [] };
2316
2480
  const valueShorts = VALUE_SHORTS[name] ?? "";
2317
2481
  let isOperands = false;
2318
2482
  for (let i = 0;i < args.length; i++) {
@@ -2343,7 +2507,7 @@ function clientInput(name, args) {
2343
2507
  else if (option === "--file")
2344
2508
  input.files.push(value);
2345
2509
  else if (DATABASE_LONGS.has(option))
2346
- input.databases.push(databaseOf(value));
2510
+ input.database = databaseOf(value);
2347
2511
  if (attached === undefined && (STATEMENT_LONGS.has(option) || option === "--file" || DATABASE_LONGS.has(option) || VALUE_LONGS.has(option)))
2348
2512
  i++;
2349
2513
  } else if (arg === "-cmd" && name === "sqlite3") {
@@ -2361,7 +2525,7 @@ function clientInput(name, args) {
2361
2525
  else if (FILE_SHORTS[name]?.includes(letter) === true)
2362
2526
  input.files.push(value);
2363
2527
  else if (DATABASE_SHORTS.has(letter))
2364
- input.databases.push(databaseOf(value));
2528
+ input.database = databaseOf(value);
2365
2529
  break;
2366
2530
  }
2367
2531
  } else {
@@ -2370,8 +2534,8 @@ function clientInput(name, args) {
2370
2534
  }
2371
2535
  if (name === "sqlite3")
2372
2536
  input.statements.push(...input.operands.slice(1));
2373
- else if (input.operands[0] !== undefined)
2374
- input.databases.push(databaseOf(input.operands[0]));
2537
+ else if (input.database === undefined && input.operands[0] !== undefined)
2538
+ input.database = databaseOf(input.operands[0]);
2375
2539
  return input;
2376
2540
  }
2377
2541
  function isTestWord(word) {
@@ -2386,11 +2550,33 @@ function targetWords(words) {
2386
2550
  function isTestScoped(words, client, input) {
2387
2551
  if (client === -1)
2388
2552
  return targetWords(words).some(isTestWord);
2389
- return targetWords(words.slice(0, client)).some(isTestWord) || (input?.databases ?? []).some((name) => TEST_SCOPED.test(name));
2553
+ const named = input?.database;
2554
+ const before = targetWords(words.slice(0, client)).filter((word) => named === undefined || !ASSIGNMENT2.test(word));
2555
+ return before.some(isTestWord) || named !== undefined && TEST_SCOPED.test(named);
2390
2556
  }
2391
2557
  async function fileText(path, read) {
2392
2558
  return DEVICE_PATH.test(path) ? null : read(path);
2393
2559
  }
2560
+ function clientDialect(name) {
2561
+ if (IS_MYSQL.has(name))
2562
+ return "mysql";
2563
+ return name === "sqlite3" ? undefined : "postgres";
2564
+ }
2565
+ async function clientStatements(pieces, index, input, read) {
2566
+ const before = index === 0 ? null : parseCommand(pieces[index - 1]?.command ?? "");
2567
+ const isPiped = pieces[index - 1]?.separator === "|";
2568
+ const paths = input.files.filter((path) => !STDIN_PATHS.has(path));
2569
+ const files = [...paths, ...isPiped && before?.program === "cat" ? before.args.filter((arg) => !arg.startsWith("-")) : []];
2570
+ const texts = await Promise.all(files.map(async (path) => fileText(path, read)));
2571
+ const unreadable = texts.indexOf(null);
2572
+ const statements = [
2573
+ ...input.statements,
2574
+ ...pieces[index]?.heredocs ?? [],
2575
+ isPiped && before !== null && PRINTERS2.has(before.program) ? before.args.join(" ") : "",
2576
+ ...texts.map((text) => text ?? "")
2577
+ ];
2578
+ return { statements, unreadable: unreadable === -1 ? undefined : files[unreadable] };
2579
+ }
2394
2580
  async function sqlViolation(command, read) {
2395
2581
  const pieces = splitCommand(command);
2396
2582
  let inShotStack = false;
@@ -2401,28 +2587,26 @@ async function sqlViolation(command, read) {
2401
2587
  inShotStack = SHOT_STACK.test(args[0] ?? "");
2402
2588
  const client = words.findIndex((word) => SQL_CLIENTS.has(programOf(word)));
2403
2589
  const input = client === -1 ? null : clientInput(programOf(words[client] ?? ""), words.slice(client + 1));
2404
- if (inShotStack || isTestScoped(words, client, input))
2590
+ if (inShotStack)
2591
+ continue;
2592
+ if (isTestScoped(words, client, input)) {
2593
+ const dialect = clientDialect(programOf(words[client] ?? ""));
2594
+ if (input !== null && dialect !== undefined) {
2595
+ const { statements } = await clientStatements(pieces, index, input, read);
2596
+ if (statements.some((statement) => hasWrite(statement) && otherDatabases(statement, dialect, input.database ?? "").length > 0))
2597
+ return SQL_OTHER_DATABASE;
2598
+ }
2405
2599
  continue;
2600
+ }
2406
2601
  if (WRITING_TOOLS.has(program) && !words.some((word) => LIST_OPTIONS.has(word)))
2407
2602
  return SQL_WRITE;
2408
2603
  if (CONSOLE_PROGRAMS.has(program) && words.some((word) => WRITING_CONSOLE.test(word)))
2409
2604
  return SQL_WRITE;
2410
2605
  if (input === null)
2411
2606
  continue;
2412
- const before = index === 0 ? null : parseCommand(pieces[index - 1]?.command ?? "");
2413
- const isPiped = pieces[index - 1]?.separator === "|";
2414
- const paths = input.files.filter((path) => !STDIN_PATHS.has(path));
2415
- const files = [...paths, ...isPiped && before?.program === "cat" ? before.args.filter((arg) => !arg.startsWith("-")) : []];
2416
- const texts = await Promise.all(files.map(async (path) => fileText(path, read)));
2417
- const unreadable = texts.indexOf(null);
2418
- if (unreadable !== -1)
2419
- return sqlUnreadable(files[unreadable] ?? "");
2420
- const statements = [
2421
- ...input.statements,
2422
- ...piece.heredocs,
2423
- isPiped && before !== null && PRINTERS2.has(before.program) ? before.args.join(" ") : "",
2424
- ...texts.map((text) => text ?? "")
2425
- ];
2607
+ const { statements, unreadable } = await clientStatements(pieces, index, input, read);
2608
+ if (unreadable !== undefined)
2609
+ return sqlUnreadable(unreadable);
2426
2610
  if (statements.some(hasWrite))
2427
2611
  return SQL_WRITE;
2428
2612
  }
@@ -2430,11 +2614,12 @@ async function sqlViolation(command, read) {
2430
2614
  }
2431
2615
 
2432
2616
  // ../env/src/guard-dumps.ts
2617
+ import { basename } from "path";
2433
2618
  var OPENER = /^[({]+/;
2434
2619
  var DUMP_FLAGS = /^-[a-z]*[px]/;
2435
2620
  var GIT_PATCHES = new Set(["diff", "log", "show", "whatchanged", "format-patch", "grep"]);
2436
2621
  var GIT_NO_PATCH = new Set(["--stat", "--numstat", "--shortstat", "--name-only", "--name-status", "--summary", "-s", "--no-patch", "--check", "--quiet"]);
2437
- var GIT_VALUE_OPTIONS = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path"]);
2622
+ var GIT_VALUE_OPTIONS = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env", "--attr-source"]);
2438
2623
  var GIT_PATCH_FLAGS = new Set(["-p", "-u", "--patch", "-c", "--cc", "--patch-with-stat", "--patch-with-raw"]);
2439
2624
  var GIT_EXCLUDE = /^:(?:!|\^|\(exclude\))/;
2440
2625
  var ENV_PRINTERS = new Set(["env", "printenv"]);
@@ -2443,6 +2628,7 @@ var SHELLS2 = new Set(["sh", "bash", "zsh", "ash"]);
2443
2628
  var SHELL_COMMAND_FLAG = /^-[abd-z]*c[a-z]*$/;
2444
2629
  var DOCKER_VALUE_OPTIONS = new Set(["-f", "--file", "-p", "--project-name", "--profile", "--env-file", "--project-directory", "--ansi", "--progress", "--parallel", "-H", "--host", "-c", "--context", "--config", "-l", "--log-level"]);
2445
2630
  var EXEC_VALUE_OPTIONS = new Set(["-e", "--env", "--env-file", "-u", "--user", "-w", "--workdir", "--index", "--detach-keys"]);
2631
+ var RUN_VALUE_OPTIONS = new Set([...EXEC_VALUE_OPTIONS, "-a", "--attach", "--add-host", "--annotation", "--blkio-weight", "--cap-add", "--cap-drop", "--cgroup-parent", "--cgroupns", "--cidfile", "-c", "--cpu-shares", "--cpus", "--cpuset-cpus", "--cpuset-mems", "--cpu-period", "--cpu-quota", "--device", "--dns", "--dns-option", "--dns-search", "--domainname", "--entrypoint", "--env-from-file", "--expose", "--gpus", "--group-add", "--health-cmd", "--health-interval", "--health-retries", "--health-start-period", "--health-timeout", "-h", "--hostname", "--ip", "--ip6", "--ipc", "--isolation", "-l", "--label", "--label-file", "--link", "--log-driver", "--log-opt", "--mac-address", "-m", "--memory", "--memory-reservation", "--memory-swap", "--mount", "--name", "--network", "--net", "--network-alias", "--pid", "--pids-limit", "--platform", "-p", "--publish", "--pull", "--restart", "--runtime", "--security-opt", "--shm-size", "--stop-signal", "--stop-timeout", "--storage-opt", "--sysctl", "--tmpfs", "--ulimit", "--userns", "--uts", "-v", "--volume", "--volumes-from"]);
2446
2632
  var CONFIG_LISTS = new Set(["--services", "--volumes", "--profiles", "--images", "--networks", "--hash", "-q", "--quiet"]);
2447
2633
  var FORMAT_OPTIONS = new Set(["-f", "--format"]);
2448
2634
  var WHOLE_FORMAT = /Env|\{\{\s*json\s+\.\s*\}\}|^json$/;
@@ -2456,11 +2642,19 @@ function firstOperand(words, valueOptions) {
2456
2642
  }
2457
2643
  return words.length;
2458
2644
  }
2645
+ function isEnvPrinter(program) {
2646
+ return ENV_PRINTERS.has(basename(program));
2647
+ }
2459
2648
  function printsEnv([program = "", ...args]) {
2460
2649
  const flags = args.findIndex((arg) => !arg.startsWith("-") || SHELL_COMMAND_FLAG.test(arg));
2461
- if (SHELLS2.has(program) && SHELL_COMMAND_FLAG.test(args[flags] ?? ""))
2462
- return splitCommand(args[flags + 1] ?? "").some((piece) => ENV_PRINTERS.has(tokenize(piece.command)[0] ?? ""));
2463
- return ENV_PRINTERS.has(program);
2650
+ if (SHELLS2.has(basename(program)) && SHELL_COMMAND_FLAG.test(args[flags] ?? ""))
2651
+ return splitCommand(args[flags + 1] ?? "").some((piece) => isEnvPrinter(tokenize(piece.command)[0] ?? ""));
2652
+ return isEnvPrinter(program);
2653
+ }
2654
+ function runPrintsEnv(after) {
2655
+ const entrypoint = after.find((_, i) => after[i - 1] === "--entrypoint") ?? after.find((word) => word.startsWith("--entrypoint="))?.slice("--entrypoint=".length);
2656
+ const command = after.slice(firstOperand(after, RUN_VALUE_OPTIONS) + 1);
2657
+ return printsEnv(entrypoint === undefined || entrypoint === "" ? command : [entrypoint, ...command]);
2464
2658
  }
2465
2659
  function dumpsContainerEnv(program, args) {
2466
2660
  if (!DOCKER.has(program))
@@ -2470,9 +2664,11 @@ function dumpsContainerEnv(program, args) {
2470
2664
  const isCompose = program === "docker-compose" || rest[0] === "compose";
2471
2665
  if (program === "docker" && isCompose)
2472
2666
  rest = afterOptions(rest.slice(1));
2473
- const [subcommand = "", ...after] = rest;
2667
+ const [subcommand = "", ...after] = !isCompose && rest[0] === "container" && ["exec", "run"].includes(rest[1] ?? "") ? rest.slice(1) : rest;
2474
2668
  if (subcommand === "exec")
2475
2669
  return printsEnv(after.slice(firstOperand(after, EXEC_VALUE_OPTIONS) + 1));
2670
+ if (subcommand === "run")
2671
+ return runPrintsEnv(after);
2476
2672
  if (isCompose)
2477
2673
  return subcommand === "config" && !after.some((word) => CONFIG_LISTS.has(word));
2478
2674
  if (subcommand !== "inspect" && (subcommand !== "container" || after[0] !== "inspect"))
@@ -2488,7 +2684,7 @@ function dumpsEnvironment(program, args, tokens) {
2488
2684
  return isBare && args.some((arg) => DUMP_FLAGS.test(arg));
2489
2685
  if (program === "set")
2490
2686
  return args.length === 0;
2491
- return program === "" && tokens.some((token) => token.replace(OPENER, "") === "env");
2687
+ return program === "" && tokens.some((token) => basename(token.replace(OPENER, "")) === "env");
2492
2688
  }
2493
2689
  function printsTrackedEnv(program, args) {
2494
2690
  if (program !== "git")
@@ -2524,7 +2720,20 @@ function isWeak(value, before) {
2524
2720
  return isProse(value, before) || !(DIGIT.test(value) || value.length >= 16);
2525
2721
  }
2526
2722
  function keyed(names, value) {
2527
- return new RegExp(`(?<![\\w-])["']?(?:[\\w-]{0,30}[_-])?(?:${names})(?:[_-][\\w-]{0,30})?["']?${KEY_VALUE_GAP}${value}`, "dgi");
2723
+ return new RegExp(`(?<![\\w-])["']?(?<name>(?:[\\w-]{0,30}[_-])?(?:${names})(?:[_-][\\w-]{0,30})?)["']?${KEY_VALUE_GAP}${value}`, "dgi");
2724
+ }
2725
+ var ANY_NAME = `(?<![\\w.-])["']?(?<name>[a-z_][\\w.-]{0,60})["']?`;
2726
+ var PASSWORD_NAME = new RegExp(`${STRONG_NAME}|pass|pwd`, "i");
2727
+ var SETTING_SUFFIX = /[_.-](?:TTL|FILE|PATH|DIR|NAME|URL|TIMEOUT|EXPIRY|EXPIRES|LIFETIME|LENGTH|ENABLED|ALGORITHM|HEADER|PREFIX|COUNT|MAX|MIN)$/i;
2728
+ var NUMBER = /^\d+$/;
2729
+ var COUNT_NAME = /(?:^|[_.-])(?:max|min|num)[_.-]|^tokens$/i;
2730
+ function isSetting(value, name) {
2731
+ return SETTING_SUFFIX.test(name) || COUNT_NAME.test(name) && NUMBER.test(value);
2732
+ }
2733
+ function isPlainNamed(value, before, name = "") {
2734
+ if (!isSecretName(name) || isSetting(value, name) || value.length < 4 || value.includes("-----BEGIN "))
2735
+ return true;
2736
+ return PASSWORD_NAME.test(name) ? isProse(value, before) : isWeak(value, before);
2528
2737
  }
2529
2738
  var TOKEN_FORMATS = [
2530
2739
  { kind: "GitHub token", pattern: /\b(?:gh[pousr]_|github_pat_)\w{20,}/dg },
@@ -2545,10 +2754,13 @@ var TOKEN_FORMATS = [
2545
2754
  { kind: "SendGrid key", pattern: /\bSG\.[\w-]{16,}\.[\w-]{16,}/dg },
2546
2755
  { kind: "Authorization header", pattern: /\bAuthorization["']?\s*[:=]\s*["']?(?:Bearer|Basic|Token|Digest)\s+([^\s"',;]{8,})/dgi, skip: isPlaceholder },
2547
2756
  { kind: "Bearer token", pattern: /\bBearer\s+((?=[\w.~+/=-]*\d)[\w.~+/=-]{20,})/dg },
2548
- { kind: "password", pattern: keyed(STRONG_NAME, `([^\\s"'&;,]{4,})`), skip: isProse },
2549
- { kind: "password", pattern: keyed(WEAK_NAME, `([^\\s"'&;,]{4,})`), skip: isWeak },
2550
- { kind: "password", pattern: keyed(STRONG_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isPlaceholder },
2551
- { kind: "password", pattern: keyed(WEAK_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isWeak }
2757
+ { kind: "password", pattern: keyed(STRONG_NAME, `([^\\s"'&;,]{4,})`), skip: (value, before, name = "") => isSetting(value, name) || isProse(value, before) },
2758
+ { kind: "password", pattern: keyed(WEAK_NAME, `([^\\s"'&;,]{4,})`), skip: (value, before, name = "") => isSetting(value, name) || isWeak(value, before) },
2759
+ { kind: "password", pattern: keyed(STRONG_NAME, `(["'])((?:\\\\.|(?!\\2)[^\\\\\\n]){4,})\\2`), skip: (value, _, name = "") => isSetting(value, name) || isPlaceholder(value) },
2760
+ { kind: "password", pattern: keyed(WEAK_NAME, `(["'])((?:\\\\.|(?!\\2)[^\\\\\\n]){4,})\\2`), skip: (value, before, name = "") => isSetting(value, name) || isWeak(value, before) },
2761
+ { kind: "password", pattern: new RegExp(`${ANY_NAME}${KEY_VALUE_GAP}([^\\s"'&;,]{4,})`, "dgi"), skip: isPlainNamed },
2762
+ { kind: "password", pattern: new RegExp(`${ANY_NAME}${KEY_VALUE_GAP}(["'])((?:\\\\.|(?!\\2)[^\\\\\\n]){4,})\\2`, "dgi"), skip: isPlainNamed },
2763
+ { kind: "password", pattern: /^\s*(?:export\s+)?(?<name>[A-Za-z_]\w{0,60})=(?!["'])(\S(?:.*\S)?)/dg, skip: isPlainNamed }
2552
2764
  ];
2553
2765
 
2554
2766
  // ../env/src/files.ts
@@ -3063,11 +3275,151 @@ function wrap(command) {
3063
3275
  import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
3064
3276
  import { dirname as dirname4, join as join6 } from "path";
3065
3277
  import process17 from "process";
3278
+
3279
+ // ../pkg/src/pin.ts
3280
+ var LOCKFILES = [
3281
+ ["bun.lock", "bun"],
3282
+ ["bun.lockb", "bun"],
3283
+ ["pnpm-lock.yaml", "pnpm"],
3284
+ ["yarn.lock", "yarn"],
3285
+ ["package-lock.json", "npm"]
3286
+ ];
3287
+ var NPM_INSTALLS = ["install", "i", "in", "ins", "inst", "insta", "instal", "isnt", "isnta", "isntal", "isntall"];
3288
+ var NPM_TEST_INSTALLS = ["it", "install-test", "cit", "clean-install-test", "install-ci-test"];
3289
+ var ACTIONS = {
3290
+ bun: actions({ install: ["install", "i"], add: ["add", "a"], remove: ["remove", "rm"], update: ["update"] }),
3291
+ pnpm: actions({ install: ["install", "i"], add: ["add"], remove: ["remove", "rm"], update: ["update", "up"] }),
3292
+ yarn: new Map([...actions({ install: ["", "install"], add: ["add"], remove: ["remove"], update: ["upgrade"] }), ["upgrade-interactive", null], ["import", null]]),
3293
+ npm: new Map([...actions({
3294
+ install: NPM_INSTALLS,
3295
+ add: ["add"],
3296
+ frozen: ["ci", "clean-install", "ic", "install-clean", "isntall-clean"],
3297
+ remove: ["uninstall", "unlink", "remove", "rm", "r", "un"],
3298
+ update: ["update", "u", "up", "upgrade", "udpate"]
3299
+ }), ...NPM_TEST_INSTALLS.map((name) => [name, null])])
3300
+ };
3301
+ var COMMANDS = {
3302
+ bun: { install: "install", frozen: "install --frozen-lockfile", add: "add", remove: "remove", update: "update" },
3303
+ pnpm: { install: "install", frozen: "install --frozen-lockfile", add: "add", remove: "remove", update: "update" },
3304
+ yarn: { install: "install", add: "add", remove: "remove" },
3305
+ npm: { install: "install", frozen: "ci", add: "install", remove: "uninstall", update: "update" }
3306
+ };
3307
+ var OPTIONS = {
3308
+ bun: { dev: "--dev", exact: "--exact" },
3309
+ pnpm: { dev: "--save-dev", exact: "--save-exact" },
3310
+ yarn: { dev: "--dev", exact: "--exact" },
3311
+ npm: { dev: "--save-dev", exact: "--save-exact" }
3312
+ };
3313
+ var OPTION_FLAGS = new Map([
3314
+ ["-D", "dev"],
3315
+ ["--save-dev", "dev"],
3316
+ ["--dev", "dev"],
3317
+ ["-E", "exact"],
3318
+ ["--save-exact", "exact"],
3319
+ ["--exact", "exact"]
3320
+ ]);
3321
+ var DIR_FLAGS = new Set(["--cwd", "-C", "--dir", "--prefix"]);
3322
+ var VALUE_FLAGS = new Set([...DIR_FLAGS, "--filter", "-F"]);
3323
+ var PLAIN_WORD2 = /^[\w=@./:+-]+$/;
3324
+ var AROUND_START = /^[\s(]*/;
3325
+ var AROUND_END = /[\s)]*$/;
3326
+ function actions(byAction) {
3327
+ return new Map(Object.entries(byAction).flatMap(([action, names]) => names.map((name) => [name, action])));
3328
+ }
3329
+ function isManager(program) {
3330
+ return Object.hasOwn(ACTIONS, program);
3331
+ }
3332
+ function translate(from, to, subcommand, rest) {
3333
+ const packages = rest.filter((arg) => !arg.startsWith("-"));
3334
+ const flags = rest.filter((arg) => arg.startsWith("-"));
3335
+ const listed = ACTIONS[from].get(subcommand);
3336
+ const action = listed === "install" && packages.length > 0 ? "add" : listed;
3337
+ const command = action ? COMMANDS[to][action] : undefined;
3338
+ if (!action || command === undefined || !packages.every((name) => PLAIN_WORD2.test(name)))
3339
+ return null;
3340
+ const options = [];
3341
+ for (const flag of flags) {
3342
+ const option = OPTION_FLAGS.get(flag) ?? (from === "bun" && flag === "-d" ? "dev" : undefined);
3343
+ if (option === undefined || action !== "add")
3344
+ return null;
3345
+ options.push(OPTIONS[to][option]);
3346
+ }
3347
+ return [to, command, ...options, ...packages].join(" ");
3348
+ }
3349
+ function installRequests(command, cwd, home) {
3350
+ const requests = [];
3351
+ const outer = [];
3352
+ for (const piece of splitCommand(command)) {
3353
+ const { opened, closed } = parenBalance(piece.command);
3354
+ for (let count = 0;count < opened; count++)
3355
+ outer.push(cwd);
3356
+ const request = requestOf(piece, cwd, home);
3357
+ if (typeof request === "string")
3358
+ cwd = request;
3359
+ else if (request !== undefined)
3360
+ requests.push(request);
3361
+ for (let count = 0;count < closed; count++)
3362
+ cwd = outer.pop() ?? cwd;
3363
+ }
3364
+ return requests;
3365
+ }
3366
+ function requestOf(piece, cwd, home) {
3367
+ const { program, args, assignments, isWrapped } = parseCommand(piece.command);
3368
+ if (program === "cd" && args[0] !== undefined)
3369
+ return resolvePath(cwd, args[0], home);
3370
+ if (!isManager(program))
3371
+ return;
3372
+ let dir = cwd;
3373
+ let subcommand = "";
3374
+ let rest = [];
3375
+ let hasLeadingFlag = false;
3376
+ for (let i = 0;i < args.length; i++) {
3377
+ const arg = args[i] ?? "";
3378
+ const equals = arg.indexOf("=");
3379
+ const flag = equals === -1 ? arg : arg.slice(0, equals);
3380
+ const value = equals === -1 ? undefined : arg.slice(equals + 1);
3381
+ const isLeading = subcommand === "";
3382
+ if (DIR_FLAGS.has(flag) && value !== undefined && value !== "") {
3383
+ dir = resolvePath(cwd, value, home);
3384
+ } else if (VALUE_FLAGS.has(arg)) {
3385
+ if (DIR_FLAGS.has(arg) && args[i + 1] !== undefined)
3386
+ dir = resolvePath(cwd, args[i + 1] ?? "", home);
3387
+ i++;
3388
+ } else if (isLeading && !arg.startsWith("-")) {
3389
+ subcommand = arg;
3390
+ rest = args.slice(i + 1);
3391
+ continue;
3392
+ }
3393
+ hasLeadingFlag ||= isLeading;
3394
+ }
3395
+ return ACTIONS[program].has(subcommand) ? { piece, program, subcommand, rest, dir, assignments, isRewritable: !hasLeadingFlag && !isWrapped && piece.command === piece.text } : undefined;
3396
+ }
3397
+ function bareCommand(text) {
3398
+ return text.replace(AROUND_START, "").replace(AROUND_END, "");
3399
+ }
3400
+ function mismatchFor(request, pinned) {
3401
+ const { piece, program, subcommand, rest, isRewritable, assignments } = request;
3402
+ if (!pinned || pinned.managers.has(program))
3403
+ return null;
3404
+ const expected = [...pinned.managers];
3405
+ const only = expected.length === 1 ? expected[0] : undefined;
3406
+ const canRewrite = only !== undefined && isRewritable && assignments.every((word) => PLAIN_WORD2.test(word));
3407
+ const translated = canRewrite ? translate(program, only, subcommand, rest) : null;
3408
+ const leading = AROUND_START.exec(piece.text)?.[0] ?? "";
3409
+ const trailing = AROUND_END.exec(piece.text)?.[0] ?? "";
3410
+ return {
3411
+ piece,
3412
+ rewrite: translated === null ? null : `${leading}${[...assignments, translated].join(" ")}${trailing}`,
3413
+ reason: `${pinned.dir} is pinned to ${expected.join(" or ")} by its lockfile, so \`${`${program} ${subcommand}`.trim()}\` would install with the wrong package manager.`
3414
+ };
3415
+ }
3416
+
3417
+ // ../pkg/src/added.ts
3066
3418
  var REDIRECT2 = /^\d*[<>]/;
3067
3419
  var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
3068
3420
  var ADDS = {
3069
3421
  bun: new Set(["add", "a", "install", "i"]),
3070
- npm: new Set(["install", "i", "add", "in", "isntall"]),
3422
+ npm: new Set([...NPM_INSTALLS, ...NPM_TEST_INSTALLS, "add"]),
3071
3423
  pnpm: new Set(["add", "i", "install"]),
3072
3424
  yarn: new Set(["add"])
3073
3425
  };
@@ -3079,8 +3431,9 @@ var RUNS = {
3079
3431
  };
3080
3432
  var RUNNERS = new Set(["bunx", "npx"]);
3081
3433
  var PACKAGE_FLAGS = new Set(["-p", "--package"]);
3082
- var VALUE_FLAGS = new Set(["--cwd", "--filter", "-F", "-c", "--call", "--workspace", "--registry", "--prefix", "-C", "--dir", "--config", "--cache-dir", "--loglevel", "--tag", "--save-prefix", "--userconfig", "--omit", "--include", "--fetch-timeout", "--fetch-retries", "--install-strategy", "--cache", ...PACKAGE_FLAGS]);
3083
- var NOT_REGISTRY = /^(?:[./~]|file:|link:|portal:|workspace:|git[+:]|github:|gitlab:|bitbucket:|https?:)|\.tgz$|^[\w.-]+\/[\w.-]+(?:#.*)?$/;
3434
+ var VALUE_FLAGS2 = new Set(["--cwd", "--filter", "-F", "-c", "--call", "--workspace", "--registry", "--prefix", "-C", "--dir", "--config", "--cache-dir", "--loglevel", "--tag", "--save-prefix", "--userconfig", "--omit", "--include", "--fetch-timeout", "--fetch-retries", "--install-strategy", "--cache", "--linker", ...PACKAGE_FLAGS]);
3435
+ var OWN_VALUE_FLAGS = { npm: new Set(["-w"]) };
3436
+ var NOT_REGISTRY = /^(?:[./]|~(?:\/|$)|file:|link:|portal:|workspace:|catalog:|git[+:]|github:|gitlab:|bitbucket:|https?:)|\.tgz$|^[\w.-]+\/[\w.-]+(?:#.*)?$/;
3084
3437
  var NPM_ALIAS = /^(?:@[^/]+\/)?[^@]+@npm:(.+)$/;
3085
3438
  var PUBLISH = /\b(?:ft|cli\.ts)\s+release\b|\b(?:bun|npm|pnpm|yarn)\s+publish\b|\bjust\s+(?:patch|minor|major)\b/;
3086
3439
  var EXACT_SPEC = /^(?:@[^/]+\/)?[^@]+@\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
@@ -3133,13 +3486,17 @@ function piecePackages(program, sub, args, rest) {
3133
3486
  return runnerPackages(rest);
3134
3487
  if (!ADDS[program]?.has(sub))
3135
3488
  return [];
3136
- return rest.flatMap((word, index) => isSkipped(word, rest[index - 1] ?? "") ? [] : registryName(word));
3489
+ return rest.flatMap((word, index) => isSkipped(word, rest[index - 1] ?? "", program) ? [] : registryName(word));
3137
3490
  }
3138
- function isSkipped(word, previous) {
3139
- return word.startsWith("-") || REDIRECT2.test(word) || VALUE_FLAGS.has(previous) || BARE_REDIRECT.test(previous);
3491
+ function isSkipped(word, previous, program = "") {
3492
+ return word.startsWith("-") || REDIRECT2.test(word) || VALUE_FLAGS2.has(previous) || OWN_VALUE_FLAGS[program]?.has(previous) === true || BARE_REDIRECT.test(previous);
3140
3493
  }
3141
3494
  function registryName(word) {
3142
- return NOT_REGISTRY.test(word) ? [] : [NPM_ALIAS.exec(word)?.[1] ?? word];
3495
+ const at = word.indexOf("@", 1);
3496
+ const spec = at === -1 ? word : word.slice(at + 1);
3497
+ if (NOT_REGISTRY.test(word) || at !== -1 && !spec.startsWith("npm:") && NOT_REGISTRY.test(spec))
3498
+ return [];
3499
+ return [NPM_ALIAS.exec(word)?.[1] ?? word];
3143
3500
  }
3144
3501
  function runnerPackages(words) {
3145
3502
  const named = [];
@@ -3157,133 +3514,54 @@ function runnerPackages(words) {
3157
3514
  return named.flatMap(registryName);
3158
3515
  }
3159
3516
 
3160
- // ../pkg/src/pin.ts
3161
- var LOCKFILES = [
3162
- ["bun.lock", "bun"],
3163
- ["bun.lockb", "bun"],
3164
- ["pnpm-lock.yaml", "pnpm"],
3165
- ["yarn.lock", "yarn"],
3166
- ["package-lock.json", "npm"]
3167
- ];
3168
- var ACTIONS = {
3169
- bun: actions({ install: ["install", "i"], add: ["add", "a"], remove: ["remove", "rm"], update: ["update"] }),
3170
- pnpm: actions({ install: ["install", "i"], add: ["add"], remove: ["remove", "rm"], update: ["update", "up"] }),
3171
- yarn: new Map([...actions({ install: ["", "install"], add: ["add"], remove: ["remove"], update: ["upgrade"] }), ["upgrade-interactive", null], ["import", null]]),
3172
- npm: actions({
3173
- install: ["install", "i", "in", "ins", "inst", "insta", "instal", "isnt", "isnta", "isntal", "isntall"],
3174
- add: ["add"],
3175
- frozen: ["ci", "clean-install", "ic", "install-clean", "isntall-clean"],
3176
- remove: ["uninstall", "unlink", "remove", "rm", "r", "un"],
3177
- update: ["update", "u", "up", "upgrade", "udpate"]
3178
- })
3179
- };
3180
- var COMMANDS = {
3181
- bun: { install: "install", frozen: "install --frozen-lockfile", add: "add", remove: "remove", update: "update" },
3182
- pnpm: { install: "install", frozen: "install --frozen-lockfile", add: "add", remove: "remove", update: "update" },
3183
- yarn: { install: "install", add: "add", remove: "remove" },
3184
- npm: { install: "install", frozen: "ci", add: "install", remove: "uninstall", update: "update" }
3185
- };
3186
- var OPTIONS = {
3187
- bun: { dev: "--dev", exact: "--exact" },
3188
- pnpm: { dev: "--save-dev", exact: "--save-exact" },
3189
- yarn: { dev: "--dev", exact: "--exact" },
3190
- npm: { dev: "--save-dev", exact: "--save-exact" }
3191
- };
3192
- var OPTION_FLAGS = new Map([
3193
- ["-D", "dev"],
3194
- ["--save-dev", "dev"],
3195
- ["--dev", "dev"],
3196
- ["-E", "exact"],
3197
- ["--save-exact", "exact"],
3198
- ["--exact", "exact"]
3199
- ]);
3200
- var DIR_FLAGS = new Set(["--cwd", "-C", "--dir", "--prefix"]);
3201
- var VALUE_FLAGS2 = new Set([...DIR_FLAGS, "--filter", "-F"]);
3202
- var PLAIN_WORD2 = /^[\w=@./:+-]+$/;
3203
- function actions(byAction) {
3204
- return new Map(Object.entries(byAction).flatMap(([action, names]) => names.map((name) => [name, action])));
3205
- }
3206
- function isManager(program) {
3207
- return Object.hasOwn(ACTIONS, program);
3208
- }
3209
- function translate(from, to, subcommand, rest) {
3210
- const packages = rest.filter((arg) => !arg.startsWith("-"));
3211
- const flags = rest.filter((arg) => arg.startsWith("-"));
3212
- const listed = ACTIONS[from].get(subcommand);
3213
- const action = listed === "install" && packages.length > 0 ? "add" : listed;
3214
- const command = action ? COMMANDS[to][action] : undefined;
3215
- if (!action || command === undefined || !packages.every((name) => PLAIN_WORD2.test(name)))
3216
- return null;
3217
- const options = [];
3218
- for (const flag of flags) {
3219
- const option = OPTION_FLAGS.get(flag) ?? (from === "bun" && flag === "-d" ? "dev" : undefined);
3220
- if (option === undefined || action !== "add")
3221
- return null;
3222
- options.push(OPTIONS[to][option]);
3223
- }
3224
- return [to, command, ...options, ...packages].join(" ");
3225
- }
3226
- function installRequests(command, cwd, home) {
3227
- const requests = [];
3228
- for (const piece of splitCommand(command)) {
3229
- const { program, args, assignments, isWrapped } = parseCommand(piece.command);
3230
- if (program === "cd" && args[0] !== undefined) {
3231
- cwd = resolvePath(cwd, args[0], home);
3232
- continue;
3233
- }
3234
- if (!isManager(program))
3235
- continue;
3236
- let dir = cwd;
3237
- let subcommand = "";
3238
- let rest = [];
3239
- let hasLeadingFlag = false;
3240
- for (let i = 0;i < args.length; i++) {
3241
- const arg = args[i] ?? "";
3242
- const equals = arg.indexOf("=");
3243
- const flag = equals === -1 ? arg : arg.slice(0, equals);
3244
- const value = equals === -1 ? undefined : arg.slice(equals + 1);
3245
- if (DIR_FLAGS.has(flag) && value !== undefined && value !== "") {
3246
- dir = resolvePath(cwd, value, home);
3247
- } else if (VALUE_FLAGS2.has(arg)) {
3248
- if (DIR_FLAGS.has(arg) && args[i + 1] !== undefined)
3249
- dir = resolvePath(cwd, args[i + 1] ?? "", home);
3250
- i++;
3251
- } else if (!arg.startsWith("-")) {
3252
- subcommand = arg;
3253
- rest = args.slice(i + 1);
3254
- break;
3255
- }
3256
- hasLeadingFlag = true;
3257
- }
3258
- if (ACTIONS[program].has(subcommand))
3259
- requests.push({ piece, program, subcommand, rest, dir, assignments, isRewritable: !hasLeadingFlag && !isWrapped && piece.command === piece.text });
3260
- }
3261
- return requests;
3262
- }
3263
- function mismatchFor(request, pinned) {
3264
- const { piece, program, subcommand, rest, isRewritable, assignments } = request;
3265
- if (!pinned || pinned.managers.has(program))
3266
- return null;
3267
- const expected = [...pinned.managers];
3268
- const only = expected.length === 1 ? expected[0] : undefined;
3269
- const canRewrite = only !== undefined && isRewritable && assignments.every((word) => PLAIN_WORD2.test(word));
3270
- const translated = canRewrite ? translate(program, only, subcommand, rest) : null;
3271
- const leading = piece.text.slice(0, piece.text.length - piece.text.trimStart().length);
3272
- const trailing = piece.text.slice(piece.text.trimEnd().length);
3273
- return {
3274
- piece,
3275
- rewrite: translated === null ? null : `${leading}${[...assignments, translated].join(" ")}${trailing}`,
3276
- reason: `${pinned.dir} is pinned to ${expected.join(" or ")} by its lockfile, so \`${`${program} ${subcommand}`.trim()}\` would install with the wrong package manager.`
3277
- };
3278
- }
3279
-
3280
3517
  // src/git.ts
3281
- var GLOBAL_VALUE_OPTIONS = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env"]);
3518
+ var GLOBAL_VALUE_OPTIONS = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env", "--attr-source"]);
3282
3519
  var READ_ONLY_STASH = new Set(["list", "show"]);
3283
3520
  var WHOLE_TREE = new Set(["-A", "--all", "-u", "--update", "--no-ignore-removal", ".", "./", ":/", "*"]);
3284
3521
  var COMMIT_VALUE_SHORTS = new Set(["m", "F", "c", "C", "t"]);
3522
+ var COMMIT_ATTACHED_SHORTS = new Set(["u", "S"]);
3285
3523
  var COMMIT_VALUE_LONGS = new Set(["--message", "--file", "--reuse-message", "--reedit-message", "--template", "--author", "--date", "--fixup", "--squash", "--cleanup", "--trailer", "--pathspec-from-file"]);
3524
+ var LONG_OPTIONS = {
3525
+ add: ["--all", "--update", "--no-ignore-removal", "--dry-run", "--patch", "--intent-to-add", "--force", "--pathspec-from-file"],
3526
+ branch: ["--delete", "--force", "--move", "--copy", "--list", "--show-current"],
3527
+ checkout: ["--force", "--patch", "--ours", "--theirs", "--merge", "--detach", "--orphan", "--track", "--quiet", "--progress", "--pathspec-from-file"],
3528
+ clean: ["--force", "--dry-run", "--quiet", "--exclude", "--interactive"],
3529
+ commit: ["--all", "--signoff", ...COMMIT_VALUE_LONGS, "--amend", "--no-verify", "--edit", "--no-edit", "--quiet", "--patch", "--include", "--only", "--interactive", "--dry-run", "--allow-empty", "--allow-empty-message", "--reset-author", "--gpg-sign", "--status", "--verbose"],
3530
+ push: ["--force", "--mirror", "--delete", "--tags", "--follow-tags", "--force-with-lease", "--force-if-includes", "--atomic", "--all", "--branches", "--prune", "--dry-run", "--set-upstream", "--no-verify", "--porcelain", "--quiet", "--verbose", "--progress", "--push-option", "--repo", "--recurse-submodules", "--signed", "--thin"],
3531
+ reset: ["--hard", "--soft", "--mixed", "--merge", "--keep", "--patch", "--quiet", "--recurse-submodules", "--pathspec-from-file"],
3532
+ restore: ["--staged", "--worktree", "--patch", "--source", "--ours", "--theirs", "--merge", "--quiet", "--progress", "--overlay", "--no-overlay", "--ignore-unmerged", "--pathspec-from-file"],
3533
+ rm: ["--cached", "--dry-run", "--force", "--quiet", "--ignore-unmatch", "--sparse", "--pathspec-from-file"],
3534
+ switch: ["--force", "--discard-changes", "--create", "--force-create", "--detach", "--guess", "--merge", "--orphan", "--track", "--quiet", "--progress"]
3535
+ };
3286
3536
  var SHORT_CLUSTER = /^-[A-Z]+$/i;
3537
+ var LONG_VALUES = new Set([...COMMIT_VALUE_LONGS, "--source", "--push-option", "--repo", "--exclude"]);
3538
+ function takesNextWord(name, word) {
3539
+ if (name !== "commit" || !SHORT_CLUSTER.test(word))
3540
+ return false;
3541
+ const letters = [...word.slice(1)];
3542
+ const at = letters.findIndex((letter) => COMMIT_VALUE_SHORTS.has(letter) || COMMIT_ATTACHED_SHORTS.has(letter));
3543
+ return at === letters.length - 1 && COMMIT_VALUE_SHORTS.has(letters[at] ?? "");
3544
+ }
3545
+ function fullLongOptions(name, rest) {
3546
+ const known = LONG_OPTIONS[name] ?? [];
3547
+ const words = [...rest];
3548
+ for (let i = 0;i < words.length; i++) {
3549
+ const word = words[i] ?? "";
3550
+ if (word === "--")
3551
+ break;
3552
+ if (!word.startsWith("--")) {
3553
+ if (takesNextWord(name, word))
3554
+ i++;
3555
+ continue;
3556
+ }
3557
+ const [spelled = "", ...value] = word.split("=");
3558
+ const option = known.includes(spelled) || spelled.length <= 2 ? spelled : known.find((each) => each.startsWith(spelled)) ?? spelled;
3559
+ words[i] = value.length > 0 ? `${option}=${value.join("=")}` : option;
3560
+ if (value.length === 0 && LONG_VALUES.has(option))
3561
+ i++;
3562
+ }
3563
+ return words;
3564
+ }
3287
3565
  var SHORT_OPTIONS = /^-[A-Z]/i;
3288
3566
  var STAGES_ALL = /[Au]/;
3289
3567
  var ALL_TAGS = new Set(["--tags", "--follow-tags"]);
@@ -3292,7 +3570,7 @@ var RISKY_CONFIG = /^(?:alias\.|core\.(?:sshcommand|hookspath|pager|editor|fsmon
3292
3570
  var RISKY_ENV = /^GIT_(?:CONFIG_(?:COUNT|PARAMETERS)|EXTERNAL_DIFF|ASKPASS|PROXY_COMMAND|PAGER)=/;
3293
3571
  var READS_CONFIG = new Set(["--get", "--get-all", "--get-regexp", "--list", "-l", "--unset", "--unset-all", "--show-origin", "--show-scope"]);
3294
3572
  var STAGE_BY_PATH = `Stage by path: the tree carries unrelated work and peer sessions edit it live. ${USE_GC}`;
3295
- var STASH = "Never `git stash`: a pop with nothing saved applies someone else's old stash. To prove a test fails without your change, `base proof --keep <test> -- <cmd>` runs it at HEAD in a temporary worktree and again here; `base -- <cmd>` runs any command at HEAD (`--ref <rev>` another commit), the working tree untouched. To set edits aside before a cherry-pick, a rebase or a checkout, commit them with `gc` first, or do the other work in `git worktree add`.";
3573
+ var STASH = "Never `git stash`: a pop with nothing saved applies someone else's old stash. To prove a test fails without your change, `base proof --keep <test> -- <cmd>` runs it at HEAD in a temporary worktree and again here; `base -- <cmd>` runs any command at HEAD (`--ref <rev>` another commit), its changes left out of the run. To set edits aside before a cherry-pick, a rebase or a checkout, commit them with `gc` first, or do the other work in `git worktree add`.";
3296
3574
  var ADD_ALL = `\`git add\` over the whole tree is refused. ${STAGE_BY_PATH}`;
3297
3575
  var COMMIT_ALL = `\`git commit -a\` stages the whole tree and is refused. ${STAGE_BY_PATH}`;
3298
3576
  var PUSH = "`git push` and `gp` run only when the user asked for a push in their latest prompt: say the commit is ready and let them ask.";
@@ -3300,7 +3578,7 @@ var CONFIG_OVERRIDE = "Never set git config that runs a program or defines a com
3300
3578
  var TAGS_APART = "A tag goes out with its branch in one `git push --atomic origin <branch> <tag>`, never a separate `git push --tags`.";
3301
3579
  function gitCommandOf(program, args) {
3302
3580
  if (program === "gp")
3303
- return { name: "push", rest: args.includes("--") ? args.slice(args.indexOf("--") + 1) : [] };
3581
+ return { name: "push", rest: fullLongOptions("push", args.includes("--") ? args.slice(args.indexOf("--") + 1) : []) };
3304
3582
  return program === "git" ? subcommandOf(args) : undefined;
3305
3583
  }
3306
3584
  function subcommandOf(args) {
@@ -3309,7 +3587,7 @@ function subcommandOf(args) {
3309
3587
  if (GLOBAL_VALUE_OPTIONS.has(arg))
3310
3588
  i++;
3311
3589
  else if (!arg.startsWith("-"))
3312
- return { name: arg, rest: args.slice(i + 1) };
3590
+ return { name: arg, rest: fullLongOptions(arg, args.slice(i + 1)) };
3313
3591
  }
3314
3592
  return { name: "", rest: [] };
3315
3593
  }
@@ -3358,6 +3636,8 @@ function commitsAll(args) {
3358
3636
  for (const [index, flag] of [...arg.slice(1)].entries()) {
3359
3637
  if (flag === "a")
3360
3638
  return true;
3639
+ if (COMMIT_ATTACHED_SHORTS.has(flag))
3640
+ break;
3361
3641
  if (!COMMIT_VALUE_SHORTS.has(flag))
3362
3642
  continue;
3363
3643
  if (index === arg.length - 2)
@@ -3453,6 +3733,8 @@ function sourceOf(args, text) {
3453
3733
  if (!SHORT_OPTIONS.test(arg))
3454
3734
  continue;
3455
3735
  for (const [index, flag] of [...arg.slice(1)].entries()) {
3736
+ if (COMMIT_ATTACHED_SHORTS.has(flag))
3737
+ break;
3456
3738
  if (flag === "s")
3457
3739
  source.hasTrailerFlag = true;
3458
3740
  if (!COMMIT_VALUE_SHORTS.has(flag))
@@ -3546,6 +3828,7 @@ var RECURSIVE_LETTER = /r/i;
3546
3828
  var HOME_PREFIX = /^(?:~|\$HOME|\$\{HOME(?::?[-?=+][^}]*)?\}?)(?=\/|$)/;
3547
3829
  var CURRENT_DIRECTORY = /^(?:\$PWD|\$\{PWD\}?|\$\(pwd\)?|`pwd`?)(?=\/|$)/;
3548
3830
  var ABSOLUTE_HOME = /^(?:home\/[^/]+|root)\/([^/]+)$/;
3831
+ var SYSTEM_FOLDERS = new Set(["bin", "boot", "dev", "etc", "home", "lib", "lib32", "lib64", "media", "mnt", "opt", "proc", "run", "sbin", "srv", "sys", "usr", "var"]);
3549
3832
  var EXEC_FLAGS = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
3550
3833
  var REMOVER = /(?:^|\/)rm$/;
3551
3834
  var TRAILING_SLASH = /\/$/;
@@ -3554,7 +3837,7 @@ var INTERPRETERS2 = new Set(["python", "node", "bun", "perl", "ruby"]);
3554
3837
  var VERSION_SUFFIX = /[\d.]+$/;
3555
3838
  var PASS_THROUGH = new Set(["tee", "cat", "pv", "tr", "sed"]);
3556
3839
  var COMMIT_FIRST = "Commit what you want to keep with `gc` first.";
3557
- var SAFE_BASE = "`base -- <cmd>` runs a command at HEAD with the working tree untouched, and `git worktree add` gives a clean tree.";
3840
+ var SAFE_BASE = "`base -- <cmd>` runs a command at HEAD in a temporary worktree, its changes left out, and `git worktree add` gives a clean tree.";
3558
3841
  var RESET_HARD = `Never \`git reset --hard\`: it throws away uncommitted work, and peer sessions edit this tree live. ${COMMIT_FIRST} \`git reset --soft\` or \`--mixed\` moves HEAD and keeps the changes; ${SAFE_BASE}`;
3559
3842
  var DISCARD_TREE = `Never discard the whole working tree (\`git checkout -- .\`, \`git checkout -f\`, \`git restore .\`, \`git rm -r .\`, \`git switch -f\`): it throws away uncommitted work, and peer sessions edit this tree live. ${COMMIT_FIRST} Restore named paths only, and \`git restore --staged\` just unstages. ${SAFE_BASE}`;
3560
3843
  var CLEAN = `Never \`git clean -f\`: it deletes untracked files that peer sessions or the user have not committed yet. \`git clean -n\` lists what it would remove; delete named files yourself.`;
@@ -3563,14 +3846,17 @@ var REMOTE_DELETE = "Never delete a remote branch or tag with `git push --delete
3563
3846
  var BRANCH_DELETE = "Never `git branch -D`: it drops commits no other branch holds. `git branch -d` deletes a merged branch only; ask the user before dropping an unmerged one.";
3564
3847
  var REBASE = `Never start a \`git rebase\`: it rewrites history and stops halfway on conflicts in a tree others edit. ${COMMIT_FIRST} \`git cherry-pick\` or \`git merge\` keep history, and \`git worktree add\` gives a clean tree to do it in. \`--continue\` and \`--abort\` stay allowed.`;
3565
3848
  var REWRITE_HISTORY = "Never `git filter-branch` or `git filter-repo`: they rewrite every commit of the repository. Ask the user to run it themselves.";
3566
- var BROAD_RM = "Never `rm -r` on `/`, `~`, `$HOME`, `.`, `..`, `*` or a top-level directory: it deletes far more than the task. Name the exact directory, such as `dist` or `node_modules`.";
3849
+ var BROAD_RM = "Never `rm -r` on `/`, `~`, `$HOME` or the home by its path, `.`, `..`, `*`, a top-level directory or a system folder's child such as `/usr/lib`: it deletes far more than the task. Name the exact directory, such as `dist` or `node_modules`.";
3567
3850
  var PROTECTED_RM = "Never `rm -r` on a `.git` directory, on `~/Workspace` itself or on a dot-directory of the home (`~/.ssh`, `$HOME/.claude`, `~/.config`): it deletes a repository's whole history, every project, or the credentials and settings of the machine. Remove the named files inside, or ask the user to run it.";
3568
- var FIND_DELETE_HOME = 'Never `find ~ -delete` or `find / -exec rm` (also `$HOME`): it deletes matches across the whole home or disk. Start `find` in the project folder or `.` and name the pattern, such as `find . -name "*.tmp" -delete`.';
3851
+ var FIND_DELETE_HOME = 'Never `find ~ -delete` or `find / -exec rm` (also `$HOME` or the home by its path): it deletes matches across the whole home or disk. Start `find` in the project folder or `.` and name the pattern, such as `find . -name "*.tmp" -delete`.';
3569
3852
  var REFLOG_EXPIRE = "Never `git reflog expire`, `git gc --prune=now` or `git update-ref -d`: they drop the reflog, unreachable commits or a ref, the only way back from a bad reset or rebase. Let git prune on its own schedule, and ask the user to run one when it is really wanted.";
3570
3853
  var DOCKER_PRUNE_ALL = "Never `docker system prune -a` (`--all`): it removes every image not used by a running container, volumes of other projects' stacks included with --volumes. `docker system prune` without -a drops only dangling data; remove named images with `docker rmi`.";
3571
3854
  var PINNED_RUN = "`dl <url>` downloads it and prints its path and sha256; read that file, then `dl <url> --exec --sha256 <sha>` runs exactly what was read.";
3572
3855
  var PIPE_TO_SHELL = `Never run what \`curl\`/\`wget\` fetches straight in a shell (\`| sh\`, \`bash <(curl ...)\`, \`eval "$(curl ...)"\`): it runs code nobody read. ${PINNED_RUN} Or hand the command to the user.`;
3573
3856
  var UNPINNED_EXEC = `Never \`dl --exec --yes\` a script no \`--sha256\` or \`--sums\` pins: it runs code nobody read. ${PINNED_RUN}`;
3857
+ function isLongPrefix(arg, option) {
3858
+ return arg.length > 2 && option.startsWith(arg);
3859
+ }
3574
3860
  function hasOption(args, long, shorts) {
3575
3861
  for (const arg of args) {
3576
3862
  if (arg === "--")
@@ -3580,7 +3866,7 @@ function hasOption(args, long, shorts) {
3580
3866
  }
3581
3867
  return false;
3582
3868
  }
3583
- function isBroadPath(path) {
3869
+ function isBroadPath(path, homePath) {
3584
3870
  const arg = path.replace(CURRENT_DIRECTORY, ".");
3585
3871
  const home = HOME_PREFIX.exec(arg);
3586
3872
  const isAbsolute = home === null && arg.startsWith("/");
@@ -3597,11 +3883,14 @@ function isBroadPath(path) {
3597
3883
  parts.pop();
3598
3884
  if (home !== null)
3599
3885
  return parts.length === 0;
3600
- return isAbsolute ? parts.length <= 1 : parts.every((part) => part === "..");
3886
+ if (!isAbsolute)
3887
+ return parts.every((part) => part === "..");
3888
+ const isHome = homePath !== undefined && `/${parts.join("/")}` === homePath.replace(TRAILING_SLASH, "");
3889
+ return parts.length <= 1 || isHome || parts.length === 2 && SYSTEM_FOLDERS.has(parts[0] ?? "");
3601
3890
  }
3602
3891
  function recursiveTargets(args) {
3603
3892
  const options = args.slice(0, args.includes("--") ? args.indexOf("--") : args.length);
3604
- const isRecursive = options.some((arg) => arg === "--recursive" || SHORT_CLUSTER.test(arg) && RECURSIVE_LETTER.test(arg));
3893
+ const isRecursive = options.some((arg) => isLongPrefix(arg, "--recursive") || SHORT_CLUSTER.test(arg) && RECURSIVE_LETTER.test(arg));
3605
3894
  return isRecursive ? args.filter((arg, i) => !arg.startsWith("-") || args.includes("--") && i > args.indexOf("--")) : [];
3606
3895
  }
3607
3896
  function isProtectedPath(path) {
@@ -3613,18 +3902,18 @@ function isProtectedPath(path) {
3613
3902
  const child = home === null ? absolute?.[1] : homeChild;
3614
3903
  return last === ".git" || child !== undefined && (child === "Workspace" || child.startsWith(".") && child !== "..");
3615
3904
  }
3616
- function deletesFromHome(args) {
3905
+ function deletesFromHome(args, home) {
3617
3906
  const firstOption = args.findIndex((arg) => arg.startsWith("-") || arg === "(" || arg === "!");
3618
3907
  const starts = firstOption === -1 ? args : args.slice(0, firstOption);
3619
3908
  const deletes = args.includes("-delete") || args.some((arg, i) => EXEC_FLAGS.has(arg) && REMOVER.test(args[i + 1] ?? ""));
3620
- return deletes && starts.some((start) => start === "/" || start.replace(TRAILING_SLASH, "") === HOME_PREFIX.exec(start)?.[0]);
3909
+ return deletes && starts.some((start) => start === "/" || [HOME_PREFIX.exec(start)?.[0], home?.replace(TRAILING_SLASH, "")].includes(start.replace(TRAILING_SLASH, "")));
3621
3910
  }
3622
3911
  function dockerPrunesAll(args) {
3623
3912
  const system = args.indexOf("system");
3624
3913
  return system !== -1 && args[system + 1] === "prune" && hasOption(args.slice(system + 2), ["--all"], "a");
3625
3914
  }
3626
- function removesBroadly(args) {
3627
- return args.includes("--no-preserve-root") || recursiveTargets(args).some(isBroadPath);
3915
+ function removesBroadly(args, home) {
3916
+ return args.some((arg) => isLongPrefix(arg, "--no-preserve-root")) || recursiveTargets(args).some((path) => isBroadPath(path, home));
3628
3917
  }
3629
3918
  function checksOutTree(rest, operands) {
3630
3919
  if (rest.includes("--"))
@@ -3692,18 +3981,18 @@ function runsUnpinned(args) {
3692
3981
  const given = (name) => own.some((arg) => arg === name || arg.startsWith(`${name}=`));
3693
3982
  return given("--exec") && given("--yes") && !given("--sha256") && !given("--sums");
3694
3983
  }
3695
- function destructiveViolation(command) {
3984
+ function destructiveViolation(command, home) {
3696
3985
  if (runsDownload(command))
3697
3986
  return PIPE_TO_SHELL;
3698
3987
  for (const piece of splitCommand(command)) {
3699
3988
  const { program, args } = parseCommand(piece.command);
3700
3989
  if (program === "dl" && runsUnpinned(args))
3701
3990
  return UNPINNED_EXEC;
3702
- if (program === "rm" && removesBroadly(args))
3991
+ if (program === "rm" && removesBroadly(args, home))
3703
3992
  return BROAD_RM;
3704
3993
  if (program === "rm" && recursiveTargets(args).some(isProtectedPath))
3705
3994
  return PROTECTED_RM;
3706
- if (program === "find" && deletesFromHome(args))
3995
+ if (program === "find" && deletesFromHome(args, home))
3707
3996
  return FIND_DELETE_HOME;
3708
3997
  if (program === "docker" && dockerPrunesAll(args))
3709
3998
  return DOCKER_PRUNE_ALL;
@@ -3731,10 +4020,10 @@ var ARGV = new RegExp(String.raw`[[(]\s*((?:(?:${QUOTED})\s*,\s*)+(?:${QUOTED}))
3731
4020
  var LITERAL = new RegExp(QUOTED, "gs");
3732
4021
  var RUNS_SHELL = /(?:\b(?:system|exec\w*|spawn\w*|popen|run|call|check_\w+|Popen|getoutput|qx)|\$)\s*(?:\(\s*)?$/;
3733
4022
  var SHELL_BACKTICKS = new Set(["perl", "ruby"]);
3734
- var ESCAPED = new Map([["n", `
4023
+ var ESCAPED2 = new Map([["n", `
3735
4024
  `], ["t", " "]]);
3736
4025
  function decode(text) {
3737
- return text.replaceAll(ESCAPE2, (_, char) => ESCAPED.get(char) ?? char);
4026
+ return text.replaceAll(ESCAPE2, (_, char) => ESCAPED2.get(char) ?? char);
3738
4027
  }
3739
4028
  function literalValue(literal) {
3740
4029
  return decode(literal.slice(1, -1));
@@ -3799,40 +4088,54 @@ var SHELL_PROGRAMS = new Set(["ssh", "scp", "sftp", "mosh", "mosh-client", "auto
3799
4088
  var SOCKET_PROGRAMS = new Set(["nc", "ncat", "netcat", "telnet", "socat"]);
3800
4089
  var URL_PROGRAMS = new Set(["git", "docker", "docker-compose"]);
3801
4090
  var DECLARERS2 = new Set(["export", "declare", "typeset"]);
3802
- var RSYNC_REMOTE = /^(?:[\w.-]+@)?[\w.-]{2,}:/;
4091
+ var RSYNC_REMOTE = /^(?:[\w.-]+@)?[\w.-]+:/;
3803
4092
  var SCP_ADDRESS = /^[^/:\s-][^/:\s]*:(?!\/\/)/;
3804
4093
  var SCP_HOST_ADDRESS = /^(?:[\w.-]+@[\w.-]+|[\w-]+(?:\.[\w-]+)+):(?!\/\/)/;
3805
4094
  var GIT_TRANSPORTS = new Set(["clone", "fetch", "pull", "push", "ls-remote"]);
3806
4095
  var TRANSPORT_VALUE_OPTIONS = new Set(["--depth", "-b", "--branch", "-o", "--origin", "--push-option", "-c", "--config", "--reference", "--separate-git-dir", "--template", "-j", "--jobs", "--filter", "--shallow-since", "--shallow-exclude", "-u", "--upload-pack", "--receive-pack", "--exec", "--server-option", "--repo", "--deepen"]);
3807
- var SSH_URL = /^ssh:\/\//;
3808
4096
  var SSH_URL_WORD = /^(?:[\w-]+=)?ssh:\/\//;
3809
4097
  var LOOPBACK = /(?:^|[:=@[])(?:localhost|127(?:\.\d+){3}|::1)(?:[:\]/]|$)/;
3810
4098
  var LISTENS = /^-[A-KM-Z]*L[A-Z]*$/i;
3811
4099
  var DOCKER_VALUE_OPTIONS2 = new Set(["-c", "--context", "-H", "--host", "-l", "--log-level", "--config", "--tlscacert", "--tlscert", "--tlskey"]);
4100
+ var DOCKER_SHORT_VALUE = /^-([cHl])(.+)$/;
4101
+ var LOCAL_DAEMON = /^(?:unix|npipe|fd):\/\/|^tcp:\/\/(?:localhost|127(?:\.\d+){3}|\[::1\])(?::\d+)?\/?$/;
3812
4102
  var CONTEXT_CHANGES = new Set(["use", "create", "update", "import"]);
3813
4103
  var KUBECTL_SERVER = /^(?:--server(?:=|$)|-s$)/;
3814
4104
  var REMOTE_VARIABLE = /^GIT_SSH(?:_COMMAND)?=/;
3815
4105
  var REMOTE = "Remote servers are off limits (no SSH, no deploys, no remote commands). Hand the user the exact command to run themselves.";
4106
+ function isRemoteDaemon(address) {
4107
+ return address !== "" && !LOCAL_DAEMON.test(address);
4108
+ }
3816
4109
  function dockerContext(args) {
3817
4110
  let context = null;
4111
+ const hosts = [];
3818
4112
  for (let i = 0;i < args.length; i++) {
3819
4113
  const arg = args[i] ?? "";
3820
- if (arg.startsWith("--context="))
3821
- context = arg.slice("--context=".length);
3822
- else if (arg === "-c" || arg === "--context")
3823
- context = args[++i] ?? null;
4114
+ const equals = arg.indexOf("=");
4115
+ const attached = DOCKER_SHORT_VALUE.exec(arg);
4116
+ let [option, value] = [arg, undefined];
4117
+ if (arg.startsWith("--") && equals !== -1)
4118
+ [option, value] = [arg.slice(0, equals), arg.slice(equals + 1)];
4119
+ else if (attached !== null)
4120
+ [option, value] = [`-${attached[1]}`, attached[2]];
3824
4121
  else if (DOCKER_VALUE_OPTIONS2.has(arg))
3825
- i++;
4122
+ value = args[++i];
4123
+ if (option === "-c" || option === "--context")
4124
+ context = value ?? null;
4125
+ else if ((option === "-H" || option === "--host") && value !== undefined)
4126
+ hosts.push(value);
3826
4127
  else if (!arg.startsWith("-"))
3827
- return { context, name: arg, rest: args.slice(i + 1) };
4128
+ return { context, hosts, name: arg, rest: args.slice(i + 1) };
3828
4129
  }
3829
- return { context, name: "", rest: [] };
4130
+ return { context, hosts, name: "", rest: [] };
3830
4131
  }
3831
4132
  function isDockerRemote(args, assignments) {
3832
- const { context, name, rest } = dockerContext(args);
4133
+ const { context, hosts, name, rest } = dockerContext(args);
3833
4134
  const fromEnv = assignments.find((assignment) => assignment.startsWith("DOCKER_CONTEXT="))?.slice("DOCKER_CONTEXT=".length);
3834
4135
  if ([context, fromEnv].some((each) => each !== null && each !== undefined && each !== "default"))
3835
4136
  return true;
4137
+ if (hosts.some(isRemoteDaemon))
4138
+ return true;
3836
4139
  return name === "context" && CONTEXT_CHANGES.has(rest[0] ?? "");
3837
4140
  }
3838
4141
  function isSocketRemote(args) {
@@ -3871,7 +4174,7 @@ function isRemote(text) {
3871
4174
  return args.some((arg) => KUBECTL_SERVER.test(arg));
3872
4175
  if ([...assignments, ...declared].some((assignment) => REMOTE_VARIABLE.test(assignment)))
3873
4176
  return true;
3874
- if ([...assignments, ...declared].some((assignment) => assignment.startsWith("DOCKER_HOST=") && SSH_URL.test(assignment.slice("DOCKER_HOST=".length))))
4177
+ if ([...assignments, ...declared].some((assignment) => assignment.startsWith("DOCKER_HOST=") && isRemoteDaemon(assignment.slice("DOCKER_HOST=".length))))
3875
4178
  return true;
3876
4179
  if (program === "docker" && isDockerRemote(args, assignments))
3877
4180
  return true;
@@ -4270,8 +4573,8 @@ function mismatches(command, { cwd, home, exists }) {
4270
4573
  return mismatch === null ? [] : [mismatch];
4271
4574
  });
4272
4575
  }
4273
- function nestedMismatches(run, context, own) {
4274
- const ownTexts = new Set(own.map((mismatch) => mismatch.piece.command.trim()));
4576
+ function nestedMismatches(run, context) {
4577
+ const ownTexts = new Set(installRequests(run[0] ?? "", context.cwd, context.home).map((request) => bareCommand(request.piece.command)));
4275
4578
  return run.slice(1).flatMap((each) => mismatches(each, context)).filter((mismatch) => !ownTexts.has(mismatch.piece.command.trim())).map((mismatch) => ({ ...mismatch, rewrite: null }));
4276
4579
  }
4277
4580
  async function checkCommand(command, context) {
@@ -4294,9 +4597,9 @@ async function checkCommand(command, context) {
4294
4597
  }
4295
4598
  };
4296
4599
  const readSql = async (path) => Promise.resolve(context.read(absolute(path, context.cwd)));
4297
- add("remote", await guarded("remote", () => first(run.map(remoteViolation))));
4600
+ add("remote", await guarded("remote", () => first([...run, ...scripted].map(remoteViolation))));
4298
4601
  add("git", await guarded("git", () => first([...run, ...scripted].map((each) => gitViolation(each, context.isPushAsked)))));
4299
- add("destructive", await guarded("destructive", () => first([...run, ...scripted].map(destructiveViolation))));
4602
+ add("destructive", await guarded("destructive", () => first([...run, ...scripted].map((each) => destructiveViolation(each, context.home)))));
4300
4603
  const commit = await guarded("commit", () => first(run.map((each) => commitViolation(each, context))));
4301
4604
  add("commit", commit === null ? null : `${commit} ${USE_GC}`);
4302
4605
  add("sql", await guarded("sql", async () => first(await Promise.all(run.map(async (each) => sqlViolation(each, readSql))))));
@@ -4308,7 +4611,7 @@ async function checkCommand(command, context) {
4308
4611
  }));
4309
4612
  add("edit", context.canSub ? await guarded("edit", () => first(run.map(replaceViolation))) : null);
4310
4613
  const found = mismatches(command, context);
4311
- const refused = [...found, ...nestedMismatches(run, context, found)].find((mismatch) => mismatch.rewrite === null || !context.canRewrite);
4614
+ const refused = [...found, ...nestedMismatches(run, context)].find((mismatch) => mismatch.rewrite === null || !context.canRewrite);
4312
4615
  const rewrite = refused?.rewrite ?? null;
4313
4616
  const route = rewrite === null ? "Run it with the pinned manager instead." : `Run \`${rewrite.trim()}\` instead.`;
4314
4617
  add("package-manager", refused === undefined ? null : `${refused.reason} ${route}`);