@cratis/pi 8.10.2 → 8.10.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.
@@ -527,11 +527,16 @@ function directory_operand(w, path) {
527
527
  if (path !~ /^\//) path = ENVIRON["GS_CWD_FALLBACK"] "/" path
528
528
  return system("test -d " shell_quote(path)) == 0
529
529
  }
530
+ function without_trailing_slashes(w) {
531
+ if (w !~ /[^\/]/) return w
532
+ sub(/(\/|\/\.)+$/, "", w)
533
+ return w == "" ? "/" : w
534
+ }
530
535
  function bare_token_name(b) { return b ~ /^\.?tokens?$/ }
531
536
  # Only probe a literal directory operand of a simple command, not shell-generated paths.
532
537
  function token_directory(w, path, leaf, cmd, status) {
533
538
  if (filter_compound || nwrap || qi != 1 || w !~ /^[A-Za-z0-9_.\/-]+$/) return 0
534
- path = w; sub(/\/+$/, "", path); leaf = base(path)
539
+ path = without_trailing_slashes(w); leaf = base(path)
535
540
  if (!token_name(leaf) || token_ok(tolower(path), leaf)) return 0
536
541
  if (w !~ /^\// && (ENVIRON["GS_CWD"] !~ /^\// || ncd != 1 || cwd_at(1) != ENVIRON["GS_CWD"])) return 0
537
542
  if (!(path in TOKEN_DIRECTORY_PROBES)) {
@@ -543,8 +548,8 @@ function token_directory(w, path, leaf, cmd, status) {
543
548
  }
544
549
  status = TOKEN_DIRECTORY_PROBES[path]
545
550
  if (status == 1) return 0
546
- # Bare token directories can themselves be credential stores.
547
- return status != 0 || bare_token_name(leaf) ? 2 : 1
551
+ # Bare token and GitHub token directories can themselves be credential stores.
552
+ return status != 0 || bare_token_name(leaf) || leaf == "github_token" ? 2 : 1
548
553
  }
549
554
  function metadata_shape(A, M, n, k, j, c, mk) {
550
555
  if (A[1] != "ls" && A[1] != "stat") return 0
@@ -578,7 +583,7 @@ function git_metadata(words, count, subcommand, k, w, ended, summary) {
578
583
  # Path-only Git operations do not turn credential vocabulary into a secret filename.
579
584
  # Exempt only plain relative paths or one-colon object specs with a simple ref.
580
585
  # Never interpret complex Git grammar; keep the original operand for conservative checks.
581
- function git_path_kind(w, pathspec, repo_only, local_add, parts, count, k, kind, path, allowed, option, directory, token_dir, source_leaf, plain_path) {
586
+ function git_path_kind(w, pathspec, repo_only, local_add, root, parts, count, k, kind, path, allowed, option, directory, token_dir, source_leaf, plain_path, addressed, raw) {
582
587
  option = w ~ /^-/
583
588
  if (option) {
584
589
  kind = sensitive_path(w)
@@ -596,10 +601,14 @@ function git_path_kind(w, pathspec, repo_only, local_add, parts, count, k, ki
596
601
  allowed = allowed && path ~ /^[A-Za-z0-9_.\/-]+$/ && path !~ /^\// && path !~ /(^|\/)\.\.(\/|$)/
597
602
  if (repo_only && !allowed) return "an operand outside the Git path allowlist"
598
603
  if (allowed) w = path
599
- directory = allowed && tolower(base(w)) == "credentials" && tolower(w) !~ /(^|\/)\.aws\/credentials$/ && directory_operand(w)
604
+ raw = w; w = without_trailing_slashes(w); addressed = join_path(root, w)
605
+ directory = allowed && base(w) == "credentials" && tolower(addressed) !~ /(^|\/)\.aws\/credentials$/ && directory_operand(join_path(root, raw))
600
606
  plain_path = !option && w ~ /^[A-Za-z0-9_.\/-]+$/
601
- if (local_add && plain_path) token_dir = token_directory(w)
602
- kind = sensitive_path(w, token_dir)
607
+ if (local_add && plain_path) token_dir = token_directory(addressed)
608
+ kind = sensitive_path(raw, token_dir)
609
+ if (kind == "" && w != raw) kind = sensitive_path(w, token_dir)
610
+ if (kind == "" && root != "") kind = sensitive_path(join_path(root, raw), token_dir)
611
+ if (kind == "" && root != "" && w != raw) kind = sensitive_path(addressed, token_dir)
603
612
  if (kind != "" && !(directory && kind == "a credentials file")) return kind
604
613
  source_leaf = plain_path && (code_file(base(w)) || build_file(base(w)))
605
614
  # Inspect every component without guessing where unsupported revision/pathspec syntax ends.
@@ -615,18 +624,48 @@ function git_path_kind(w, pathspec, repo_only, local_add, parts, count, k, ki
615
624
  if (!allowed && stem_scan(w, "raw") != "") return "a protected Git operand"
616
625
  return ""
617
626
  }
618
- function git_paths(A, M, n, k, ended, pathspec) {
619
- if (A[1] != "git" || A[2] !~ /^(add|checkout|restore|rm|mv|diff|log|show)$/) return 0
620
- for (k = 1; k <= n; k++) {
627
+ function join_path(dir, w) { return dir == "" || w ~ /^\// ? w : dir "/" w }
628
+ # Keep .. and symlink components in filesystem order. Git applies all -C switches first,
629
+ # then interprets the explicit work tree and Git directory relative to the resulting cwd.
630
+ function git_options(A, M, s, n, k, w, m, option, value, eq, cwd, tree) {
631
+ GIT_CWD = GIT_ROOT = GIT_DIR = ""
632
+ for (k = s + 1; k <= n && A[k] ~ /^-/; k++) {
633
+ w = A[k]; m = M[k]; option = w; value = ""
634
+ if (expands(w, m)) return 0
635
+ if (w ~ /^(-C|-c|--git-dir|--work-tree|--namespace|--attr-source|--super-prefix)$/) {
636
+ if (++k > n || expands(A[k], M[k])) return 0
637
+ value = A[k]
638
+ } else if (w ~ /^--(git-dir|work-tree|namespace|attr-source|super-prefix)=/) {
639
+ eq = index(w, "="); option = substr(w, 1, eq - 1); value = substr(w, eq + 1)
640
+ } else if (w ~ /^-[Cc]./) { option = substr(w, 1, 2); value = substr(w, 3) }
641
+ else if (w == "--") { k++; break }
642
+ else if (w ~ /^(-p|-P|--(no-pager|paginate|bare|no-replace-objects|no-lazy-fetch|no-optional-locks|no-advice|(literal|no-literal|glob|noglob|icase)-pathspecs))$/) continue
643
+ else if (w ~ /^(-h|-v|--(help|version|exec-path|html-path|man-path|info-path))$/ || w ~ /^--list-cmds=/) return n + 1
644
+ else return 0
645
+ if (option ~ /^(-C|--(work-tree|git-dir))$/ && value ~ /^[~+-]/) return 0
646
+ if (option == "-C" && value != "") cwd = join_path(cwd, value)
647
+ if (option == "--work-tree") tree = value
648
+ if (option == "--git-dir") GIT_DIR = value
649
+ if (option == "-c" && tolower(value) ~ /^(core\.worktree|include(if)?\.)/) return 0
650
+ }
651
+ if (k <= n && expands(A[k], M[k])) return 0
652
+ GIT_CWD = cwd
653
+ GIT_ROOT = tree == "" ? cwd : join_path(cwd, tree)
654
+ return k
655
+ }
656
+ function git_paths(A, M, n, k, s, ended, pathspec) {
657
+ if (A[1] != "git") return 0
658
+ s = git_options(A, M, 1, n)
659
+ if (!s || A[s] !~ /^(add|checkout|restore|rm|mv|diff|log|show)$/) return 0
660
+ for (k = s + 1; k <= n; k++) {
621
661
  if (expands(A[k], M[k]) || !literal_word(A[k], M[k]) || A[k] ~ /[*?\[]/) return 0
622
- if (k <= 2) continue
623
662
  if (!ended && A[k] == "--") { ended = 1; continue }
624
- if (!ended && A[2] == "diff" && A[k] ~ /^--no-index($|=)/) return 0
625
- pathspec = ended || A[2] ~ /^(add|checkout|restore|rm|mv)$/
663
+ if (!ended && A[s] == "diff" && A[k] ~ /^--no-index($|=)/) return 0
664
+ pathspec = ended || A[s] ~ /^(add|checkout|restore|rm|mv)$/
626
665
  # Options are checked for sensitive values but are never positional path exemptions.
627
- if (git_path_kind(A[k], pathspec, A[k] !~ /^-/, A[2] == "add") != "") return 0
666
+ if (git_path_kind(A[k], pathspec, A[k] !~ /^-/, A[s] == "add", GIT_ROOT) != "") return 0
628
667
  }
629
- return 1
668
+ return s
630
669
  }
631
670
  # Allowlist: a leading NAME=VALUE assignment is admitted before an allowlisted shape only when the name is not
632
671
  # one that changes how a program loads, resolves or runs, and the value is plain literal text naming no protected
@@ -981,7 +1020,7 @@ function end_cmd( k, m, w, j, hit, exempt, path_git, paths_only, test_filter)
981
1020
  msg_shape = data_shape(W, WM, nw)
982
1021
  for (k = 1; k <= nw; k++) {
983
1022
  if (msg_shape && (k in MDATA)) continue
984
- if (path_git && W[k] !~ /^-/) continue
1023
+ if (path_git && k > path_git && W[k] !~ /^-/) continue
985
1024
  if (is_assign(W[k])) set_var(W[k], WM[k])
986
1025
  if (paths_only && ((k in DATA) || sensitive_path(W[k]) == "")) continue
987
1026
  exempt = (k in RP) && !WU[k]
@@ -1041,6 +1080,15 @@ function cmdsub(s, i, n, start, depth, c, j) {
1041
1080
  enqueue(substr(s, start, i - start))
1042
1081
  return i + 1
1043
1082
  }
1083
+ # Only skip a simple process-substitution body. Shell constructs such as comments,
1084
+ # here-docs and case arms can make the apparent first closing parenthesis misleading.
1085
+ function process_sub_end(s, start, body, end) {
1086
+ body = substr(s, start)
1087
+ if (!match(body, /^([A-Za-z0-9_.\/@%+,=: \t-]|\047[^\047\n]*\047|"[^"$`\\\n]*"|\\[^\n])*\)/)) return 0
1088
+ end = RLENGTH
1089
+ if (substr(body, 1, end - 1) ~ /(^|[ \t])case([ \t]|$)/) return 0
1090
+ return start + end - 1
1091
+ }
1044
1092
  # An unquoted here-document delimiter lets the shell run command and backtick substitutions in the body, so
1045
1093
  # their text is analyzed like any other command. A quoted delimiter makes the body plain data.
1046
1094
  function heredoc_substitutions(body, i, n, c, j) {
@@ -1192,6 +1240,17 @@ function tokenize(s, i, n, c, c2, j, dash, delim) {
1192
1240
  # `>&`, `>|` and `&>` are parts of a redirection operator, not command separators.
1193
1241
  if ((c == "&" || c == "|") && inword && !wquoted && word ~ />$/) { addw(c, "u"); wplain++; i++; continue }
1194
1242
  if (c == "&" && substr(s, i + 1, 1) == ">") { flush_word(); addw(c, "u"); inword = 1; wplain = 1; i++; continue }
1243
+ if ((c == "<" || c == ">") && substr(s, i + 1, 1) == "(") {
1244
+ complex = filter_compound = 1
1245
+ j = process_sub_end(s, i + 2)
1246
+ if (!j || inword || !nw || queued >= 64 || substr(s, j + 1, 1) ~ /[^ \t\r\n;&|()<>]/) {
1247
+ report("a process substitution whose operands cannot be checked", "run the nested command and the read separately")
1248
+ return
1249
+ }
1250
+ enqueue(substr(s, i + 2, j - i - 2))
1251
+ # The substitution supplies one descriptor operand, not a shell command separator.
1252
+ addw("/dev/fd/0", "l"); wquoted = inword = 1; i = j + 1; continue
1253
+ }
1195
1254
  if (c == "(" && (j = glob_end(s, i)) > 0 && (inword || nw > 0 || substr(s, j + 1, 1) ~ /^[A-Za-z0-9_.]$/)) {
1196
1255
  inword = 1; addw(substr(s, i, j - i + 1), "u"); i = j + 1; continue
1197
1256
  }
@@ -1495,11 +1554,13 @@ function variable_values(name, k, j, count, result, values, masks, value_part
1495
1554
  if (UNK[name] || ACTIVE[name] || value_depth >= 4) return "\001"
1496
1555
  ACTIVE[name] = 1; value_depth++
1497
1556
  result = "\003"; count = BVN[name]
1557
+ # One unconditional leading literal assignment, followed by a single command, has no ambient alternative.
1558
+ if (count == 1 && qi == 1 && CMD ~ ("^" name "=[A-Za-z0-9_./-]+;[ \t]*[A-Za-z][^;&|{}()<>`\n]*$")) result = ""
1498
1559
  delete values; delete masks
1499
1560
  for (k = 1; k <= count; k++) { values[k] = BV[name, k]; masks[k] = BVM[name, k] }
1500
1561
  for (k = 1; k <= count; k++) {
1501
1562
  resolve(values[k], masks[k])
1502
- for (j = 1; j <= nalt; j++) result = result "\034" ALT[j]
1563
+ for (j = 1; j <= nalt; j++) result = result (result == "" ? "" : "\034") ALT[j]
1503
1564
  delete value_parts
1504
1565
  if (split(result, value_parts, "\034") > 64) { result = "\001"; break }
1505
1566
  }
@@ -1695,9 +1756,8 @@ function path_probe(a, probe, path_parts, probe_parts, n, m, k, tail) {
1695
1756
  for (k = n-m+2; k <= n; k++) tail = tail "/" path_parts[k]
1696
1757
  return pattern_match(tail, probe)
1697
1758
  }
1698
- # Only a literal prefix plus one trailing star is resolved against the filesystem.
1699
- # The script is fixed shell code: cwd/prefix are single-quoted positional arguments, and
1700
- # only the literal basename prefix plus * is expanded. No command text, operand or bracket body is evaluated as code.
1759
+ # Resolve only one star between literal path fragments against the filesystem.
1760
+ # The fixed probe receives those fragments as quoted positional arguments: no input is evaluated as code.
1701
1761
  # Recognize only && chains with one reader and literal read-only Git metadata.
1702
1762
  # Quoted regex/format text is opaque data; expansions and other shell syntax fail
1703
1763
  # closed. The semantic command index binds a probe to that reader, not a later one.
@@ -1764,9 +1824,10 @@ function glob_directory( text, head, dir, prior) {
1764
1824
  if (dir ~ /(^|\/)\.\.(\/|$)/ || qi != 1 || !probe_read_chain(text, prior)) return ""
1765
1825
  return dir
1766
1826
  }
1767
- function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count, ok, kind, found, name, original, basename, k) {
1768
- prefix = substr(a, 1, length(a) - 1)
1769
- if (substr(a, length(a), 1) != "\004" || prefix == "" || prefix ~ /[^A-Za-z0-9._\/@+=,:%-]/) return "a key or certificate file"
1827
+ function glob_secret_match(a, with_suffix, star, suffix, prefix, parent, dir, script, cmd, line, count, ok, kind, found, name, original, basename, k) {
1828
+ if (!with_suffix && substr(a, length(a), 1) != "\004") return "a key or certificate file"
1829
+ star = index(a, "\004"); prefix = substr(a, 1, star - 1); suffix = substr(a, star + 1)
1830
+ if (!star || (!with_suffix && prefix == "") || prefix ~ /[^A-Za-z0-9._\/@+=,:%-]/ || suffix ~ /[^A-Za-z0-9._@+=,:%-]/) return "a key or certificate file"
1770
1831
  parent = prefix; sub(/[^\/]*$/, "", parent)
1771
1832
  dir = glob_directory()
1772
1833
  if (glob_recursive) for (k = 2; k <= PROBE_COUNT; k++) {
@@ -1790,10 +1851,10 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1790
1851
  "if [ -d \"$f\" ]; then [ -r \"$f\" ] && [ -x \"$f\" ] || return 3; " \
1791
1852
  "for child in \"$f\"/*; do scan_file \"$child\" $((depth+1)) || return 3; done; " \
1792
1853
  "else [ -f \"$f\" ] || return 3; printf \"F:%s\\n\" \"$PWD/$f\"; fi; }; " \
1793
- "n=0; seen=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ ! -L \"$f\" ] || exit 3; " \
1854
+ "n=0; seen=0; for f in \"$stem\"*\"$4\"; do n=$((n+1)); [ \"$n\" -le 200 ] && [ ! -L \"$f\" ] || exit 3; " \
1794
1855
  "if [ -d \"$f\" ] && [ \"$3\" != 1 ]; then continue; fi; " \
1795
1856
  "scan_file \"$f\" 0 || exit 3; done; echo OK"
1796
- cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " " shell_quote(glob_recursive ? "1" : "0") " 2>/dev/null"
1857
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " " shell_quote(glob_recursive ? "1" : "0") " " shell_quote(suffix) " 2>/dev/null"
1797
1858
  while ((cmd | getline line) > 0) {
1798
1859
  if (line == "OK") { ok = 1; continue }
1799
1860
  if (ok || substr(line, 1, 2) != "F:" || ++count > 20000) { ok = 0; break }
@@ -1811,24 +1872,41 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1811
1872
  if (!count && base(prefix) != "") for (k = 1; k <= nprobe; k++) {
1812
1873
  if (index(PROBE[k], tolower(base(prefix))) == 1 && sensitive_path(PROBE[k]) != "") return sensitive_path(PROBE[k])
1813
1874
  }
1814
- if (!count && !filenames_only && (base(prefix) ~ /^(secrets?|cert(ificate)?s?|keys?|private|credentials?)([._-]|$)/ || tolower(prefix) ~ /\.(pem|key|p12|pfx|jks|keystore|kdbx|kubeconfig|env)([._-]|$)/ || sensitive_path(dir "/" prefix) != "")) return "a key or certificate file"
1875
+ # With a fixed suffix, the directory alone is not a possible file match.
1876
+ if (!count && !filenames_only && (base(prefix) ~ /^(secrets?|cert(ificate)?s?|keys?|private|credentials?)([._-]|$)/ || tolower(prefix) ~ /\.(pem|key|p12|pfx|jks|keystore|kdbx|kubeconfig|env)([._-]|$)/ || sensitive_path(join_path(dir, prefix) suffix) != "")) return "a key or certificate file"
1815
1877
  return found
1816
1878
  }
1817
- # Literal words retain the full classifier. Glob words use canonical names and all protected extensions;
1818
- # substring-only token names outside that canonical set are not glob probes.
1879
+ # For globs that cannot be checked against bounded real matches, intersect the basename with
1880
+ # the token-name rule: a token/tokens component, optionally bounded by ., _ or -. A fixed
1881
+ # source suffix is exempt just as it is for literal paths (*.cs and src/**/*.ts remain usable).
1882
+ function token_glob(b, i, j, left, right, separators) {
1883
+ b = tolower(b)
1884
+ if (code_file(b) || b ~ /\.(css|scss|less)$/) return 0
1885
+ if (length(b) > 255) return 1
1886
+ # The literal name classifier folds case. Broaden POSIX case classes before testing it.
1887
+ gsub(/\[:(upper|lower):\]/, "[:alpha:]", b)
1888
+ separators = "._-"
1889
+ for (i = 0; i <= 3; i++) for (j = 0; j <= 3; j++) {
1890
+ left = i ? "\004" substr(separators, i, 1) : ""
1891
+ right = j ? substr(separators, j, 1) "\004" : ""
1892
+ if (overlap(b, left "token" right) || overlap(b, left "tokens" right)) return 1
1893
+ }
1894
+ return 0
1895
+ }
1819
1896
  function alt_kind(a, b, d, kind, k, glob) {
1820
- # An unsupported expansion may supply slashes too, reaching a protected directory even with a fixed suffix.
1821
- if (index(a, "\001")) return "an unresolved file name that may name a protected file"
1822
- b = a; sub(/.*\//, "", b)
1823
- glob = (a ~ /[\004-\006]/)
1897
+ # Runtime text can supply a pathname or switch, even with a fixed suffix. Never evaluate it.
1898
+ if (a ~ /[\001\003]/) return "an unresolved file name that may name a protected file"
1824
1899
  if (!has_sentinel(a)) return sensitive_path(a)
1825
- # A supported reader glob is judged by its real regular-file matches, not possible key basenames.
1900
+ b = without_trailing_slashes(a); sub(/.*\//, "", b)
1901
+ glob = (a ~ /[\004-\006]/)
1902
+ # Keep the bounded literal-prefix reader probe; it checks real matches rather than guesses.
1826
1903
  if (glob && substr(a, length(a), 1) == "\004") return glob_secret_match(a)
1827
- if (!glob) {
1828
- kind = sensitive_path(a)
1829
- if (kind != "") return kind
1830
- if (only_runtime(b)) return ""
1831
- a = tolower(a); b = tolower(b)
1904
+ if (glob && b ~ /[\004-\006]/ && token_glob(b)) {
1905
+ # A single star with a fixed suffix can be decided from bounded real matches.
1906
+ if (b ~ /\004.*\.[A-Za-z0-9_+-]+$/) {
1907
+ kind = glob_secret_match(a, 1)
1908
+ if (kind != "") return kind
1909
+ } else return "a token file"
1832
1910
  }
1833
1911
  d = a; sub(/[^\/]*$/, "", d)
1834
1912
  if (has_sentinel(b)) {
@@ -1839,6 +1917,7 @@ function alt_kind(a, b, d, kind, k, glob) {
1839
1917
  }
1840
1918
  for (k = 1; k <= nextension; k++) if (overlap(b, "\004." EXT[k])) return glob_secret_match(a)
1841
1919
  } else if (glob) {
1920
+ if ((kind = sensitive_path(a)) != "") return kind
1842
1921
  for (k = 1; k <= nprobe; k++) if (b == PROBE[k]) {
1843
1922
  kind = sensitive_path(d b)
1844
1923
  if (kind != "") return kind
@@ -1850,10 +1929,17 @@ function alt_kind(a, b, d, kind, k, glob) {
1850
1929
  return ""
1851
1930
  }
1852
1931
  # The kind of protected file operand k of A names; via_pattern says the answer came from a pattern or a variable.
1853
- function operand_kind(A, k, off, filenames, w, m, j, kind) {
1932
+ function operand_kind(A, k, off, filenames, trim_slash, w, m, j, kind, normalized, home) {
1854
1933
  w = A[k]; m = mask_of(A, k); via_pattern = 0; matched_file = ""; filenames_only = filenames
1855
1934
  if (off > 0) { w = substr(w, off + 1); m = substr(m, off + 1) }
1856
- if (!expands(w, m)) return sensitive_path(w)
1935
+ if (!expands(w, m)) {
1936
+ kind = sensitive_path(w)
1937
+ if (trim_slash && kind == "" && (normalized = without_trailing_slashes(w)) != w) kind = sensitive_path(normalized)
1938
+ return kind
1939
+ }
1940
+ if (w ~ /^~\// && substr(m, 1, 1) == "u" && ENVIRON["HOME"] ~ /^\//) {
1941
+ home = ENVIRON["HOME"]; w = home substr(w, 2); gsub(/./, "l", home); m = home substr(m, 2)
1942
+ }
1857
1943
  resolve(w, m); via_pattern = 1
1858
1944
  for (j = 1; j <= nalt; j++) { kind = alt_kind(ALT[j]); if (kind != "") return kind }
1859
1945
  return ""
@@ -2143,6 +2229,7 @@ function scan_short(w, shortvals, sed_like, i, c, last) {
2143
2229
  function report_operand(A, k, b, filenames, kind) {
2144
2230
  kind = operand_kind(A, k, 0, filenames)
2145
2231
  if (kind != "" && matched_file != "") report(b " of " kind " (" matched_file ") prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
2232
+ else if (kind ~ /^an unresolved file name/) report(b " has " kind, "name the exact non-credential file instead of using a variable or command substitution")
2146
2233
  else if (kind != "" && via_pattern) report(b " of a glob that may match " kind " prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
2147
2234
  else if (kind != "") report(b " of " kind " prints credentials", "name the file and the key you need in your report; ask the user to confirm a value instead of printing it; for an env template read the .env.example")
2148
2235
  }
@@ -2243,16 +2330,9 @@ function bulk_roots(A, s, n, b, k, j, w, m, dir, ended, enabled, target, skip
2243
2330
  delete ROOT; delete ROOT_MASK; delete ROOT_DIR; nr = 0; bulk_find = 0; bulk_reads = 1
2244
2331
  dir = effective_dir
2245
2332
  if (b == "git") {
2246
- s++
2247
- while (s <= n && A[s] ~ /^-/) {
2248
- w = A[s]
2249
- if (w == "-C" || w == "--work-tree") { dir = literal_directory(A[s + 1], dir); s += 2 }
2250
- else if (w ~ /^-C./) { dir = literal_directory(substr(w, 3), dir); s++ }
2251
- else if (w ~ /^--work-tree=/) { dir = literal_directory(substr(w, 13), dir); s++ }
2252
- else if (w == "-c" || w == "--git-dir") s += 2
2253
- else s++
2254
- }
2255
- if (A[s] != "grep") return 0
2333
+ s = git_options(A, VM, s, n)
2334
+ if (!s || A[s] != "grep") return 0
2335
+ if (GIT_ROOT != "") dir = join_path(dir, GIT_ROOT)
2256
2336
  for (k = s + 1; k <= n; k++) if (A[k] == "--no-index") enabled = 1
2257
2337
  if (!enabled) return 0
2258
2338
  b = "grep"
@@ -2454,41 +2534,100 @@ function copy_globs_safe(A, s, n, b, k, w, m, start, patterns, count) {
2454
2534
  }
2455
2535
  return copy_glob_probe(patterns)
2456
2536
  }
2457
- function transfer_files(A, s, n, b, k, last, options, kind, w, eq, off, ended, m, token_dir) {
2537
+ function transfer_files(A, s, n, b, k, last, options, kind, w, eq, off, ended, m, token_dir, normalized) {
2458
2538
  for (k = s + 1; k <= n; k++) if (A[k] ~ /^-./) options = 1
2459
2539
  last = n
2460
- if (b ~ /^(cp|mv|ln)$/ && !options && n == s + 2) last--
2540
+ if (b ~ /^(cp|mv|ln)$/ && !options && n == s + 2 && !expands(A[n], mask_of(A, n))) last--
2461
2541
  for (k = s + 1; k <= last; k++) {
2462
2542
  w = A[k]; off = 0
2463
2543
  if (!ended && w == "--") { ended = 1; continue }
2464
2544
  if (!ended && w ~ /^-./) {
2465
2545
  eq = index(w, "=")
2466
- if (w !~ /^--/ || !eq) continue
2467
- off = eq
2546
+ if (w ~ /^--/ && eq) off = eq
2547
+ else if (!expands(w, mask_of(A, k))) continue
2468
2548
  }
2469
- m = mask_of(A, k)
2470
- token_dir = b == "mv" && s == 1 && !off && literal_word(w, m) && !expands(w, m) ? token_directory(w) : 0
2471
- kind = token_dir ? sensitive_path(w, 1) : operand_kind(A, k, off)
2549
+ m = mask_of(A, k); normalized = without_trailing_slashes(w)
2550
+ token_dir = (b == "mv" || (b ~ /^(cp|rsync|scp)$/ && normalized != w)) && s == 1 && !off && literal_word(w, m) && !expands(w, m) ? token_directory(w) : 0
2551
+ kind = token_dir ? sensitive_path(normalized, 1) : operand_kind(A, k, off, 0, 1)
2472
2552
  if (kind == "" && token_dir == 2) kind = "a token directory"
2473
2553
  if (kind != "") report(b " reads " kind, "name only non-credential source files")
2474
2554
  }
2475
2555
  }
2556
+ # A revision can contain punctuation that the shell resolver treats as glob or brace syntax.
2557
+ # Recognize only simple refs, ancestry suffixes, reflog selectors and ranges with no runtime text.
2558
+ function git_revision(w, m, ref) {
2559
+ if (m ~ /[cC]/ || w !~ /[~^]|@[{]|[.][.]/) return 0
2560
+ ref = "[A-Za-z0-9_/][A-Za-z0-9_/-]*([.][A-Za-z0-9_/-]+)*"
2561
+ ref = "(" ref "([~^][0-9]*)*|(" ref ")?@[{]([0-9]+|u|upstream)[}])"
2562
+ return w ~ ("^" ref "([.][.][.]?" ref ")?$")
2563
+ }
2564
+ # A revision-shaped operand can name a credential backup on disk.
2565
+ function git_backup_kind(w, kind) {
2566
+ do {
2567
+ kind = sensitive_path(w)
2568
+ if (kind != "") return kind
2569
+ } while (sub(/([~^][0-9]*|@[{]([0-9]+|u|upstream)[}])$/, "", w))
2570
+ return ""
2571
+ }
2572
+ function git_revision_kind(w, refs, count, k, kind) {
2573
+ if (!index(w, "..")) return git_backup_kind(w)
2574
+ kind = sensitive_path(w)
2575
+ if (kind != "") return kind
2576
+ count = split(w, refs, /[.][.][.]?/)
2577
+ for (k = 1; k <= count; k++) {
2578
+ kind = git_backup_kind(refs[k])
2579
+ if (kind != "") return kind
2580
+ }
2581
+ return ""
2582
+ }
2476
2583
  # Git grep reuses pattern/file separation; ls-files never reaches this content path.
2477
- function git_content(A, s, n, subcommand, k, w, kind, ended, pathspec, m, local_add) {
2478
- subcommand = A[s + 1]
2479
- if (subcommand ~ /^(add|checkout|restore|rm|mv|diff|log|show)$/) {
2480
- for (k = s + 2; k <= n; k++) {
2584
+ function git_content(A, s, n, start, subcommand, k, w, kind, ended, pathspec, m, local_add, cwd, tree, gitdir, operands, count, d, dir, j, glob, no_index, revision) {
2585
+ start = s; s = git_options(A, VM, s, n)
2586
+ if (!s) {
2587
+ report("Git global options or subcommand cannot be resolved", "use an explicit subcommand and literal Git directory options")
2588
+ return
2589
+ }
2590
+ subcommand = A[s]; cwd = GIT_CWD; tree = GIT_ROOT; gitdir = GIT_DIR
2591
+ if (subcommand == "diff")
2592
+ for (k = s + 1; k <= n && A[k] != "--"; k++)
2593
+ if (A[k] == "--no-index") { no_index = 1; break }
2594
+ if (subcommand ~ /^(add|checkout|restore|rm|mv|diff|log|show|cat-file)$/) {
2595
+ for (k = s + 1; k <= n; k++) {
2481
2596
  if (!ended && A[k] == "--") { ended = 1; continue }
2482
2597
  pathspec = ended || subcommand ~ /^(add|checkout|restore|rm|mv)$/
2483
2598
  w = A[k]; m = mask_of(A, k)
2484
- local_add = s == 1 && subcommand == "add" && literal_word(w, m) && !expands(w, m)
2485
- kind = git_path_kind(w, pathspec, 0, local_add)
2599
+ local_add = start == 1 && subcommand == "add" && literal_word(w, m) && !expands(w, m)
2600
+ revision = !pathspec && !no_index && git_revision(w, m)
2601
+ kind = git_path_kind(w, pathspec || no_index, 0, local_add, tree)
2602
+ if (kind == "" && revision) kind = git_revision_kind(w)
2603
+ if (kind == "" && no_index && (ended || w !~ /^-/) && w ~ /[~^]|@[{]/) kind = git_backup_kind(w)
2604
+ if (kind == "" && !revision && expands(w, m))
2605
+ kind = operand_kind(A, k, w ~ /^--[^=]*=/ ? index(w, "=") : 0)
2606
+ # Git also interprets quoted pathspec wildcards. Model a basename pattern without evaluating it.
2607
+ if (kind == "" && pathspec && w !~ /^-/ && w ~ /[*?\[]/) {
2608
+ glob = w; gsub(/[^*?\[]/, "l", glob); gsub(/[*?\[]/, "u", glob)
2609
+ resolve(w, glob)
2610
+ for (j = 1; j <= nalt; j++) if (token_glob(base(ALT[j]))) { kind = "a token file"; break }
2611
+ }
2486
2612
  if (kind != "") report("git " subcommand " names " kind, "name only non-credential source files; list filenames with git ls-files")
2487
2613
  }
2488
2614
  }
2615
+ if (subcommand == "grep") reader(A, s, n)
2616
+ if (tree != "" || gitdir != "") {
2617
+ for (k = s + 1; k <= n; k++) if (relative_link_word(A[k]) && (subcommand != "grep" || k in ROPER)) operands[++count] = A[k]
2618
+ for (d = 1; d <= nlink_possible; d++) {
2619
+ dir = LINK_POSSIBLE[d]
2620
+ for (j = 1; j <= nwrap; j++) dir = literal_directory(WRAP_DIR[j], dir)
2621
+ if (gitdir != "" && sensitive_path(join_path(join_path(dir, cwd), gitdir)) != "")
2622
+ report("Git directory may contain credentials", "use a non-credential Git directory")
2623
+ if (tree == "") continue
2624
+ dir = join_path(dir, tree)
2625
+ if (sensitive_path(without_trailing_slashes(dir)) != "") report("Git work directory may contain credentials", "use a non-credential work directory")
2626
+ if (count) check_links_in(operands, count, dir)
2627
+ }
2628
+ }
2489
2629
  if (subcommand !~ /^(grep|show|cat-file)$/) return
2490
- if (subcommand == "grep") reader(A, s + 1, n)
2491
- for (k = s + 2; k <= n; k++) {
2630
+ for (k = s + 1; k <= n; k++) {
2492
2631
  if (subcommand == "grep" && !(k in ROPER)) continue
2493
2632
  w = tolower(A[k]); sub(/^.*[\/:]/, "", w)
2494
2633
  if (w == "secrets.json") report("git " subcommand " of a credentials file prints credentials", "name only non-credential source files; list filenames with git ls-files")
@@ -2537,7 +2676,7 @@ function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
2537
2676
  if (interpreter_name(b)) interpreter_invocation(A, s, n, b)
2538
2677
  if (b == "cd" || b == "pushd" || b == "popd") { change_directory(A, s, n, b); return }
2539
2678
  check_bulk_roots(A, s, n, b)
2540
- if (A[s] == "git") git_content(A, s, n)
2679
+ if (b == "git") git_content(A, s, n)
2541
2680
  shell_config(A, s, n, b)
2542
2681
  collect_bindings(A, s, n, b)
2543
2682
  if (b == "for" || b == "select" || b == "unset") return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "8.10.2",
3
+ "version": "8.10.3",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [