@cratis/pi 7.138.0 → 7.138.1

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.
@@ -189,7 +189,8 @@ Dependency manifests, including `package.json`, retain their origin/opt-in allow
189
189
  **every simple command must be on this read-only allowlist**:
190
190
 
191
191
  Only the following **exact options** are exempt, because they select/present reads rather
192
- than create files or invoke helpers. Any other option denies, including long-option
192
+ than create files or name helpers. Repository configuration can still run helpers for
193
+ allowed Git verbs. Any other option denies, including long-option
193
194
  abbreviations and unlisted `--option=value` forms. `--` ends option checking; remaining
194
195
  arguments are operands. A lone `-` is a stdin operand. Value-free short flags may combine
195
196
  (e.g. `grep -ni`); value-taking forms must use the explicitly listed spelling.
@@ -200,24 +201,33 @@ arguments are operands. A lone `-` is a stdin operand. Value-free short flags ma
200
201
  | `head`, `tail` | `-n N`, `-nN`, `-c N`, `-N` (numeric counts); no `-f` |
201
202
  | `wc` | `-l -w -c -m` |
202
203
  | `ls` | `-l -a -A -1 -h -d -R -t -r -F` |
204
+ | `rg` | `-n` only; no long options |
203
205
  | `grep`, `egrep`, `fgrep` | `-n -i -r -R -l -L -c -v -w -x -F -E -H -h -o -q -s`; `-e PATTERN`, `-A N`, `-B N`, `-C N`; no long options |
204
206
  | `echo` | `-n -e -E` |
205
207
  | `printf`, `test`, `[`, `true`, `false`, `pwd` | None (in particular, no `printf -v`) |
206
208
  | `git status` | `-s -b --short --porcelain` |
207
- | `git diff` | `--stat --name-only --name-status --cached --staged --check -p -U<N> --no-color` |
209
+ | `git diff` | `--stat --numstat --name-only --name-status --cached --staged --check -p -U<N> --no-color` |
208
210
  | `git log` | `--oneline --stat --name-only -n N -nN -<N> -p --no-color --format=<fmt> --pretty=<fmt> --follow` |
209
211
  | `git show` | `--stat --name-only -p --no-color --format=<fmt>` |
210
212
  | `git add` | `-A -u -p` |
211
213
  | `git commit` | `-m MSG`, `-mMSG`, `-a`, `-q`; `-F FILE` only for a literal non-protected file; no `--no-verify` |
212
214
  | `git blame`, `ls-files`, `rev-parse`, `check-ignore`, `grep` | None |
213
215
 
214
- No global git options are exempt (`-C`, `-c`, `--no-pager` etc. deny before the subcommand).
216
+ The only global Git option exemption is a single separate `-C <dir>` with a literal,
217
+ non-empty directory word not starting with `-`, followed by exactly one of these tails:
218
+ `status --short`, `rev-parse HEAD`, `branch --show-current`, or `tag --list <pattern>`.
219
+ The tag tail takes exactly one pattern not starting with `-` (for example, `'*7.321*'`).
220
+ No extra words are accepted. Attached `-Cdir`/`-C=dir`, repeated `-C`, other verbs and
221
+ all other global options (`-c`, `--git-dir`, `--work-tree`, `--no-pager`, `--exec-path`, etc.)
222
+ remain denied. `-C` gives **no protection** from a hostile repository's configuration:
223
+ fsmonitor, hooks, pager and diff/textconv helpers can still run. This is a syntax filter,
224
+ not a repository sandbox.
215
225
  Git format values containing `%(` are not accepted. Index/commit operations are deliberate
216
226
  allowances, not general shell execution permission. Output-to-file options such as
217
227
  `git diff --output=...` are never exempt, even with a non-protected destination on a line
218
228
  that references a protected file.
219
229
 
220
- `gh` (all subcommands), `rg`, `ag`, `sort`, `uniq`, `cut`, `jq`, `yq`, `less`, `more`, `stat`,
230
+ `gh` (all subcommands), `ag`, `sort`, `uniq`, `cut`, `jq`, `yq`, `less`, `more`, `stat`,
221
231
  `file`, `diff`, `cmp`, checksum tools, `realpath`, `dirname`, `basename`, `which` and `type`
222
232
  are not on this list: their option surfaces are deliberately not analysed here.
223
233
 
@@ -42,14 +42,16 @@ function candidate(s) {
42
42
  # A generic attached option prefix must not hide a path spelling (-t.pi/...).
43
43
  if (s ~ /^-/ && match(s, /[.\/]/) && RSTART > 1) candidate(substr(s, RSTART))
44
44
  }
45
- function scan(s, n, i, c, word) {
45
+ function scan(s, n, i, c, word, whole) {
46
46
  n = length(s)
47
47
  for (i = 1; i <= n; i++) {
48
48
  c = substr(s, i, 1)
49
49
  if (c ~ /[ \t\n\r;|&<>()\047"`$=\\]/) { candidate(word); word = "" }
50
50
  else word = word c
51
+ if (c ~ /[ \t\n\r;|&<>()\047"`$]/) { candidate(whole); whole = "" }
52
+ else whole = whole c
51
53
  }
52
- candidate(word)
54
+ candidate(word); candidate(whole)
53
55
  # Braces have a second boundary view; retain the original pattern above too.
54
56
  if (s ~ /[{}]/) { gsub(/[{}]/, " ", s); scan(s) }
55
57
  }
@@ -98,8 +100,9 @@ function endword() {
98
100
  } else {
99
101
  if (++argc > 256) bad = 1
100
102
  W[argc] = word
103
+ globbed[argc] = glob
101
104
  }
102
- word = ""; inword = 0
105
+ word = ""; inword = glob = 0
103
106
  }
104
107
  # Each exemption permits only the reviewed read/presentation options below. No unknown
105
108
  # options, long-option abbreviations or implicit value-taking short clusters are accepted.
@@ -152,15 +155,27 @@ function options_allowed(verb, first, i, w) {
152
155
  }
153
156
  return 1
154
157
  }
158
+ # Only git -C <literal-dir> status --short, rev-parse HEAD, branch --show-current,
159
+ # or tag --list <pattern> are exempt, with exact arity; no other global option is.
160
+ # -C gives no protection from hostile repository config (fsmonitor, hooks, pager,
161
+ # diff/textconv helpers). This filter checks syntax, not repository trust.
162
+ function directory_metadata() {
163
+ if (argc < 5 || W[3] == "" || W[3] ~ /^-/ || globbed[3]) return 0
164
+ if (argc == 5) return (W[4] == "status" && W[5] == "--short") || (W[4] == "rev-parse" && W[5] == "HEAD") || (W[4] == "branch" && W[5] == "--show-current")
165
+ return argc == 6 && W[4] == "tag" && W[5] == "--list" && W[6] !~ /^-/
166
+ }
155
167
  function allow_command( verb, first) {
156
168
  if (!argc) return
157
169
  if (++commands > 64) { bad = 1; return }
158
170
  verb = W[1]; first = 2
159
- # No global git option is exempt, including -C, -c and --no-pager.
171
+ if (verb == "git" && W[2] == "-C") {
172
+ if (!directory_metadata()) bad = 1
173
+ return
174
+ }
160
175
  if (verb == "git") { verb = verb " " W[2]; first = 3 }
161
176
  if (!(verb in verbs) || !options_allowed(verb, first)) bad = 1
162
177
  }
163
- function command_end() { endword(); allow_command(); delete W; argc = 0 }
178
+ function command_end() { endword(); allow_command(); delete W; delete globbed; argc = 0 }
164
179
  function readonly(s, i, c, c2, sq, dq) {
165
180
  for (i = 1; i <= length(s); i++) {
166
181
  c = substr(s, i, 1); c2 = substr(s, i + 1, 1)
@@ -171,6 +186,8 @@ function readonly(s, i, c, c2, sq, dq) {
171
186
  # Expansions and globs can supply option words the per-verb tables never see.
172
187
  if (c == "`" || c == "$") bad = 1
173
188
  if (dq) { word = word c; continue }
189
+ # Directory metadata requires a literal -C operand, not a pathname expansion.
190
+ if (c == "*" || c == "?" || c == "[") glob = 1
174
191
  # A glob that starts a word, or follows a leading dash, may expand to an option word.
175
192
  if ((c == "*" || c == "?" || c == "[") && (word == "" ? !(c == "[" && c2 ~ /[ \t]/) : substr(word, 1, 1) == "-")) bad = 1
176
193
  if (c == "#" && !inword) { while (i <= length(s) && substr(s, i, 1) != "\n") i++; c = "\n" }
@@ -196,13 +213,14 @@ BEGIN {
196
213
  policy("cat", "nAvetsb", "")
197
214
  policy("head", "", ""); policy("tail", "", "")
198
215
  policy("wc", "lwcm", ""); policy("ls", "laA1hdRtrF", "")
216
+ policy("rg", "n", "")
199
217
  policy("grep", "nirRlLcvwxFEHhoqs", "")
200
218
  policy("egrep", "nirRlLcvwxFEHhoqs", ""); policy("fgrep", "nirRlLcvwxFEHhoqs", "")
201
219
  policy("echo", "neE", "")
202
220
  policy("printf", "", ""); policy("test", "", ""); policy("[", "", "")
203
221
  policy("true", "", ""); policy("false", "", ""); policy("pwd", "", "")
204
222
  policy("git status", "sb", "--short --porcelain")
205
- policy("git diff", "p", "--stat --name-only --name-status --cached --staged --check --no-color")
223
+ policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color")
206
224
  policy("git log", "p", "--oneline --stat --name-only --no-color --follow")
207
225
  policy("git show", "p", "--stat --name-only --no-color")
208
226
  policy("git add", "Aup", ""); policy("git commit", "aq", "")
@@ -193,30 +193,63 @@ control_patterns=('.claude/settings.json' '.claude/settings.local.json' '.mcp.js
193
193
 
194
194
  # Glob-language intersection, not expansion/eval. A star has an epsilon transition and
195
195
  # a character loop. The product automaton accepts iff the two patterns share a spelling.
196
- # Braces conservatively become a star; bracket classes retain their ordinary meaning.
196
+ # In a reference, everything from the first '{' to the last '}' becomes one star: brace
197
+ # expansion, however nested, quoted or escaped, only rewrites text inside that span. A
198
+ # reference bracket is never parsed: it is either a literal '[' or one any-character step
199
+ # to any later ']' in the same segment. Bash's reading is always one of those alternatives,
200
+ # so the class contents can only widen the match. References that mix braces with brackets,
201
+ # whose brace span holds '/', with anything but plain path characters outside the brace
202
+ # span (quoting, substitution and expansion syntax), or with dense brackets are not modeled at all: they fail closed (exit 2) so the work stays
203
+ # bounded.
197
204
  IFS= read -r -d '' glob_program <<'AWK' || true
198
- function tokens(s, side, i, c, j, t, n) {
205
+ function tokens(s, side, i, c, j, k, t, copy, jumps, first, closing) {
199
206
  s = tolower(s)
207
+ if (side == 1) {
208
+ copy = s
209
+ if (index(s, "{") && index(s, "[")) exit 2
210
+ if (gsub(/\[/, "[", copy) > 64) exit 2
211
+ first = index(s, "{")
212
+ for (k = length(s); k > first; k--) if (substr(s, k, 1) == "}") { closing = k; break }
213
+ if (first && closing) {
214
+ if (index(substr(s, first, closing - first + 1), "/")) exit 2
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)
217
+ }
218
+ }
200
219
  for (i = 1; i <= length(s); i++) {
201
- c = substr(s, i, 1); t = c
202
- if (c == "{") { j = index(substr(s, i), "}"); if (j) i += j - 1; t = "*" }
203
- else if (c == "[") {
204
- j = index(substr(s, i + 1), "]")
205
- if (j) { t = substr(s, i, j + 1); i += j; sub(/^\[!/, "[^", t) }
220
+ c = substr(s, i, 1); t = c; j = i
221
+ if (c == "{") {
222
+ j = index(substr(s, i), "}"); j = j ? i + j - 1 : i; t = "*"
223
+ if (side == 1 && index(substr(s, i, j - i + 1), "/")) exit 2
206
224
  }
207
225
  N[side]++; A[side, N[side]] = t
226
+ for (k = i; k <= j; k++) TOKEN[side, k] = N[side]
227
+ if (c == "[" && side == 1) START[N[side]] = i
228
+ i = j
229
+ }
230
+ TOKEN[side, length(s) + 1] = N[side] + 1
231
+ for (t = 1; t <= N[side]; t++) {
232
+ if (side != 1 || !(t in START)) continue
233
+ for (k = START[t] + 2; k <= length(s); k++) {
234
+ c = substr(s, k, 1)
235
+ if (c == "/") break
236
+ if (c != "]") continue
237
+ # A ']' inside a brace star re-enters that star, which covers the rest of it.
238
+ j = TOKEN[1, k] == TOKEN[1, k + 1] ? TOKEN[1, k] : TOKEN[1, k + 1]
239
+ if (++jumps > 4096) exit 2
240
+ JUMP[t, ++JUMPS[t]] = j
241
+ }
208
242
  }
209
243
  }
210
244
  function push(i, j, key) { key = i SUBSEP j; if (!(key in seen)) { seen[key] = 1; L[++last] = i; R[last] = j } }
211
245
  function accepts(t, c, side) {
212
- if (side == 1 && c == "/" && (t == "*" || t == "?" || length(t) > 1)) return 0
213
- return t == "*" || t == "?" || (length(t) > 1 && substr(t, 1, 1) == "[" ? c ~ ("^" t "$") : t == c)
246
+ if (side == 1 && c == "/" && (t == "*" || t == "?")) return 0
247
+ return t == "*" || t == "?" || t == c
214
248
  }
215
- function compatible(a, b, k, c) {
216
- if (length(a) == 1 && a != "*" && a != "?") return accepts(b, a, 2)
217
- if (length(b) == 1 && b != "*" && b != "?") return accepts(a, b, 1)
218
- for (k = 1; k < 256; k++) { c = sprintf("%c", k); if (accepts(a, c, 1) && accepts(b, c, 2)) return 1 }
219
- return 0
249
+ function compatible(a, b) {
250
+ if (a != "*" && a != "?") return accepts(b, a, 2)
251
+ if (b != "*" && b != "?") return accepts(a, b, 1)
252
+ return 1
220
253
  }
221
254
  BEGIN {
222
255
  tokens(ENVIRON["REF_LEFT"], 1); tokens(ENVIRON["REF_RIGHT"], 2); push(1, 1)
@@ -228,6 +261,7 @@ BEGIN {
228
261
  if (a == "*") push(i + 1, j)
229
262
  if (b == "*") push(i, j + 1)
230
263
  if (i <= N[1] && j <= N[2] && compatible(a, b)) push(i + (a != "*"), j + (b != "*"))
264
+ if (i <= N[1] && j <= N[2] && compatible("?", b)) for (k = 1; k <= JUMPS[i]; k++) push(JUMP[i, k], j + (b != "*"))
231
265
  }
232
266
  exit 1
233
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.138.0",
3
+ "version": "7.138.1",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [