@cratis/pi 7.131.6 → 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
@@ -900,7 +900,11 @@ function allowed_option(option) { return option ~ /^(errexit|nounset|pipefail|xt
900
900
  function shell_invocation(A, s, n, k, j, flags, c, script) {
901
901
  for (k = s + 1; k <= n; k++) {
902
902
  if (A[k] == "--" || A[k] !~ /^[-+]/) break
903
- 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
+ }
904
908
  flags = substr(A[k], 2); script = index(flags, "c")
905
909
  for (j = 1; j <= length(flags); j++) {
906
910
  c = substr(flags, j, 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.131.6",
3
+ "version": "7.131.7",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [