@cratis/pi 7.9.1 → 7.9.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.
@@ -18,7 +18,9 @@ Three layers:
18
18
  The Claude Code wiring that fires them is tracked here, in
19
19
  [`settings.template.json`](./settings.template.json). Claude reads `.claude/settings.json`. In a
20
20
  repository set up with `cratis ai install`, that file is a **symlink** to this template and follows
21
- every `cratis ai update`; there is nothing to copy. Where the corpus is present without the CLI,
21
+ every `cratis ai update`; there is nothing to copy. The template runs each script through `bash`, so
22
+ a checkout or install that lost the scripts' execute bit still enforces every guard. Where the corpus
23
+ is present without the CLI,
22
24
  activate the hooks by copying the template once:
23
25
 
24
26
  ```bash
@@ -498,22 +500,22 @@ pointing them at a repository that *has* the thing under test; where it is absen
498
500
  # Run from an application checkout; <Module>/<Feature>/<Slice> is the layout general.md documents.
499
501
  jq -nc '{session_id:"t", cwd:"'"$PWD"'", tool_name:"Edit",
500
502
  tool_input:{file_path:"'"$PWD"'/Source/<Module>/<Feature>/<Slice>/<Slice>.cs"}}' \
501
- | .cratis/ai/hooks/scripts/cratis-pattern-scan.sh; echo "exit=$?"
503
+ | bash .cratis/ai/hooks/scripts/cratis-pattern-scan.sh; echo "exit=$?"
502
504
 
503
505
  # Hard block — expect exit 2
504
506
  jq -nc '{session_id:"t", cwd:"'"$PWD"'", tool_name:"Edit",
505
507
  tool_input:{file_path:"'"$PWD"'/Directory.Packages.props", new_string:"x"}}' \
506
- | .cratis/ai/hooks/scripts/cratis-guard-writes.sh; echo "exit=$?"
508
+ | bash .cratis/ai/hooks/scripts/cratis-guard-writes.sh; echo "exit=$?"
507
509
 
508
510
  # Store-mutation guard, both directions: expect exit 2, then exit 0 for the read-only neighbor
509
511
  jq -nc '{tool_name:"Bash", tool_input:{command:"cratis chronicle observers replay my-observer --yes"}}' \
510
- | .cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh; echo "exit=$?"
512
+ | bash .cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh; echo "exit=$?"
511
513
  jq -nc '{tool_name:"Bash", tool_input:{command:"cratis chronicle observers list -o plain"}}' \
512
- | .cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh; echo "exit=$?"
514
+ | bash .cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh; echo "exit=$?"
513
515
 
514
516
  # Quality gate — show the dispatch plan without running anything
515
517
  jq -nc '{session_id:"t", cwd:"'"$PWD"'", stop_hook_active:false}' \
516
- | CRATIS_HOOKS_GATE_DRYRUN=1 .cratis/ai/hooks/scripts/cratis-quality-gate.sh
518
+ | CRATIS_HOOKS_GATE_DRYRUN=1 bash .cratis/ai/hooks/scripts/cratis-quality-gate.sh
517
519
  ```
518
520
 
519
521
  The subpath guard takes corpus roots as arguments, so it is testable in both directions without
@@ -524,10 +526,10 @@ roots. A one-sided test passes vacuously; run both.
524
526
  # Negative — expect a warning naming the file and line
525
527
  mkdir -p /tmp/scratch-corpus
526
528
  echo "import x from '@cratis/components/ThisDoesNotExist';" > /tmp/scratch-corpus/drift.md
527
- .cratis/ai/hooks/scripts/validate-package-subpaths.sh .cratis/ai/rules /tmp/scratch-corpus
529
+ bash .cratis/ai/hooks/scripts/validate-package-subpaths.sh .cratis/ai/rules /tmp/scratch-corpus
528
530
 
529
531
  # Positive — expect silence, and the report to show every real reference resolving
530
- CRATIS_HOOKS_SUBPATH_REPORT=1 .cratis/ai/hooks/scripts/validate-package-subpaths.sh
532
+ CRATIS_HOOKS_SUBPATH_REPORT=1 bash .cratis/ai/hooks/scripts/validate-package-subpaths.sh
531
533
  ```
532
534
 
533
535
  Tier 2 is testable the same way, and wants a third run the subpath guard does not: a probe of names
@@ -539,15 +541,15 @@ a correct one, so prove it stays quiet when it should.
539
541
  mkdir -p /tmp/scratch-corpus
540
542
  echo "import { CommandDialog, ThisNameDoesNotExist } from '@cratis/components/CommandDialog';" \
541
543
  > /tmp/scratch-corpus/drift.md
542
- .cratis/ai/hooks/scripts/validate-package-imports.sh /tmp/scratch-corpus
544
+ bash .cratis/ai/hooks/scripts/validate-package-imports.sh /tmp/scratch-corpus
543
545
 
544
546
  # Discrimination — every name real, expect silence
545
547
  echo "import { DataPage, MenuItem } from '@cratis/components/DataPage';" \
546
548
  > /tmp/scratch-corpus/drift.md
547
- .cratis/ai/hooks/scripts/validate-package-imports.sh /tmp/scratch-corpus
549
+ bash .cratis/ai/hooks/scripts/validate-package-imports.sh /tmp/scratch-corpus
548
550
 
549
551
  # Positive — the real corpus, with the report showing every binding resolving
550
- CRATIS_HOOKS_IMPORT_REPORT=1 .cratis/ai/hooks/scripts/validate-package-imports.sh
552
+ CRATIS_HOOKS_IMPORT_REPORT=1 bash .cratis/ai/hooks/scripts/validate-package-imports.sh
551
553
  ```
552
554
 
553
555
  Tier 3 wants the same three runs, and its negative case is the one that motivated it. Put
@@ -559,15 +561,15 @@ own motivating case is the wrong design.
559
561
  mkdir -p /tmp/scratch-corpus
560
562
  printf 'A reactor may return a `ReactorSideEffect` to control where the event is appended.\n' \
561
563
  > /tmp/scratch-corpus/drift.md
562
- .cratis/ai/hooks/scripts/validate-type-references.sh /tmp/scratch-corpus
564
+ bash .cratis/ai/hooks/scripts/validate-type-references.sh /tmp/scratch-corpus
563
565
 
564
566
  # Discrimination — every name real, expect silence
565
567
  printf 'Return `EventForEventSourceId`, or a `ReactorSideEffectFailure` from an `IReactor`.\n' \
566
568
  > /tmp/scratch-corpus/drift.md
567
- .cratis/ai/hooks/scripts/validate-type-references.sh /tmp/scratch-corpus
569
+ bash .cratis/ai/hooks/scripts/validate-type-references.sh /tmp/scratch-corpus
568
570
 
569
571
  # Positive — the real corpus, expect silence, with the report showing how each name resolved
570
- CRATIS_HOOKS_TYPE_REPORT=1 .cratis/ai/hooks/scripts/validate-type-references.sh
572
+ CRATIS_HOOKS_TYPE_REPORT=1 bash .cratis/ai/hooks/scripts/validate-type-references.sh
571
573
  ```
572
574
 
573
575
  Run `bash -n` on every script and `jq .` on every JSON file before committing. The owning
@@ -25,8 +25,8 @@ const warning = message => {
25
25
  const run = (command, args, options = {}) => spawnSync(command, args, {
26
26
  encoding: 'utf8', timeout: commandTimeout, maxBuffer: 32 * 1024 * 1024, ...options,
27
27
  });
28
- const gh = args => {
29
- const result = run('gh', args);
28
+ const gh = (args, options = {}) => {
29
+ const result = run('gh', args, options);
30
30
  if (result.error || result.status !== 0) throw new Error(`gh ${args[0]} failed: ${result.stderr?.trim() || result.error?.message || result.status}`);
31
31
  return result.stdout;
32
32
  };
@@ -62,7 +62,7 @@ function originRepository(cwd) {
62
62
  }
63
63
 
64
64
  function targetCallers(repository, cwd) {
65
- if (repository?.toLowerCase() === originRepository(cwd)?.toLowerCase()) return callers(cwd);
65
+ if (cwd && repository?.toLowerCase() === originRepository(cwd)?.toLowerCase()) return callers(cwd);
66
66
  let files;
67
67
  try { files = JSON.parse(gh(['api', `repos/${repository}/contents/.github/workflows`])); }
68
68
  catch (error) {
@@ -133,7 +133,7 @@ function rules(warn, repositoryCallers) {
133
133
  }
134
134
  }
135
135
 
136
- function check(argv, repositoryCallers) {
136
+ function check(argv, repositoryCallers, lookupOptions) {
137
137
  const { values } = parseArgs({ args: argv, options: {
138
138
  'body-file': { type: 'string' }, label: { type: 'string', multiple: true },
139
139
  'add-label': { type: 'string', multiple: true }, 'remove-label': { type: 'string', multiple: true },
@@ -143,10 +143,11 @@ function check(argv, repositoryCallers) {
143
143
  const warn = message => { warned = true; warning(`Warning: ${message}`); };
144
144
  let pull;
145
145
  // gh requires a selector when --repo is supplied; otherwise preserve current-branch lookup.
146
- const repoArgs = values.pr && values.repo ? ['--repo', values.repo] : [];
146
+ const lookupRepository = lookupOptions ? lookupOptions.env.GH_REPO : values.repo;
147
+ const repoArgs = values.pr && lookupRepository ? ['--repo', lookupRepository] : [];
147
148
  if (values.pr !== undefined) {
148
149
  pull = JSON.parse(gh(['pr', 'view', ...(values.pr ? [values.pr] : []), ...repoArgs,
149
- '--json', 'labels,body,author,baseRefName']));
150
+ '--json', 'labels,body,author,baseRefName'], lookupOptions || (values.repo ? { env: { ...process.env, GH_REPO: values.repo } } : {})));
150
151
  }
151
152
  if (!values['body-file'] && !pull) throw new Error('--body-file is required when creating a pull request');
152
153
  const split = labels => (labels || []).flatMap(label => label.split(',')).map(label => label.trim()).filter(Boolean);
@@ -312,7 +313,7 @@ function effectiveRepository(words, cwd, environmentRepository) {
312
313
  if (/[$`]/.test(environmentRepository)) throw new Error('Use a literal value for GH_REPO, not a shell expansion.');
313
314
  return repositoryName(environmentRepository);
314
315
  }
315
- return originRepository(cwd);
316
+ return cwd ? originRepository(cwd) : undefined;
316
317
  }
317
318
 
318
319
  function hook() {
@@ -343,14 +344,15 @@ function hook() {
343
344
  }
344
345
  if (words[0] !== 'gh' || words[1] !== 'pr' || !['create', 'edit'].includes(words[2])) continue;
345
346
  if (words.includes('--help') || words.includes('-h')) continue;
346
- if (!knownDirectory) {
347
- if (!optedIn(cwd)) return 0;
347
+ const repository = effectiveRepository(words, knownDirectory ? cwd : undefined, environmentRepository);
348
+ if (!knownDirectory && !repository) {
349
+ if (!optedIn(cwd)) continue;
348
350
  throw new Error('Use a literal directory before gh pr create/edit.');
349
351
  }
350
- const repository = effectiveRepository(words, cwd, environmentRepository);
351
352
  if (!/^Cratis\/[^/]+$/i.test(repository)) continue;
352
- const repositoryCallers = targetCallers(repository, cwd);
353
+ const repositoryCallers = targetCallers(repository, knownDirectory ? cwd : undefined);
353
354
  if (!repositoryCallers.length) continue;
355
+ if (!knownDirectory) throw new Error('Use a literal directory before gh pr create/edit.');
354
356
  const args = [];
355
357
  let target = '', hasBody = false;
356
358
  for (let index = 3; index < words.length; index++) {
@@ -377,10 +379,14 @@ function hook() {
377
379
  }
378
380
  if (words[2] === 'create' && !hasBody) throw new Error('write the body to `.ai-work/pr-body.md` and use `--body-file` when creating a pull request.');
379
381
  if (words[2] === 'edit') args.push('--pr', target);
380
- // Use the same resolved target for opt-in, PR metadata and repository metadata.
381
382
  args.push('--repo', repository);
383
+ // Pin PR lookup only for a command-targeted repository; otherwise let gh resolve its base repo.
384
+ const lookupEnvironment = { ...process.env };
385
+ const targetedRepository = effectiveRepository(words, undefined, environmentRepository);
386
+ if (targetedRepository) lookupEnvironment.GH_REPO = targetedRepository;
387
+ else delete lookupEnvironment.GH_REPO;
382
388
  process.chdir(cwd);
383
- const code = check(args, repositoryCallers);
389
+ const code = check(args, repositoryCallers, { env: lookupEnvironment });
384
390
  if (code !== 0 && code !== 3) throw new Error('The pull-request body or release intent failed cratis-check-pr. Fix the reported violations before retrying.');
385
391
  }
386
392
  return 0;
@@ -68,7 +68,7 @@
68
68
  { "command": "observers retry-partition", "effect": "retries a failed partition from the sequence number where it failed" },
69
69
  { "command": "observers clear-quarantine", "effect": "clears an observer's quarantine so it resumes processing" },
70
70
  { "command": "jobs stop", "effect": "stops a running background job" },
71
- { "command": "jobs resume", "effect": "resumes a stopped or failed background job" },
71
+ { "command": "jobs resume", "effect": "resumes a stopped background job" },
72
72
  { "command": "recommendations perform", "effect": "executes a server recommendation, such as a schema or replay maintenance action" },
73
73
  { "command": "recommendations ignore", "effect": "marks a recommendation as ignored so it no longer appears" },
74
74
  { "command": "subscriptions add", "effect": "adds an event store subscription to a target event store" },
@@ -7,7 +7,7 @@
7
7
  "hooks": [
8
8
  {
9
9
  "type": "command",
10
- "command": "\"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-writes.sh"
10
+ "command": "bash \"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-writes.sh"
11
11
  }
12
12
  ]
13
13
  },
@@ -16,11 +16,11 @@
16
16
  "hooks": [
17
17
  {
18
18
  "type": "command",
19
- "command": "\"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh"
19
+ "command": "bash \"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-store-mutations.sh"
20
20
  },
21
21
  {
22
22
  "type": "command",
23
- "command": "\"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-pr-body.sh"
23
+ "command": "bash \"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-guard-pr-body.sh"
24
24
  }
25
25
  ]
26
26
  }
@@ -31,7 +31,7 @@
31
31
  "hooks": [
32
32
  {
33
33
  "type": "command",
34
- "command": "\"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-pattern-scan.sh"
34
+ "command": "bash \"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-pattern-scan.sh"
35
35
  }
36
36
  ]
37
37
  }
@@ -41,7 +41,7 @@
41
41
  "hooks": [
42
42
  {
43
43
  "type": "command",
44
- "command": "\"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-quality-gate.sh"
44
+ "command": "bash \"$CLAUDE_PROJECT_DIR\"/.cratis/ai/hooks/scripts/cratis-quality-gate.sh"
45
45
  }
46
46
  ]
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.9.1",
3
+ "version": "7.9.2",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [