@cratis/pi 7.170.4 → 7.170.6

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.
@@ -44,6 +44,11 @@ Reader glob probes skip directories only when decoded options establish a nonrec
44
44
  unknown or recursive grep options keep directory matches conservative. Simple sed print/substitution
45
45
  programs are data only without in-place edits, execution, or file writes; `-f` remains a file operand.
46
46
  GitHub API endpoints are normalized before checking sensitive paths.
47
+ GitHub output filters (`--jq`/`-q`, `--template`/`-t`) may select response fields such as `.env`,
48
+ but may not read the process environment through `env` or `$ENV`, including within expressions.
49
+ Quoted strings and comments in jq filters remain data. Bundled filter flags are checked too;
50
+ `-t` is a title or subject only for `pr`/`issue`/`release` create/edit, `pr merge`, and
51
+ `ssh-key`/`gpg-key` add. API endpoint names never opt out of template checks.
47
52
 
48
53
  The shell-write guard classifies **write-target words**, not every word. It lexes the command into
49
54
  simple commands. When every command is a reviewed reader or staging verb (`cat`, `head`, `tail`, `wc`,
@@ -282,11 +287,15 @@ Rule numbers refer to the numbered list in [`../rules/general.md`](../rules/gene
282
287
  repository's dependency-manifest policy allows them (see below)
283
288
  - `.env`, `.env.*`, `*.env` — secrets
284
289
  - Agent controls: `.claude/settings.json`, `.claude/settings.local.json`, `.mcp.json`,
285
- `.pi/settings.json` and `.pi/extensions/**`
286
- - With `.cratis/ai.manifest.json` present, the installed `.cratis/ai/**`, `.claude/**` and `.pi/**`
287
- trees. Both addressed paths and symlink destinations are checked, including the Claude settings
288
- link to the hook template. The uninstalled Cratis/AI source repository is exempt from this
289
- agent-control category so its authored corpus and harness adapters remain editable.
290
+ `.pi/settings.json`, `.pi/extensions/**`, `.cratis/ai.manifest.json` and `.cratis/ai.json`
291
+ - The installed `.cratis/ai/**` corpus, including when its manifest is missing or unreadable.
292
+ Adapter paths in `.claude/**` and `.pi/**` are protected according to the manifest's
293
+ `Integrations` entries. Both addressed paths and symlink destinations are checked, including
294
+ the Claude settings link to the hook template. Without an installation manifest, authored
295
+ corpus and harness adapters remain editable only when Git `HEAD` records the authoring layout:
296
+ `Cratis.AI.slnx`, the guard source and the `@cratis/pi` package in `Source/Pi.Plugin`. Changing a
297
+ remote URL or adding uncommitted files does not establish this source-repository exception.
298
+ The two policy JSON files remain protected in the source repository.
290
299
 
291
300
  For agent controls, report the intended change rather than rewriting permissions or hooks.
292
301
  A person edits settings; `cratis ai update` replaces managed files using the CLI's filesystem
@@ -595,7 +595,18 @@ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
595
595
  return scripts > 0
596
596
  }
597
597
  # Only fully modeled literal non-readers can distinguish data slots from paths.
598
- function nonreader(A, M, n, i, w, first, read) {
598
+ function gh_reader_bundle(A, i, n, j, flag) {
599
+ for (j = 2; j <= length(A[i]); j++) {
600
+ flag = substr(A[i], j, 1)
601
+ if (flag ~ /^[icwd]$/) continue
602
+ if (flag != "q" && flag != "t") return 0
603
+ DATA[i] = 1
604
+ if (j == length(A[i])) { if (++i > n) return 0; DATA[i] = 1 }
605
+ return i
606
+ }
607
+ return i
608
+ }
609
+ function nonreader(A, M, n, i, w, first, read, nexti) {
599
610
  delete DATA
600
611
  for (i = 1; i <= n; i++) if (expands(A[i], M[i]) || index(A[i], "`") || A[i] ~ /^</) return 0
601
612
  first = tolower(base(A[1]))
@@ -627,9 +638,11 @@ function nonreader(A, M, n, i, w, first, read) {
627
638
  for (i = A[2] == "api" ? 3 : 4; i <= n; i++) {
628
639
  w = A[i]
629
640
  if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
641
+ if (w ~ /^--(jq|template)=/) { DATA[i] = 1; continue }
630
642
  if (w ~ /^(--jq|-q|--template|-t)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
631
643
  if (w ~ /^(--json|--repo|-R|--limit|-L|--hostname|--header|-H)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
632
644
  if (A[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > n || A[i] !~ /^(GET|HEAD)$/) return 0; continue }
645
+ if (w ~ /^-[^-]/) { nexti = gh_reader_bundle(A, i, n); if (!nexti) return 0; i = nexti; continue }
633
646
  if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
634
647
  if (A[2] != "api") DATA[i] = 1
635
648
  }
@@ -885,7 +898,19 @@ function tokenize(s, i, n, c, c2, j, dash, delim) {
885
898
  }
886
899
 
887
900
  # ── option parsing shared by the CLIs: positionals P/PI, output format, -f/--format value, --raw ──
888
- function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
901
+ function gh_short_options(A, i, shortvals, output_filters, j, f, rest, value) {
902
+ for (j = 2; j <= length(A[i]); j++) {
903
+ f = substr(A[i], j, 1)
904
+ if (!index(shortvals, f)) continue
905
+ rest = substr(A[i], j + 1)
906
+ if (rest == "") value = A[++i]
907
+ else { value = rest; sub(/^=/, "", value) }
908
+ if (f == "q" || (f == "t" && output_filters == 1)) check_gh_filter(value)
909
+ return i
910
+ }
911
+ return i
912
+ }
913
+ function kparse(A, s, n, shortvals, output_filters, i, w, eq, key, val, f, rest) {
889
914
  delete P; delete PI
890
915
  np = 0; outfmt = ""; fmtval = ""; tmpl = ""; tmplfile = 0; dd = 0; raw = 0
891
916
  for (i = s; i <= n; i++) {
@@ -894,7 +919,11 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
894
919
  if (substr(w, 1, 2) == "--") {
895
920
  eq = index(w, "="); key = w; val = ""
896
921
  if (eq) { key = substr(w, 1, eq - 1); val = substr(w, eq + 1) }
897
- if (key == "--output") { if (!eq) { i++; val = A[i] } outfmt = tolower(val) }
922
+ if (output_filters && (key == "--jq" || key == "--template")) {
923
+ if (!eq) { i++; val = A[i] }
924
+ check_gh_filter(val)
925
+ }
926
+ else if (key == "--output") { if (!eq) { i++; val = A[i] } outfmt = tolower(val) }
898
927
  else if (key == "--format") { if (!eq) { i++; val = A[i] } fmtval = val }
899
928
  else if (key == "--template") {
900
929
  if (!eq) { i++; val = A[i] } tmpl = val
@@ -906,6 +935,7 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
906
935
  continue
907
936
  }
908
937
  if (substr(w, 1, 1) == "-" && length(w) > 1) {
938
+ if (output_filters) { i = gh_short_options(A, i, shortvals, output_filters); continue }
909
939
  f = substr(w, 2, 1); rest = substr(w, 3)
910
940
  if (f == "o") {
911
941
  if (rest == "") { i++; val = A[i] } else val = (substr(rest, 1, 1) == "=" ? substr(rest, 2) : rest)
@@ -1664,8 +1694,45 @@ function endpoint_path(path, i, pair, value, decoded) {
1664
1694
  sub(/[?#].*$/, "", decoded); gsub(/\/\/+/, "/", decoded); sub(/\/+$/, "", decoded)
1665
1695
  return decoded
1666
1696
  }
1697
+ # Ignore string literals and field names, but inspect expressions inside string interpolation.
1698
+ function filter_reads_environment(s, i, c, nextc, quoted, depth, parens, token, previous, level, containers, object_key) {
1699
+ for (i = 1; i <= length(s); i++) {
1700
+ c = substr(s, i, 1); nextc = substr(s, i + 1, 1)
1701
+ if (quoted) {
1702
+ if (c == "\\") {
1703
+ if (nextc == "(") { parens[++depth] = 1; quoted = 0; previous = "" }
1704
+ i++
1705
+ } else if (c == "\"") quoted = 0
1706
+ continue
1707
+ }
1708
+ if (c == "\"") { quoted = 1; previous = "string"; continue }
1709
+ if (c == "#") { while (i <= length(s) && substr(s, i, 1) != "\n") i++; continue }
1710
+ if (depth && c == "(") parens[depth]++
1711
+ if (depth && c == ")" && --parens[depth] == 0) { depth--; quoted = 1; continue }
1712
+ if (c == "[" || c == "{") containers[++level] = c
1713
+ if (c == "]" || c == "}") { delete containers[level]; level-- }
1714
+ if (c ~ /[A-Za-z_]/) {
1715
+ token = c
1716
+ while (substr(s, i + 1, 1) ~ /[A-Za-z0-9_]/) token = token substr(s, ++i, 1)
1717
+ object_key = containers[level] == "{" && (previous == "{" || previous == ",") && substr(s, i + 1) ~ /^[[:space:]]*:[^:]/
1718
+ if ((token == "env" && previous != "." && previous != "$" && !object_key) || (token == "ENV" && previous == "$")) return 1
1719
+ previous = token
1720
+ } else if (c !~ /[[:space:]]/) previous = c
1721
+ }
1722
+ return 0
1723
+ }
1724
+ function check_gh_filter(value) {
1725
+ if (filter_reads_environment(value))
1726
+ report("gh output filter reads the process environment, including credentials", "select response fields without env or $ENV")
1727
+ }
1728
+ function gh_title_option() {
1729
+ return (P[1] ~ /^(pr|issue|release)$/ && P[2] ~ /^(create|edit)$/) ||
1730
+ (P[1] == "pr" && P[2] == "merge") || (P[1] ~ /^(ssh-key|gpg-key)$/ && P[2] == "add")
1731
+ }
1667
1732
  function gh(A, s, n, i, w, mutating, k, path, kind) {
1668
1733
  kparse(A, s + 1, n, "XHfFqtR")
1734
+ # Only named command pairs use -t for a title or subject rather than an output template.
1735
+ kparse(A, s + 1, n, "XHfFqtR", (gh_title_option() ? 2 : 1))
1669
1736
  if (P[1] == "secret") {
1670
1737
  if (P[2] != "set" && P[2] != "delete" && P[2] != "remove")
1671
1738
  report("gh secret " P[2] " reads the repository secret store", "gh secret set NAME (writes nothing to the output); refer to secrets by name only")
@@ -187,7 +187,7 @@ origin_matches() {
187
187
  # One policy vocabulary for normal Write/Edit and whole-command reference checks.
188
188
  manifest_patterns=(package.json Directory.Packages.props global.json NuGet.config yarn.lock package-lock.json pnpm-lock.yaml packages.lock.json)
189
189
  environment_patterns=('.env' '.env.*' '*.env')
190
- control_patterns=('.claude/settings.json' '.claude/settings.local.json' '.mcp.json' '.pi/settings.json' '.pi/extensions/*')
190
+ control_patterns=('.claude/settings.json' '.claude/settings.local.json' '.mcp.json' '.pi/settings.json' '.pi/extensions/*' '.cratis/ai.manifest.json' '.cratis/ai.json')
191
191
 
192
192
  # Glob-language intersection, not expansion/eval. A star has an epsilon transition and
193
193
  # a character loop. The product automaton accepts iff the two patterns share a spelling.
@@ -209,16 +209,17 @@ function tokens(s, side, i, c, j, k, t, copy, jumps, first, closing) {
209
209
  if (gsub(/\[/, "[", copy) > 64) exit 2
210
210
  first = index(s, "{")
211
211
  for (k = length(s); k > first; k--) if (substr(s, k, 1) == "}") { closing = k; break }
212
- if (first && closing) {
212
+ if (first && closing && s != "{}") {
213
213
  if (index(substr(s, first, closing - first + 1), "/")) exit 2
214
214
  if (substr(s, first, closing - first + 1) ~ /[$`'"\\]/) exit 2
215
215
  if (substr(s, 1, first - 1) substr(s, closing + 1) ~ /[^a-z0-9._\/*?,+=:@%-]/) exit 2
216
- s = substr(s, 1, first) substr(s, closing)
216
+ s = substr(s, 1, first - 1) "*" substr(s, closing + 1)
217
217
  }
218
218
  }
219
219
  for (i = 1; i <= length(s); i++) {
220
220
  c = substr(s, i, 1); t = c; j = i
221
- if (c == "{") {
221
+ # Only a standalone empty brace argument is literal; path placeholders can expand.
222
+ if (c == "{" && s != "{}") {
222
223
  j = index(substr(s, i), "}")
223
224
  if (j) { j = i + j - 1; t = "*" } else j = i
224
225
  if (side == 1 && index(substr(s, i, j - i + 1), "/")) exit 2
@@ -292,6 +293,8 @@ control_match() {
292
293
  local value="$1" reference_pattern="$reference_pattern" pattern LC_ALL=C
293
294
  shift
294
295
  if names_match "$value" "$@"; then return 0; fi
296
+ # Do not turn a standalone placeholder into a path by appending descendants.
297
+ [ "$value" != '{}' ] || return 1
295
298
  [ "$reference_mode" = 1 ] || return 1
296
299
  if [ "$reference_pattern" = 0 ]; then
297
300
  shopt -s nocasematch
@@ -305,6 +308,23 @@ control_match() {
305
308
  }
306
309
 
307
310
  # ── 4. Agent controls and installed managed trees ─────────────────────────────
311
+ # Authoring requires committed framework source, not a mutable remote URL or new files.
312
+ authored_cache_root=""
313
+ authored_cache_status=1
314
+ authored_corpus_repository() {
315
+ if [ "$authored_cache_root" != "$1" ]; then
316
+ authored_cache_root="$1"
317
+ authored_cache_status=1
318
+ if git -C "$1" cat-file -e HEAD:Cratis.AI.slnx 2>/dev/null &&
319
+ git -C "$1" cat-file -e HEAD:.cratis/ai/hooks/scripts/cratis-guard-writes.sh 2>/dev/null &&
320
+ git -C "$1" show HEAD:Source/Pi.Plugin/package.json 2>/dev/null |
321
+ jq -e -s 'length == 1 and .[0].name == "@cratis/pi" and .[0].type == "module"' >/dev/null 2>&1; then
322
+ authored_cache_status=0
323
+ fi
324
+ fi
325
+ return "$authored_cache_status"
326
+ }
327
+
308
328
  agent_control_target() {
309
329
  local target="$1" directory policy_root target_rel managed pattern
310
330
  dir_of "$target"
@@ -319,9 +339,14 @@ agent_control_target() {
319
339
  policy_root="$directory"
320
340
  relative_to "$target" "$policy_root"
321
341
  target_rel="$REPLY"
322
- if [ -f "$policy_root/.cratis/ai.manifest.json" ]; then
342
+ # Policy files remain controls even in the authored corpus repository.
343
+ if control_match "$target_rel" '.cratis/ai.manifest.json' '.cratis/ai.json'; then return 0; fi
344
+ if [ ! -f "$policy_root/.cratis/ai.manifest.json" ] && authored_corpus_repository "$policy_root"; then
345
+ return 1
346
+ fi
347
+ if [ -f "$policy_root/.cratis/ai.manifest.json" ] || [ -d "$policy_root/.cratis/ai" ]; then
323
348
  if control_match "$target_rel" '.cratis/ai/*'; then return 0; fi
324
- if control_match "$target_rel" '.claude/*' '.pi/*'; then
349
+ if [ -f "$policy_root/.cratis/ai.manifest.json" ] && control_match "$target_rel" '.claude/*' '.pi/*'; then
325
350
  # Integration paths, not corpus Files, establish adapter ownership.
326
351
  managed="$(jq -r '
327
352
  (.Integrations // []) | if type != "array" then empty else
@@ -335,12 +360,6 @@ agent_control_target() {
335
360
  if control_match "$target_rel" "$pattern"; then return 0; fi
336
361
  done <<<"$managed"
337
362
  fi
338
- else
339
- # The corpus is authored source in Cratis/AI, not a managed installation.
340
- repository_origin "$policy_root"
341
- if origin_matches '^(https://github\.com/|git@github\.com:|ssh://git@github\.com(:[0-9]+)?/)cratis/ai(\.git)?/?$'; then
342
- return 1
343
- fi
344
363
  fi
345
364
  control_match "$target_rel" "${control_patterns[@]}"
346
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.170.4",
3
+ "version": "7.170.6",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [