@cratis/pi 7.151.0 → 7.151.2

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.
@@ -103,6 +103,13 @@ capacity numbers into workflows or guidance.
103
103
  - **Never** route `pull_request`-triggered jobs of a *public* repository to self-hosted
104
104
  runners — that hands code execution on our infrastructure to any fork.
105
105
 
106
+ ## Arc proxies
107
+
108
+ - Workflows never generate Arc TypeScript proxies; the client commits them. Every `dotnet
109
+ build`/`publish` of an Arc project passes `-p:CratisProxiesOutputPath=` (empty, Arc's off
110
+ switch; `DisableProxyGenerator` is repository-defined, not Arc's). See the
111
+ **cratis-arc-command** proxy-generation reference.
112
+
106
113
  ## Automation that writes back
107
114
 
108
115
  - A bot that pushes to a branch must **retry with `git pull --rebase`** — the branch
@@ -34,6 +34,15 @@ searches with secret/certificate/key-like prefixes also remain blocked. For ripg
34
34
  symlinks, not filename-only mode. Literal directory checks retain the process-cwd fallback when the
35
35
  payload omits cwd; glob probing does not. Filesystem check/use races remain: this is not a sandbox.
36
36
 
37
+ A Pi session runs guards from its starting checkout. Refresh the corpus there with `cratis ai update`,
38
+ or start a new session in the checkout you change. Selecting a newer installed guard corpus per call
39
+ is tracked in [Cratis/AI#1114](https://github.com/Cratis/AI/issues/1114).
40
+
41
+ Reader glob probes skip directories only when decoded options establish a nonrecursive reader;
42
+ unknown or recursive grep options keep directory matches conservative. Simple sed print/substitution
43
+ programs are data only without in-place edits, execution, or file writes; `-f` remains a file operand.
44
+ GitHub API endpoints are normalized before checking sensitive paths.
45
+
37
46
  The shell-write guard classifies **write-target words**, not every word. It lexes the command into
38
47
  simple commands. When every command is a reviewed reader or staging verb (`cat`, `head`, `tail`, `wc`,
39
48
  `ls`, `rg`, `grep`, `echo`, `git status|diff|log|show|add|commit`, `git ls-files`, `jq`, read-only
@@ -841,12 +850,16 @@ source root is not `Source/` re-scopes the `paths` globs there too.
841
850
 
842
851
  **One property gates the proxy generator.** The generator's MSBuild target is
843
852
  `Condition="'$(CratisProxiesOutputPath)' != ''"`, so clearing that property with
844
- `-p:CratisProxiesOutputPath=` is the *only* way to make it no-op. There is no
845
- `DisableProxyGenerator` property — MSBuild silently accepts unknown `-p:` names, so passing one
846
- looks like it works and changes nothing. A consuming repository's build workflow should split the
847
- two configurations the way the shipped gates do: Release clears the path, Debug does not, because
848
- `general.md` makes the Debug build the canonical trigger for regenerating the TypeScript proxies
849
- the frontend phase depends on.
853
+ `-p:CratisProxiesOutputPath=` is Arc's off switch. `DisableProxyGenerator` is not an Arc
854
+ property; it works only where a repository defines it — MSBuild silently accepts unknown `-p:`
855
+ names, so passing it elsewhere looks like it works and changes nothing. Proxies are generated and
856
+ committed by the client, never in CI, so CI builds always clear the path.
857
+
858
+ The Debug/Release split applies to the shipped client-side local gates only: Release clears the
859
+ path, and the committing client's Debug gate does not, because `general.md` makes the Debug build
860
+ the canonical trigger for regenerating the TypeScript proxies the frontend phase depends on, and
861
+ the client commits the result. A consuming repository's CI never copies the Debug proxy step; it
862
+ passes `-p:CratisProxiesOutputPath=` in every configuration.
850
863
 
851
864
  ## Unattended runs
852
865
 
@@ -436,15 +436,91 @@ function split_scan(w, m, k, r, hit) {
436
436
  }
437
437
  return ""
438
438
  }
439
- function end_cmd( k, m, w, j, hit, exempt, path_git) {
439
+ # Admit only print/substitution scripts without secondary commands, execution or file writes.
440
+ function safe_sed_script(p, delimiter, i, c, spans) {
441
+ if (p ~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 1
442
+ if (substr(p, 1, 1) != "s" || length(p) < 4) return 0
443
+ delimiter = substr(p, 2, 1)
444
+ if (delimiter ~ /[A-Za-z0-9\\ \t\n]/) return 0
445
+ for (i = 3; i <= length(p); i++) {
446
+ c = substr(p, i, 1)
447
+ if (c == "\n") return 0
448
+ if (c == "\\") { if (++i > length(p) || substr(p, i, 1) == "\n") return 0; continue }
449
+ if (c == delimiter && ++spans == 2) return substr(p, i + 1) ~ /^[gpI0-9]*$/
450
+ }
451
+ return 0
452
+ }
453
+ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
454
+ delete SED_DATA
455
+ for (i = s + 1; i <= n && A[i] != "--"; i++) if (A[i] ~ /^(-e|--expression)(=|$)/ || A[i] ~ /^-e./) explicit = 1
456
+ for (i = s + 1; i <= n; i++) {
457
+ w = A[i]
458
+ if (!ended && w == "--") { ended = 1; continue }
459
+ if (!ended && (w ~ /^-[nEr]+$/ || w ~ /^--(quiet|silent|regexp-extended)$/)) continue
460
+ if (!ended && (w == "-e" || w == "--expression")) { if (++i > n) return 0; program = A[i] }
461
+ else if (!ended && w ~ /^(-e.|--expression=)/) { program = w; sub(/^(-e|--expression=)/, "", program) }
462
+ else if (!ended && w ~ /^-/) return 0
463
+ else if (!explicit && !scripts) program = w
464
+ else continue
465
+ if (!safe_sed_script(program)) return 0
466
+ SED_DATA[i] = 1; scripts++
467
+ }
468
+ return scripts > 0
469
+ }
470
+ # Only fully modeled literal non-readers can distinguish data slots from paths.
471
+ function nonreader(A, M, n, i, w, first, read) {
472
+ delete DATA
473
+ for (i = 1; i <= n; i++) if (expands(A[i], M[i]) || index(A[i], "`") || A[i] ~ /^</) return 0
474
+ first = tolower(base(A[1]))
475
+ if (first == "sed") {
476
+ if (!sed_slots(A, 1, n)) return 0
477
+ for (i in SED_DATA) DATA[i] = 1
478
+ return 1
479
+ }
480
+ if (first == "dotnet") return A[2] ~ /^(test|build)$/
481
+ if (first == "git" && A[2] == "clone") {
482
+ for (i = 3; i <= n; i++) if (A[i] ~ /^(https?|ssh|git):\/\// || A[i] ~ /^git@/) DATA[i] = 1
483
+ return 1
484
+ }
485
+ if (first == "shellcheck") return 1
486
+ if (first == "find") {
487
+ for (i = 2; i <= n; i++) {
488
+ w = A[i]
489
+ if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
490
+ if (w ~ /^-(name|iname|path|regex|wholename)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
491
+ if (w ~ /^-(maxdepth|mindepth)$/) { if (++i > n || A[i] !~ /^[0-9]+$/) return 0; DATA[i] = 1; continue }
492
+ if (w ~ /^-/ && w !~ /^-(print|print0|type|L|P|H)$/) return 0
493
+ if (w == "-type") { if (++i > n || A[i] !~ /^[bcdflps]$/) return 0 }
494
+ }
495
+ return 1
496
+ }
497
+ if (first != "gh") return 0
498
+ read = A[2] " " A[3]
499
+ if (A[2] != "api" && read !~ /^(repo (view|list)|issue (view|list|status)|pr (view|list|status|diff|checks)|release (view|list)|run (view|list|watch)|search (issues|prs|repos|commits|code))$/) return 0
500
+ for (i = A[2] == "api" ? 3 : 4; i <= n; i++) {
501
+ w = A[i]
502
+ if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
503
+ if (w ~ /^(--jq|-q|--template|-t)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
504
+ if (w ~ /^(--json|--repo|-R|--limit|-L|--hostname|--header|-H)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
505
+ if (A[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > n || A[i] !~ /^(GET|HEAD)$/) return 0; continue }
506
+ if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
507
+ if (A[2] != "api") DATA[i] = 1
508
+ }
509
+ return 1
510
+ }
511
+ function end_cmd( k, m, w, j, hit, exempt, path_git, paths_only) {
440
512
  flush_word()
441
513
  if (nw > 0) {
442
514
  commands++
515
+ delete PROBE_WORDS; PROBE_COUNT = nw
516
+ for (k = 1; k <= nw; k++) PROBE_WORDS[k] = W[k]
517
+ paths_only = nonreader(W, WM, nw)
443
518
  regex_slots(W, 1, nw)
444
519
  path_git = git_paths(W, WM, nw)
445
520
  for (k = 1; k <= nw; k++) {
446
521
  if (path_git && W[k] !~ /^-/) continue
447
522
  if (is_assign(W[k])) set_var(W[k], WM[k])
523
+ if (paths_only && ((k in DATA) || sensitive_path(W[k]) == "")) continue
448
524
  exempt = (k in RP) && !WU[k]
449
525
  if (exempt && RP[k] < 0) continue
450
526
  w = exempt ? substr(W[k], 1, RP[k]) : W[k]
@@ -735,6 +811,7 @@ function sensitive_path(w, l, b) {
735
811
  b ~ /credentials.*\.(yaml|yml|xml|ini|toml|txt|conf|properties|config)([.]|$)/ ||
736
812
  b ~ /secrets\.ya?ml([.]|$)/) return "a credentials file"
737
813
  if (l ~ /\.docker\/config\.json$/) return "the Docker registry credentials"
814
+ if (l ~ /(^|\/)(\.ssh|\.aws)\/?$/) return "a credential directory"
738
815
  if (l ~ /\/proc\/[^\/]*\/environ$/) return "a process environment"
739
816
  if (l ~ /^\/(var\/)?run\/secrets\//) return "mounted secrets"
740
817
  return ""
@@ -1017,7 +1094,10 @@ function probe_read_chain(text, prior, i, c, q, normal, n, k, readers, reader
1017
1094
  n = split(normal, parts, "\034")
1018
1095
  for (k = 1; k <= n; k++) {
1019
1096
  clause = parts[k]; sub(/^[ \t]+/, "", clause); sub(/[ \t]+$/, "", clause)
1020
- if (clause ~ /^(cat|rg|grep|egrep|fgrep|head|tail)[ \t]/) { readers++; reader_index = prior + k; continue }
1097
+ if (clause ~ /^(cat|rg|grep|egrep|fgrep|head|tail|wc)[ \t]/) {
1098
+ glob_recursive = reader_may_recurse(PROBE_WORDS, PROBE_COUNT)
1099
+ readers++; reader_index = prior + k; continue
1100
+ }
1021
1101
  if (clause ~ /^git[ \t]+diff([ \t]+(--cc|--stat|--check|--no-color))*$/) continue
1022
1102
  if (clause ~ /^git[ \t]+log([ \t]+(-[0-9]+|--format=[^ \t]+|--oneline|--no-color))*$/) continue
1023
1103
  if (clause ~ /^git[ \t]+(branch[ \t]+--show-current|rev-parse[ \t]+HEAD|status[ \t]+--short)$/) continue
@@ -1025,6 +1105,25 @@ function probe_read_chain(text, prior, i, c, q, normal, n, k, readers, reader
1025
1105
  }
1026
1106
  return readers == 1 && reader_index == commands
1027
1107
  }
1108
+ # Options are decoded by tokenize, not inferred from quote-masked command text.
1109
+ # Only known nonrecursive grep flags can justify skipping a directory. Unknown/value options refuse.
1110
+ function reader_may_recurse(A, n, i, j, w, b, ended, pattern) {
1111
+ b = base(A[1])
1112
+ if (b ~ /^(cat|head|tail|wc)$/) return 0
1113
+ if (b !~ /^(grep|egrep|fgrep)$/) return 1
1114
+ for (i = 2; i <= n; i++) {
1115
+ w = A[i]
1116
+ if (!ended && w == "--") { ended = 1; continue }
1117
+ if (!ended && w ~ /^-/) {
1118
+ if (w == "-e" || w == "--regexp") { if (++i > n) return 1; pattern = 1; continue }
1119
+ if (w ~ /^(-e.|--regexp=)/) { pattern = 1; continue }
1120
+ if (w ~ /^--/ || w !~ /^-[EFGPivwxcnNlLoqsaHIhVzuUSyZ0]+$/) return 1
1121
+ continue
1122
+ }
1123
+ if (!pattern) pattern = 1
1124
+ }
1125
+ return 0
1126
+ }
1028
1127
  function glob_directory( text, head, dir, prior) {
1029
1128
  dir = ENVIRON["GS_CWD"]; text = CMD
1030
1129
  if (ENVIRON["GS_GLOB_SAFE"] != "1" || dir == "" || dir !~ /^\//) return ""
@@ -1052,10 +1151,13 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1052
1151
  "checked_cd() { local logical; logical=$(cd -L -- \"$1\" && pwd -P) || return 3; " \
1053
1152
  "cd -P -- \"$1\" || return 3; [ \"$logical\" = \"$PWD\" ] && [ -r . ] && [ -x . ]; }; " \
1054
1153
  "checked_cd \"$1\" || exit 3; parent=${2%/*}; stem=${2##*/}; [ \"$parent\" != \"$2\" ] || parent=.; " \
1055
- "checked_cd \"$parent\" || exit 3; " \
1056
- "n=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ -f \"$f\" ] && [ ! -L \"$f\" ] || exit 3; " \
1154
+ "probe=$parent; while [ ! -e \"$probe\" ]; do [ ! -L \"$probe\" ] || exit 3; next=${probe%/*}; " \
1155
+ "[ \"$next\" != \"$probe\" ] || next=.; probe=$next; done; " \
1156
+ "checked_cd \"$probe\" || exit 3; [ \"$probe\" = \"$parent\" ] || { echo OK; exit 0; }; " \
1157
+ "n=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ ! -L \"$f\" ] || exit 3; " \
1158
+ "if [ -d \"$f\" ]; then [ \"$3\" != 1 ] || exit 3; continue; fi; [ -f \"$f\" ] || exit 3; " \
1057
1159
  "case \"$PWD/$f\" in *[!a-zA-Z0-9._/@+=,:%-]*) exit 3;; esac; printf \"F:%s\\n\" \"$PWD/$f\"; done; echo OK"
1058
- cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " 2>/dev/null"
1160
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " " shell_quote(glob_recursive ? "1" : "0") " 2>/dev/null"
1059
1161
  while ((cmd | getline line) > 0) {
1060
1162
  if (line == "OK") { ok = 1; continue }
1061
1163
  if (ok || substr(line, 1, 2) != "F:" || ++count > 200) { ok = 0; break }
@@ -1069,6 +1171,10 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1069
1171
  }
1070
1172
  close(cmd)
1071
1173
  if (!ok) { matched_file = ""; return "a key or certificate file" }
1174
+ # Explicit credential-name prefixes stay protected even before those files exist.
1175
+ if (!count && base(prefix) != "") for (k = 1; k <= nprobe; k++) {
1176
+ if (index(PROBE[k], tolower(base(prefix))) == 1 && sensitive_path(PROBE[k]) != "") return sensitive_path(PROBE[k])
1177
+ }
1072
1178
  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"
1073
1179
  return found
1074
1180
  }
@@ -1080,6 +1186,8 @@ function alt_kind(a, b, d, kind, k, glob) {
1080
1186
  b = a; sub(/.*\//, "", b)
1081
1187
  glob = (a ~ /[\004-\006]/)
1082
1188
  if (!has_sentinel(a)) return sensitive_path(a)
1189
+ # A supported reader glob is judged by its real regular-file matches, not possible key basenames.
1190
+ if (glob && substr(a, length(a), 1) == "\004") return glob_secret_match(a)
1083
1191
  if (!glob) {
1084
1192
  kind = sensitive_path(a)
1085
1193
  if (kind != "") return kind
@@ -1284,7 +1392,21 @@ function dock(A, s, n, off, sub1, nxt, insp, k, listing) {
1284
1392
  }
1285
1393
  if (sub1 == "exec" && np >= 3 + off) analyze(A, PI[3 + off], n)
1286
1394
  }
1287
- function gh(A, s, n, i, w, mutating, k) {
1395
+ function endpoint_path(path, i, pair, value, decoded) {
1396
+ sub(/[?#].*$/, "", path)
1397
+ endpoint_uncertain = 0
1398
+ for (i = 1; i <= length(path); i++) {
1399
+ pair = tolower(substr(path, i + 1, 2))
1400
+ if (substr(path, i, 1) == "%" && length(pair) == 2 && pair ~ /^[0-9a-f][0-9a-f]$/) {
1401
+ value = HEX[substr(pair, 1, 1)] * 16 + HEX[substr(pair, 2, 1)]
1402
+ if (value < 32 || value == 127) { endpoint_uncertain = 1; return "" }
1403
+ decoded = decoded sprintf("%c", value); i += 2
1404
+ } else decoded = decoded substr(path, i, 1)
1405
+ }
1406
+ sub(/[?#].*$/, "", decoded); gsub(/\/\/+/, "/", decoded); sub(/\/+$/, "", decoded)
1407
+ return decoded
1408
+ }
1409
+ function gh(A, s, n, i, w, mutating, k, path, kind) {
1288
1410
  kparse(A, s + 1, n, "XHfFqtR")
1289
1411
  if (P[1] == "secret") {
1290
1412
  if (P[2] != "set" && P[2] != "delete" && P[2] != "remove")
@@ -1298,6 +1420,10 @@ function gh(A, s, n, i, w, mutating, k) {
1298
1420
  return
1299
1421
  }
1300
1422
  if (P[1] == "api") {
1423
+ for (k = 2; k <= np; k++) {
1424
+ path = endpoint_path(P[k]); kind = sensitive_path(path)
1425
+ if (endpoint_uncertain || kind != "") report("gh api endpoint names a protected file", "request only non-credential file contents; list filenames instead")
1426
+ }
1301
1427
  mutating = 0
1302
1428
  for (i = s + 1; i < n; i++) if (A[i] == "-X" || A[i] == "--method") { w = toupper(A[i + 1]); if (w == "PUT" || w == "PATCH" || w == "DELETE") mutating = 1 }
1303
1429
  if (!mutating)
@@ -1358,6 +1484,11 @@ function env_program(b, p, t) {
1358
1484
  }
1359
1485
  function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued, valued2, shortvals, filenames) {
1360
1486
  b = base(A[s]); mode = ""; valued = " "; valued2 = " "; shortvals = ""
1487
+ if (b == "sed") {
1488
+ sed_slots(A, s, n)
1489
+ for (k = s + 1; k <= n; k++) if (!(k in SED_DATA) && A[k] !~ /^-/) report_operand(A, k, b, 0)
1490
+ return
1491
+ }
1361
1492
  if (b == "busybox") { if (base(A[s + 1]) == "awk") reader(A, s + 1, n); return }
1362
1493
  if (b ~ /^(awk|gawk|mawk|nawk|jq|yq|gojq|jaq)$/) for (k = s + 1; k <= n; k++) env_program(b, A[k])
1363
1494
  if (b ~ /^(rg|grep|egrep|fgrep)$/) {
@@ -57,6 +57,9 @@ function quoted_literal(s) {
57
57
  return s
58
58
  }
59
59
  function raw_brace_word(w, quote, first, bare) {
60
+ # Unknown interpreter/program text may concatenate brace fragments: retain its conservative refusal.
61
+ # Modeled readers never send their opaque filters through this fallback.
62
+ if (unparsed && index(w, "{") && !index(w, "}")) candidate("*")
60
63
  if (!(w ~ /[$`"\047\\]/)) return
61
64
  first = substr(w, 1, 1); quote = (first == "\047" || first == "\"") ? first : ""
62
65
  if (quote != "" && substr(w, length(w), 1) == quote && index(substr(w, 2, length(w) - 2), quote) == 0) return
@@ -164,6 +167,7 @@ function endword() {
164
167
  if (redirect) {
165
168
  if (!(redirect == 2 && word ~ /^([0-9]+|-)$/)) {
166
169
  file_redirect = 1
170
+ redirect_words = redirect_words " " word
167
171
  if (changed_cwd || lead_glob) unparsed = 1
168
172
  if (changed_cwd || word ~ /[$`*?\[{~()]/ || protected(word)) bad = 1
169
173
  }
@@ -211,6 +215,7 @@ function options_allowed(verb, first, i, w) {
211
215
  }
212
216
  }
213
217
  if (verb == "git diff" && w ~ /^-U[0-9]+$/) continue
218
+ if (verb == "shellcheck" && w ~ /^--severity=(error|warning|info|style)$/) continue
214
219
  if ((verb == "git log" && w ~ /^--(format|pretty)=/) || (verb == "git show" && w ~ /^--format=/)) {
215
220
  if (index(w, "%(")) return 0
216
221
  continue
@@ -256,9 +261,41 @@ function directory_metadata() {
256
261
  if (argc == 5) return (W[4] == "status" && W[5] == "--short") || (W[4] == "rev-parse" && W[5] == "HEAD") || (W[4] == "branch" && W[5] == "--show-current")
257
262
  return argc == 6 && W[4] == "tag" && W[5] == "--list" && W[6] !~ /^-/
258
263
  }
259
- # -n alone is not read-only: sed scripts can still execute or write files.
260
- # Only numeric/last-line print addresses qualify, with no additional options.
261
- function print_only_sed( i, ended) {
264
+ # Keep this bounded sed grammar in sync with the secrets guard. Program files and unknown commands
265
+ # remain conservative; only print/substitution scripts without execution or file-write flags qualify.
266
+ function safe_sed_script(p, delimiter, i, c, spans) {
267
+ if (p ~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 1
268
+ if (substr(p, 1, 1) != "s" || length(p) < 4) return 0
269
+ delimiter = substr(p, 2, 1)
270
+ if (delimiter ~ /[A-Za-z0-9\\ \t\n]/) return 0
271
+ for (i = 3; i <= length(p); i++) {
272
+ c = substr(p, i, 1)
273
+ if (c == "\n") return 0
274
+ if (c == "\\") { if (++i > length(p) || substr(p, i, 1) == "\n") return 0; continue }
275
+ if (c == delimiter && ++spans == 2) return substr(p, i + 1) ~ /^[gpI0-9]*$/
276
+ }
277
+ return 0
278
+ }
279
+ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
280
+ delete SED_DATA
281
+ for (i = s + 1; i <= n && A[i] != "--"; i++) if (A[i] ~ /^(-e|--expression)(=|$)/ || A[i] ~ /^-e./) explicit = 1
282
+ for (i = s + 1; i <= n; i++) {
283
+ w = A[i]
284
+ if (!ended && w == "--") { ended = 1; continue }
285
+ if (!ended && (w ~ /^-[nEr]+$/ || w ~ /^--(quiet|silent|regexp-extended)$/)) continue
286
+ if (!ended && (w == "-e" || w == "--expression")) { if (++i > n) return 0; program = A[i] }
287
+ else if (!ended && w ~ /^(-e.|--expression=)/) { program = w; sub(/^(-e|--expression=)/, "", program) }
288
+ else if (!ended && w ~ /^-/) return 0
289
+ else if (!explicit && !scripts) program = w
290
+ else continue
291
+ if (!safe_sed_script(program)) return 0
292
+ SED_DATA[i] = 1; scripts++
293
+ }
294
+ return scripts > 0
295
+ }
296
+ # Preserve the original protected-file read lane exactly; newly admitted programs below retain
297
+ # the pre-existing conservative file-operand check rather than broadening this exception.
298
+ function legacy_print_sed( i, ended) {
262
299
  if (argc < 4 || W[2] != "-n" || W[3] !~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 0
263
300
  for (i = 4; i <= argc; i++) {
264
301
  if (!ended && W[i] == "--") { ended = 1; continue }
@@ -266,10 +303,69 @@ function print_only_sed( i, ended) {
266
303
  }
267
304
  return 1
268
305
  }
306
+ function print_only_sed( i, ended) {
307
+ if (legacy_print_sed()) return 1
308
+ if (!sed_slots(W, 1, argc)) return 0
309
+ for (i = 2; i <= argc; i++) {
310
+ if (i in SED_DATA) { if (globbed[i]) return 0; continue }
311
+ if (!ended && W[i] == "--") { ended = 1; continue }
312
+ if (!ended && W[i] ~ /^-/) continue
313
+ # Exempt script data, never the input paths: retain the existing protected-input refusal.
314
+ redirect_words = redirect_words " " W[i]
315
+ if (protected(W[i])) return 0
316
+ }
317
+ return 1
318
+ }
269
319
  # Verbs whose reviewed options are display flags only: a word-leading glob that expands to an option-shaped
270
320
  # file name can change what they print, never what they write or run. Every other verb refuses a leading glob.
321
+ function shell_quote(s) { gsub(/\047/, "\047\\\047\047", s); return "\047" s "\047" }
322
+ # rg can execute --pre supplied by a filename. Check real leading-glob matches, never command text.
323
+ function reader_globs( i, cmd, line, count, ok, script) {
324
+ if (changed_cwd || ENVIRON["GSW_GLOB_SAFE"] != "1") return 0
325
+ script = "cd -- \"$1\" && [ -r . ] && [ -x . ] || exit 3; unset GLOBIGNORE; shopt -s nullglob dotglob nocaseglob; " \
326
+ "n=0; while IFS= read -r f; do n=$((n+1)); [ \"$n\" -le 200 ] || exit 3; " \
327
+ "case $f in -*|*[!a-zA-Z0-9._/@+=,:%-]*) exit 3;; esac; printf \"F:%s\\n\" \"$f\"; done < <(compgen -G \"$2\"); echo OK"
328
+ for (i = 2; i <= argc; i++) {
329
+ if (W[i] == "--") return 1
330
+ if (!leading[i]) continue
331
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(ENVIRON["GSW_CWD"]) " " shell_quote(W[i]) " 2>/dev/null"
332
+ ok = count = 0
333
+ while ((cmd | getline line) > 0) {
334
+ if (line == "OK") { ok = 1; continue }
335
+ if (ok || substr(line, 1, 2) != "F:" || ++count > 200) { ok = 0; break }
336
+ }
337
+ if (close(cmd) != 0 || !ok) return 0
338
+ }
339
+ return 1
340
+ }
271
341
  function glob_safe() {
272
- return W[1] ~ /^(cat|head|tail|wc|ls|grep|egrep|fgrep)$/ || (W[1] == "git" && W[2] == "ls-files")
342
+ return W[1] ~ /^(cat|head|tail|wc|ls|grep|egrep|fgrep|shellcheck)$/ || (W[1] == "rg" && reader_globs()) || (W[1] == "git" && W[2] == "ls-files")
343
+ }
344
+ function find_allowed( i, w, predicates) {
345
+ for (i = 2; i <= argc; i++) {
346
+ w = W[i]
347
+ if (w ~ /^-(name|iname|path|regex|wholename)$/) { if (++i > argc || globbed[i]) return 0; predicates++; continue }
348
+ if (w ~ /^-(maxdepth|mindepth)$/) { if (++i > argc || W[i] !~ /^[0-9]+$/) return 0; continue }
349
+ if (w ~ /^-/ && w !~ /^-(print|print0|type|L|P|H)$/) return 0
350
+ if (w == "-type") { if (++i > argc || W[i] !~ /^[bcdflps]$/) return 0 }
351
+ }
352
+ return predicates > 0
353
+ }
354
+ function gh_allowed( i, w, subcommand, read) {
355
+ subcommand = W[2] " " W[3]
356
+ read = subcommand ~ /^(repo (view|list)|issue (view|list|status)|pr (view|list|status|diff|checks)|release (view|list)|run (view|list|watch)|search (issues|prs|repos|commits|code))$/
357
+ if (W[2] != "api" && !read) return 0
358
+ for (i = W[2] == "api" ? 3 : 4; i <= argc; i++) {
359
+ w = W[i]
360
+ if (globbed[i]) return 0
361
+ if (w ~ /^(--jq|-q|--json|-t|--template|--repo|-R|--limit|-L|--hostname|--header|-H)$/) {
362
+ if (++i > argc || globbed[i]) return 0
363
+ continue
364
+ }
365
+ if (W[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > argc || W[i] !~ /^(GET|HEAD)$/) return 0; continue }
366
+ if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
367
+ }
368
+ return 1
273
369
  }
274
370
  # The two managed corpus scripts are admitted for execution only by exact literal spelling: the path is
275
371
  # compared as a whole word (no ./, .., variable, glob or quoting variant can equal it), every other word must
@@ -304,6 +400,8 @@ function allow_command( verb, first, i) {
304
400
  return
305
401
  }
306
402
  if (verb == "sed") { if (!print_only_sed()) cmd_failed = 1; return }
403
+ if (verb == "find") { if (!find_allowed()) cmd_failed = 1; return }
404
+ if (verb == "gh") { if (!gh_allowed()) cmd_failed = 1; return }
307
405
  if (verb == "git" && W[2] == "-C") {
308
406
  if (argc >= 4 && W[3] != "" && W[3] !~ /^-/ && !globbed[3] && W[4] ~ /^(add|commit)$/) {
309
407
  verb = verb " " W[4]; first = 5
@@ -327,11 +425,12 @@ function command_end(separator, upto, resume, silent) {
327
425
  endword(); cmd_failed = 0; allow_command()
328
426
  if (cmd_failed) { bad = 1; unparsed = 1 }
329
427
  if (W[1] == "cd" && (separator == "|" || previous_pipe)) fail()
330
- silent = argc && !cmd_failed && !cmd_redirect && !force_emit && W[1] != "cd"
428
+ silent = argc && !cmd_failed && !input_redirect && !force_emit && W[1] != "cd"
429
+ if (silent && redirect_words != "") emitted[++emitted_count] = redirect_words
331
430
  if (!silent && upto > seg_start) emitted[++emitted_count] = substr(lexed, seg_start, upto - seg_start)
332
431
  seg_start = resume
333
432
  previous_pipe = (separator == "|")
334
- cmd_redirect = force_emit = 0
433
+ cmd_redirect = force_emit = input_redirect = 0; redirect_words = ""
335
434
  delete W; delete globbed; delete leading; argc = 0
336
435
  }
337
436
  function readonly(s, i, c, c2, sq, dq) {
@@ -357,6 +456,7 @@ function readonly(s, i, c, c2, sq, dq) {
357
456
  if (c == "(" || c == ")" || c == "{" || c == "}") fail()
358
457
  if (c == ">" || c == "<" || (c == "&" && c2 == ">")) {
359
458
  cmd_redirect = 1
459
+ if (c == "<") input_redirect = 1
360
460
  if (inword && word ~ /^[0-9]+$/) { word = ""; inword = 0 } else endword()
361
461
  if (redirect) fail()
362
462
  if (c == "<" && (c2 == "<" || c2 == "(")) fail()
@@ -391,6 +491,7 @@ BEGIN {
391
491
  # operand. No value-taking option is accepted (--arg, -f, -L, --rawfile, --slurpfile, --from-file, --indent).
392
492
  policy("jq", "rcesnRSjaMC", "--raw-output --compact-output --slurp --null-input --exit-status --raw-input --sort-keys --join-output --ascii-output --monochrome-output --tab")
393
493
  policy("awk", "", "")
494
+ policy("shellcheck", "x", "--external-sources")
394
495
  policy("git status", "sb", "--short --porcelain")
395
496
  policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color --cc")
396
497
  policy("git log", "p", "--oneline --stat --name-only --no-color --follow")
@@ -413,7 +514,9 @@ BEGIN {
413
514
  exit readonly(text) ? 0 : 1
414
515
  }
415
516
  AWK
416
- candidates_text="$(GSW_COMMAND="$command_text" GSW_MODE=targets LC_ALL=C awk "$program" </dev/null)" || parser_failed
517
+ glob_shell_safe=1
518
+ if [[ -n "${BASH_ENV+x}" || -n "${ENV+x}" || -n "${GLOBIGNORE+x}" ]]; then glob_shell_safe=0; fi
519
+ candidates_text="$(GSW_COMMAND="$command_text" GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_MODE=targets LC_ALL=C awk "$program" </dev/null)" || parser_failed
417
520
  [ -n "$candidates_text" ] || exit 0
418
521
  candidates=()
419
522
  while IFS= read -r candidate; do candidates[${#candidates[@]}]="$candidate"; done <<<"$candidates_text"
@@ -431,7 +534,7 @@ references="$("$BASH" "$classifier" --references <<<"$classifier_input" 2>"$clas
431
534
  # A command that is not read-only is refused whatever the classifier could model, so an unmodeled word
432
535
  # (for example program text inside an interpreter heredoc) must not hide the refusal behind a parser
433
536
  # failure. A read-only command keeps the fail-closed parser failure.
434
- if ! GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_PROTECTED="" LC_ALL=C awk "$program" </dev/null; then
537
+ if ! GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_PROTECTED="" LC_ALL=C awk "$program" </dev/null; then
435
538
  printf '%s\n' 'BLOCKED by cratis-guard-shell-writes: this command is not read-only and its references could not all be modeled; use the edit/write tools, or report the intended change.' >&2
436
539
  exit 2
437
540
  fi
@@ -440,6 +543,6 @@ references="$("$BASH" "$classifier" --references <<<"$classifier_input" 2>"$clas
440
543
  exit 2
441
544
  }
442
545
  [ -n "$references" ] || exit 0
443
- if GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_PROTECTED="$references" LC_ALL=C awk "$program" </dev/null; then exit 0; fi
546
+ if GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_PROTECTED="$references" LC_ALL=C awk "$program" </dev/null; then exit 0; fi
444
547
  printf "BLOCKED by cratis-guard-shell-writes: protected reference '%s' (cratis-guard-writes). Use the edit/write tools, or report the intended change; for a read, name literal paths or use the Read/Grep tools.\n" "${references%%$'\n'*}" >&2
445
548
  exit 2
@@ -221,7 +221,8 @@ function tokens(s, side, i, c, j, k, t, copy, jumps, first, closing) {
221
221
  for (i = 1; i <= length(s); i++) {
222
222
  c = substr(s, i, 1); t = c; j = i
223
223
  if (c == "{") {
224
- j = index(substr(s, i), "}"); j = j ? i + j - 1 : i; t = "*"
224
+ j = index(substr(s, i), "}")
225
+ if (j) { j = i + j - 1; t = "*" } else j = i
225
226
  if (side == 1 && index(substr(s, i, j - i + 1), "/")) exit 2
226
227
  }
227
228
  N[side]++; A[side, N[side]] = t
@@ -69,11 +69,13 @@
69
69
  "Commands are pinned to .cratis/ai/rules/general.md 'Quality Gates' and .cratis/ai/hooks/agent-stop.md.",
70
70
  "Note the Release build passes -p:CratisProxiesOutputPath= per general.md so the proxy",
71
71
  "generator does not re-run and touch already-correct generated files. That property is the",
72
- "only gate: the generator's target is Condition=\"'$(CratisProxiesOutputPath)' != ''\", and",
73
- "there is no DisableProxyGenerator property \u2014 MSBuild accepts unknown -p: names silently,",
74
- "so passing one looks effective and does nothing. The Debug gate deliberately omits the",
75
- "override because general.md makes Debug the canonical proxy-regeneration trigger. A",
76
- "consuming repository's own CI should split Debug and Release the same way."
72
+ "Arc off switch: the generator's target is Condition=\"'$(CratisProxiesOutputPath)' != ''\".",
73
+ "DisableProxyGenerator is not an Arc property, only repository-defined \u2014 MSBuild accepts",
74
+ "unknown -p: names silently, so passing it elsewhere looks effective and does nothing.",
75
+ "The Debug/Release split is for these client-side local hooks only: the committing client's",
76
+ "Debug gate omits the override because general.md makes Debug the canonical proxy-regeneration",
77
+ "trigger, and the client commits the result. CI never copies that Debug proxy step: it passes",
78
+ "-p:CratisProxiesOutputPath= in every configuration."
77
79
  ],
78
80
  "enabled": true,
79
81
  "failFast": true,
@@ -102,6 +102,13 @@ capacity numbers into workflows or guidance.
102
102
  - **Never** route `pull_request`-triggered jobs of a *public* repository to self-hosted
103
103
  runners — that hands code execution on our infrastructure to any fork.
104
104
 
105
+ ## Arc proxies
106
+
107
+ - Workflows never generate Arc TypeScript proxies; the client commits them. Every `dotnet
108
+ build`/`publish` of an Arc project passes `-p:CratisProxiesOutputPath=` (empty, Arc's off
109
+ switch; `DisableProxyGenerator` is repository-defined, not Arc's). See the
110
+ **cratis-arc-command** proxy-generation reference.
111
+
105
112
  ## Automation that writes back
106
113
 
107
114
  - A bot that pushes to a branch must **retry with `git pull --rebase`** — the branch
@@ -102,13 +102,20 @@ On the frontend, the generated route already starts with the API prefix.
102
102
 
103
103
  ## Skipping generation
104
104
 
105
- The package has no `DisableProxyGenerator` property. MSBuild accepts unknown
106
- `-p:` names silently, so passing it looks effective and does nothing. The only
107
- gate is `CratisProxiesOutputPath`: leave it empty (for a build, pass
108
- `-p:CratisProxiesOutputPath=`) and the `CratisProxyGenerator` target does not
109
- run. A repository can define its own `DisableProxyGenerator` property and
110
- condition its own targets on it, as the Chronicle kernel project does; that is
111
- repository-local, not part of this package.
105
+ **Proxies are generated by the committing client, never in CI.** The client that
106
+ changes a command or query builds Debug, generates the proxies and commits them
107
+ with the change. CI builds compile against the committed proxies; a CI build that
108
+ regenerates them produces diffs nobody commits or drift that exists only on the
109
+ runner. Every CI build of an Arc project passes `-p:CratisProxiesOutputPath=`
110
+ (empty), in every configuration.
111
+
112
+ `-p:CratisProxiesOutputPath=` is Arc's off switch: the `CratisProxyGenerator`
113
+ target runs only when `CratisProxiesOutputPath` is non-empty, so an empty value
114
+ makes it a no-op. `DisableProxyGenerator` is **not an Arc property**; it works only
115
+ in a repository that defines it itself (for example a project that gates
116
+ `CratisProxiesOutputPath` and the generator reference on it, as the Chronicle
117
+ kernel `Core.csproj` does). MSBuild accepts unknown `-p:` names silently, so passing
118
+ it where it is not defined looks effective and does nothing.
112
119
 
113
120
  ## What the generator extracts for client-side validation
114
121
 
@@ -59,6 +59,11 @@ before an external effect. A request to verify does not authorize a push.
59
59
  7. A change to a command, read model or query shape runs the repository's proxy
60
60
  and API regeneration checks; never hand-edit generated files. A package bump
61
61
  regenerates the checked-in snapshots that pin versions, in the same commit.
62
+ Arc TypeScript proxies are generated and committed by the client, never in CI:
63
+ CI, and local gates that mirror CI, pass `-p:CratisProxiesOutputPath=` (empty;
64
+ the `DisableProxyGenerator` name is repository-defined, not Arc's); only the
65
+ client's own Debug hook regenerates proxies. See the
66
+ **cratis-arc-command** proxy-generation reference.
62
67
 
63
68
  Use affected-project checks while coding and writing specifications. Build once
64
69
  at the end: run the full local gate when the work is believed complete, not after
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.151.0",
3
+ "version": "7.151.2",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [