@cratis/pi 7.131.5 → 7.131.7

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.
@@ -337,6 +337,32 @@ function executableWords(words) {
337
337
  return { words: result, environmentRepository };
338
338
  }
339
339
 
340
+ function isPrMutation(words, index) {
341
+ return words[index] === 'pr' && ['create', 'edit'].includes(words[index + 1]);
342
+ }
343
+
344
+ function normalizeGlobalOptions(words) {
345
+ if (words[0] !== 'gh') return words;
346
+ const options = [];
347
+ let index = 1;
348
+ while (words[index]?.startsWith('-')) {
349
+ const option = words[index++];
350
+ if (['-R', '--repo'].includes(option)) {
351
+ options.push(option, words[index++]);
352
+ continue;
353
+ }
354
+ if (/^(?:-R.|--repo=)/.test(option)) {
355
+ options.push(option);
356
+ continue;
357
+ }
358
+ // The caller refuses this only where the release-note checks apply.
359
+ if (words.slice(index).some((_, offset) => isPrMutation(words, index + offset))) return null;
360
+ return words;
361
+ }
362
+ if (!isPrMutation(words, index)) return words;
363
+ return ['gh', words[index], words[index + 1], ...options, ...words.slice(index + 2)];
364
+ }
365
+
340
366
  function effectiveRepository(words, cwd, environmentRepository) {
341
367
  // gh selects an edit's PR URL before --repo, then GH_REPO, then the checkout origin.
342
368
  let repository, target;
@@ -375,7 +401,7 @@ function hook() {
375
401
  try { payload = JSON.parse(readFileSync(0, 'utf8')); } catch { return 0; }
376
402
  claudeHook = payload?.hook_event_name === 'PreToolUse';
377
403
  const text = payload?.tool_input?.command;
378
- if (typeof text !== 'string' || !/\bgh\s+pr\s+(create|edit)\b/.test(text.replace(/\\\r?\n/g, ''))) return 0;
404
+ if (typeof text !== 'string' || !/\bgh(?:\s+\S+)*\s+pr\s+(create|edit)\b/.test(text.replace(/\\\r?\n/g, ''))) return 0;
379
405
  // Match each simple command, never the same text inside an echo/grep argument.
380
406
  let cwd = payload.cwd || process.cwd();
381
407
  invocation = { 'hook payload directory': payload.cwd || '(none)' };
@@ -384,7 +410,13 @@ function hook() {
384
410
  try { parsed = commands(text); } catch (error) { if (!optedIn(cwd)) return 0; throw error; }
385
411
  const written = new Set();
386
412
  for (const command of parsed) {
387
- const { words, environmentRepository } = executableWords(command.words);
413
+ const executable = executableWords(command.words);
414
+ const words = normalizeGlobalOptions(executable.words);
415
+ if (!words) {
416
+ if (!optedIn(cwd)) continue;
417
+ throw new Error('Put options after gh pr create/edit; only -R/--repo is supported before the subcommand.');
418
+ }
419
+ const { environmentRepository } = executable;
388
420
  const writes = [...command.writes];
389
421
  if (words[0] === 'tee') writes.push(...words.slice(1).filter(word => !word.startsWith('-')));
390
422
  if (knownDirectory) for (const file of writes) written.add(resolve(cwd, file));
@@ -14,7 +14,7 @@ command_text=${payload//\\n/ }
14
14
  command_text=${command_text//\\t/ }
15
15
  command_text=${command_text//\\r/ }
16
16
  command_text=${command_text//\\/}
17
- if [[ ! "$command_text" =~ gh[[:space:]]+pr[[:space:]]+(create|edit) ]]; then
17
+ if [[ ! "$command_text" =~ gh([[:space:]]+[^[:space:]]+)*[[:space:]]+pr[[:space:]]+(create|edit) ]]; then
18
18
  exit 0
19
19
  fi
20
20
  if ! command -v node >/dev/null 2>&1; then
@@ -48,7 +48,7 @@ probe_lower="$(printf '%s' "$probe" | tr '[:upper:]' '[:lower:]')" || parser_fai
48
48
  case "$probe_lower" in
49
49
  *kubectl*|*printenv*|*env*|*docker*|*podman*|*"gh "*|*vault*|*pulumi*|*show-secret*|*aws*|*"az "*|*gcloud*|*kubeconfig*|*.kube*|\
50
50
  *sh*|*extglob*|*set*|*emulate*|*'-o'*|*'+o'*|*globignore*|*export*|*declare*|*id_rsa*|*id_ed25519*|*id_ecdsa*|*id_dsa*|*.pem*|*.p12*|*.pfx*|*token*|*.netrc*|*.npmrc*|\
51
- *credentials*|*.pgpass*|*pypirc*|*secrets*) ;;
51
+ *credentials*|*.pgpass*|*pypirc*|*secrets*|*oc*) ;;
52
52
  *)
53
53
  case "$command_text" in
54
54
  *'$'*|*'*'*|*'?'*|*'['*|*'{'*|*'('*|*'^'*|*'~'*|*'`'*) ;;
@@ -462,7 +462,7 @@ function tokenize(s, i, n, c, c2, j, dash, delim) {
462
462
  # ── option parsing shared by the CLIs: positionals P/PI, output format, -f/--format value, --raw ──
463
463
  function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
464
464
  delete P; delete PI
465
- np = 0; outfmt = ""; fmtval = ""; tmpl = ""; dd = 0; raw = 0
465
+ np = 0; outfmt = ""; fmtval = ""; tmpl = ""; tmplfile = 0; dd = 0; raw = 0
466
466
  for (i = s; i <= n; i++) {
467
467
  w = A[i]
468
468
  if (w == "--") { dd = i; break }
@@ -471,7 +471,11 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
471
471
  if (eq) { key = substr(w, 1, eq - 1); val = substr(w, eq + 1) }
472
472
  if (key == "--output") { if (!eq) { i++; val = A[i] } outfmt = tolower(val) }
473
473
  else if (key == "--format") { if (!eq) { i++; val = A[i] } fmtval = val }
474
- else if (key == "--template") { if (!eq) { i++; val = A[i] } tmpl = val }
474
+ else if (key == "--template") {
475
+ if (!eq) { i++; val = A[i] } tmpl = val
476
+ if (val ~ /^[[:space:]]*@/ || val !~ /[{]/) tmplfile = 1
477
+ }
478
+ else if (key == "--template-file") { if (!eq) i++; tmplfile = 1 }
475
479
  else if (key == "--raw") raw = 1
476
480
  else if (!eq && (key in LV)) i++
477
481
  continue
@@ -490,10 +494,60 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
490
494
  np++; P[np] = w; PI[np] = i
491
495
  }
492
496
  }
493
- # `-o jsonpath={.}` and `-o go-template={{.}}` print the whole object, exactly like -o json.
494
- function proj_leaks(t) {
495
- t = tolower(t); gsub(/[ \t]/, "", t)
496
- return t ~ /[{](\.|@|\.items|\.items\[\*\])[}]/
497
+ # Projection paths pass only through these explicit field shapes.
498
+ function proj_path_allowed(t, inrange) {
499
+ if (!inrange) sub(/^\.items\[(\*|[0-9]+)\]/, "", t)
500
+ if (t ~ /^\.(kind|apiversion)$/) return 1
501
+ if (t ~ /^\.metadata\.(name|namespace|uid|creationtimestamp|resourceversion|generation|deletiontimestamp)$/) return 1
502
+ if (t ~ /^\.metadata\.labels(\.[a-z0-9_-]+)?$/) return 1
503
+ if (t ~ /^\.metadata\.ownerreferences\[(\*|[0-9]+)\]\.(name|kind|uid)$/) return 1
504
+ if (t ~ /^\.status(\.[a-z0-9_-]+|\[(\*|[0-9]+)\])*$/) return 1
505
+ if (t ~ /^\.spec(\.template\.spec)?\.(containers|initcontainers|ephemeralcontainers)\[(\*|[0-9]+)\]\.(name|image|imagepullpolicy)$/) return 1
506
+ return t ~ /^\.spec\.(nodename|replicas|serviceaccountname|schedulername|restartpolicy|type|clusterip)$/
507
+ }
508
+ function proj_columns_allowed(t, columns, n, k, p, colon) {
509
+ n = split(tolower(t), columns, ","); if (!n) return 0
510
+ for (k = 1; k <= n; k++) {
511
+ p = columns[k]; gsub(/[[:space:]]/, "", p)
512
+ colon = index(p, ":"); if (colon <= 1) return 0
513
+ p = substr(p, colon + 1)
514
+ if (p !~ /^\./) p = "." p
515
+ if (!proj_path_allowed(p, 0)) return 0
516
+ }
517
+ return 1
518
+ }
519
+ function proj_jsonpath_allowed(t, i, c, segment, active, quote, escaped, literal, depth) {
520
+ t = tolower(t)
521
+ for (i = 1; i <= length(t); i++) {
522
+ c = substr(t, i, 1)
523
+ if (!active) {
524
+ if (c == "}") return 0
525
+ if (c == "{") { active = 1; segment = ""; literal = 0 }
526
+ continue
527
+ }
528
+ if (c == "{") return 0
529
+ if (c == "}") {
530
+ if (quote != "") return 0
531
+ if (!literal) {
532
+ if (segment == "range.items[*]") depth++
533
+ else if (segment == "end") { if (!depth) return 0; depth-- }
534
+ else if (!proj_path_allowed(segment, depth > 0)) return 0
535
+ }
536
+ active = 0; continue
537
+ }
538
+ if (quote != "") {
539
+ if (escaped) escaped = 0
540
+ else if (c == "\\") escaped = 1
541
+ else if (c == quote) { quote = ""; literal = 1 }
542
+ } else if (c !~ /[[:space:]]/) {
543
+ if (literal) return 0
544
+ if (c == "\"" || c == SQ) {
545
+ if (segment != "") return 0
546
+ quote = c
547
+ } else segment = segment c
548
+ }
549
+ }
550
+ return !active && !depth
497
551
  }
498
552
  function skipopts(A, s, n, vals) {
499
553
  while (s <= n && substr(A[s], 1, 1) == "-") {
@@ -846,7 +900,11 @@ function allowed_option(option) { return option ~ /^(errexit|nounset|pipefail|xt
846
900
  function shell_invocation(A, s, n, k, j, flags, c, script) {
847
901
  for (k = s + 1; k <= n; k++) {
848
902
  if (A[k] == "--" || A[k] !~ /^[-+]/) break
849
- if (A[k] ~ /^--/) continue
903
+ if (A[k] ~ /^--/) {
904
+ # Only startup switches that preserve the checked shell syntax are safe.
905
+ if (A[k] !~ /^--(norc|noprofile|noediting|verbose|login|version|help)$/) config_report()
906
+ continue
907
+ }
850
908
  flags = substr(A[k], 2); script = index(flags, "c")
851
909
  for (j = 1; j <= length(flags); j++) {
852
910
  c = substr(flags, j, 1)
@@ -920,8 +978,9 @@ function dyn_command(A, s, n, j, na, b, d, S, unresolved, rx) {
920
978
  }
921
979
 
922
980
  # ── tools ──
923
- function kube(A, s, n, verb, m, parts, k, r, rlist) {
981
+ function kube(A, s, n, verb, m, parts, k, r, rlist, projection) {
924
982
  kparse(A, s + 1, n, "nlcsfkLR")
983
+ projection = index(outfmt, "=") ? substr(outfmt, index(outfmt, "=") + 1) : ""
925
984
  verb = P[1]
926
985
  if (verb == "exec") {
927
986
  if (dd) analyze(A, dd + 1, n)
@@ -946,10 +1005,14 @@ function kube(A, s, n, verb, m, parts, k, r, rlist) {
946
1005
  } else if (r in SENS) {
947
1006
  if (verb == "describe")
948
1007
  report("kubectl describe " r " prints the full container spec, including inline credentials", "kubectl get " r " -o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, or kubectl get events / kubectl logs; say which field you need")
949
- else if (outfmt == "json" || outfmt == "yaml")
1008
+ else if (outfmt != "" && outfmt !~ /^(wide|name|jsonpath|jsonpath-as-json|custom-columns|go-template|template|templatefile|go-template-file|jsonpath-file|custom-columns-file)(=|$)/)
950
1009
  report("kubectl get " r " -o " outfmt " prints the full container spec, including inline credentials", "-o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, -o wide, or the status fields you need")
951
- else if ((outfmt ~ /^(jsonpath|go-template|jsonpath-as-json)=/ || tmpl != "") && proj_leaks(tmpl outfmt))
952
- report("kubectl get " r " with a projection that selects the whole object prints the full container spec, including inline credentials", "-o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, -o wide, or the status fields you need")
1010
+ else if (tmplfile || outfmt ~ /^(templatefile|go-template-file|jsonpath-file|custom-columns-file)(=|$)/)
1011
+ report("kubectl get " r " with a file-based projection may print the full container spec, including inline credentials", "use an inline projection of the needed fields: -o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, -o wide, or the status fields you need")
1012
+ else if (outfmt ~ /^(go-template|template)(=|$)/ || (tmpl != "" && outfmt !~ /^(jsonpath|jsonpath-as-json)(=|$)/))
1013
+ report("kubectl get " r " with a projection that selects the container spec prints the full container spec, including inline credentials", "-o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, -o wide, or the status fields you need")
1014
+ else if ((outfmt ~ /^(jsonpath|jsonpath-as-json)(=|$)/ && (!proj_jsonpath_allowed(projection) || !proj_jsonpath_allowed(tmpl))) || (outfmt ~ /^custom-columns(=|$)/ && !proj_columns_allowed(projection)))
1015
+ report("kubectl get " r " with a projection that selects the container spec prints the full container spec, including inline credentials", "-o jsonpath=" SQ "{.items[*].spec.containers[*].image}" SQ ", -o custom-columns=NAME:.metadata.name,STATUS:.status.phase, -o name, -o wide, or the status fields you need")
953
1016
  }
954
1017
  }
955
1018
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.131.5",
3
+ "version": "7.131.7",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [